Browse Source

Normalize actions passed via websockets

fastled
Xose Pérez 7 years ago
parent
commit
eb432ffe95
4 changed files with 36 additions and 19 deletions
  1. +10
    -10
      code/espurna/config/data.h
  2. BIN
      code/espurna/data/index.html.gz
  3. +25
    -8
      code/espurna/web.ino
  4. +1
    -1
      code/html/custom.js

+ 10
- 10
code/espurna/config/data.h
File diff suppressed because it is too large
View File


BIN
code/espurna/data/index.html.gz View File


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

@ -80,15 +80,13 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
if (root.containsKey("action")) {
String action = root["action"];
unsigned int relayID = 0;
if (root.containsKey("relayID")) {
String value = root["relayID"];
relayID = value.toInt();
}
DEBUG_MSG("[WEBSOCKET] Requested action: %s\n", action.c_str());
if (action.equals("reset")) ESP.restart();
if (action.equals("reset")) {
ESP.restart();
}
if (action.equals("restore") && root.containsKey("data")) {
JsonObject& data = root["data"];
@ -112,14 +110,33 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
ws.text(client_id, "{\"message\": \"Changes saved. You should reboot your board now.\"}");
}
if (action.equals("reconnect")) {
// Let the HTTP request return and disconnect after 100ms
deferred.once_ms(100, wifiDisconnect);
}
if (action.equals("on")) relayStatus(relayID, true);
if (action.equals("off")) relayStatus(relayID, false);
if (action.equals("relay") && root.containsKey("data")) {
JsonObject& data = root["data"];
if (data.containsKey("status")) {
bool state = (strcmp(data["status"], "1") == 0);
unsigned int relayID = 0;
if (data.containsKey("id")) {
String value = data["id"];
relayID = value.toInt();
}
relayStatus(relayID, state);
}
}
#if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
if (action.equals("color") && root.containsKey("data")) {


+ 1
- 1
code/html/custom.js View File

@ -75,7 +75,7 @@ function doReconnect() {
function doToggle(element, value) {
var relayID = parseInt(element.attr("data"));
websock.send(JSON.stringify({'action': value ? 'on' : 'off', 'relayID': relayID}));
websock.send(JSON.stringify({'action': 'relay', 'data': { 'id': relayID, 'status': value ? 1 : 0 }}));
return false;
}


Loading…
Cancel
Save