Browse Source

Notify OTA updates to web clients and reload page after the update

fastled
Xose Pérez 7 years ago
parent
commit
77e887dc6c
6 changed files with 13 additions and 10 deletions
  1. BIN
      code/espurna/data/script.js.gz
  2. +3
    -0
      code/espurna/ota.ino
  3. +1
    -1
      code/espurna/pow.ino
  4. +1
    -1
      code/espurna/relay.ino
  5. +6
    -8
      code/espurna/web.ino
  6. +2
    -0
      code/html/custom.js

BIN
code/espurna/data/script.js.gz View File


+ 3
- 0
code/espurna/ota.ino View File

@ -24,10 +24,13 @@ void otaSetup() {
ArduinoOTA.onStart([]() { ArduinoOTA.onStart([]() {
DEBUG_MSG("[OTA] Start\n"); DEBUG_MSG("[OTA] Start\n");
wsSend("{\"message\": \"OTA update started\"}");
}); });
ArduinoOTA.onEnd([]() { ArduinoOTA.onEnd([]() {
DEBUG_MSG("\n[OTA] End\n"); DEBUG_MSG("\n[OTA] End\n");
wsSend("{\"action\": \"reload\"}");
delay(100);
}); });
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {


+ 1
- 1
code/espurna/pow.ino View File

@ -181,7 +181,7 @@ void powLoop() {
String output; String output;
root.printTo(output); root.printTo(output);
wsSend((char *) output.c_str());
wsSend(output.c_str());
if (--report_count == 0) { if (--report_count == 0) {


+ 1
- 1
code/espurna/relay.ino View File

@ -52,7 +52,7 @@ String relayString() {
void relayWS() { void relayWS() {
String output = relayString(); String output = relayString();
wsSend((char *) output.c_str());
wsSend(output.c_str());
} }
bool relayStatus(unsigned char id) { bool relayStatus(unsigned char id) {


+ 6
- 8
code/espurna/web.ino View File

@ -30,24 +30,24 @@ Ticker deferred;
// WEBSOCKETS // WEBSOCKETS
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool wsSend(char * payload) {
//DEBUG_MSG("[WEBSOCKET] Broadcasting '%s'\n", payload);
bool wsSend(const char * payload) {
DEBUG_MSG("[WEBSOCKET] Broadcasting '%s'\n", payload);
ws.textAll(payload); ws.textAll(payload);
} }
bool wsSend(uint32_t client_id, char * payload) {
//DEBUG_MSG("[WEBSOCKET] Sending '%s' to #%ld\n", payload, client_id);
bool wsSend(uint32_t client_id, const char * payload) {
DEBUG_MSG("[WEBSOCKET] Sending '%s' to #%ld\n", payload, client_id);
ws.text(client_id, payload); ws.text(client_id, payload);
} }
void wsMQTTCallback(unsigned int type, const char * topic, const char * payload) { void wsMQTTCallback(unsigned int type, const char * topic, const char * payload) {
if (type == MQTT_CONNECT_EVENT) { if (type == MQTT_CONNECT_EVENT) {
wsSend((char *) "{\"mqttStatus\": true}");
wsSend("{\"mqttStatus\": true}");
} }
if (type == MQTT_DISCONNECT_EVENT) { if (type == MQTT_DISCONNECT_EVENT) {
wsSend((char *) "{\"mqttStatus\": false}");
wsSend("{\"mqttStatus\": false}");
} }
} }
@ -564,8 +564,6 @@ ArRequestHandlerFunction _onRelayStatusWrapper(unsigned int relayID) {
if (request->method() == HTTP_PUT) { if (request->method() == HTTP_PUT) {
if (request->hasParam("status", true)) { if (request->hasParam("status", true)) {
AsyncWebParameter* p = request->getParam("status", true); AsyncWebParameter* p = request->getParam("status", true);
wsSend((char *) String(relayID).c_str());
wsSend((char *) p->value().c_str());
unsigned int value = p->value().toInt(); unsigned int value = p->value().toInt();
if (value == 2) { if (value == 2) {
relayToggle(relayID); relayToggle(relayID);


+ 2
- 0
code/html/custom.js View File

@ -207,6 +207,8 @@ function processData(data) {
window.location = "/"; window.location = "/";
}); });
} else {
window.location = "/";
} }
} }


Loading…
Cancel
Save