Browse Source

Added key check to remove unneeded keys

v2
Xose Pérez 6 years ago
parent
commit
2339a5756a
36 changed files with 10946 additions and 10909 deletions
  1. +11
    -9
      code/espurna/alexa.ino
  2. +2
    -2
      code/espurna/api.ino
  3. +6
    -5
      code/espurna/button.ino
  4. +2
    -3
      code/espurna/config/prototypes.h
  5. BIN
      code/espurna/data/index.all.html.gz
  6. BIN
      code/espurna/data/index.light.html.gz
  7. BIN
      code/espurna/data/index.rfbridge.html.gz
  8. BIN
      code/espurna/data/index.sensor.html.gz
  9. BIN
      code/espurna/data/index.small.html.gz
  10. +4
    -4
      code/espurna/domoticz.ino
  11. +0
    -22
      code/espurna/espurna.ino
  12. +4
    -4
      code/espurna/homeassistant.ino
  13. +3
    -8
      code/espurna/i2c.ino
  14. +9
    -8
      code/espurna/influxdb.ino
  15. +9
    -7
      code/espurna/led.ino
  16. +17
    -17
      code/espurna/light.ino
  17. +16
    -12
      code/espurna/mqtt.ino
  18. +10
    -10
      code/espurna/nofuss.ino
  19. +6
    -6
      code/espurna/ntp.ino
  20. +4
    -6
      code/espurna/ota.ino
  21. +6
    -7
      code/espurna/relay.ino
  22. +6
    -5
      code/espurna/scheduler.ino
  23. +30
    -24
      code/espurna/sensor.ino
  24. +57
    -0
      code/espurna/settings.ino
  25. +2444
    -2444
      code/espurna/static/index.all.html.gz.h
  26. +2317
    -2317
      code/espurna/static/index.light.html.gz.h
  27. +1982
    -1982
      code/espurna/static/index.rfbridge.html.gz.h
  28. +2021
    -2021
      code/espurna/static/index.sensor.html.gz.h
  29. +1939
    -1939
      code/espurna/static/index.small.html.gz.h
  30. +7
    -6
      code/espurna/telnet.ino
  31. +5
    -4
      code/espurna/thinkspeak.ino
  32. +5
    -4
      code/espurna/web.ino
  33. +9
    -6
      code/espurna/wifi.ino
  34. +7
    -19
      code/espurna/ws.ino
  35. +6
    -6
      code/html/custom.js
  36. +2
    -2
      code/html/index.html

+ 11
- 9
code/espurna/alexa.ino View File

@ -25,23 +25,26 @@ static std::queue<AlexaDevChange> _alexa_dev_changes;
// ALEXA // ALEXA
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool _alexaWebSocketOnReceive(const char * key, JsonVariant& value) {
return (strncmp(key, "alx", 3) == 0);
}
#if WEB_SUPPORT
void _alexaWebSocketOnSend(JsonObject& root) { void _alexaWebSocketOnSend(JsonObject& root) {
root["alxVisible"] = 1; root["alxVisible"] = 1;
root["alxEnabled"] = getSetting("alxEnabled", ALEXA_ENABLED).toInt() == 1; root["alxEnabled"] = getSetting("alxEnabled", ALEXA_ENABLED).toInt() == 1;
} }
#endif
void _alexaConfigure() { void _alexaConfigure() {
alexa.enable(getSetting("alxEnabled", ALEXA_ENABLED).toInt() == 1); alexa.enable(getSetting("alxEnabled", ALEXA_ENABLED).toInt() == 1);
} }
bool _alexaKeyCheck(const char * key) {
return (strncmp(key, "alx", 3) == 0);
}
void _alexaBackwards() { void _alexaBackwards() {
moveSetting("fauxmoEnabled", "alxEnabled"); // 1.9.0 - 2017-08-25 moveSetting("fauxmoEnabled", "alxEnabled"); // 1.9.0 - 2017-08-25
moveSetting("alexaEnabled", "alxEnabled"); // 1.13.1 - 2018-06-27
moveSetting("alexaEnabled", "alxEnabled"); // 1.14.0 - 2018-06-27
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void alexaSetup() { void alexaSetup() {
@ -52,13 +55,10 @@ void alexaSetup() {
// Load & cache settings // Load & cache settings
_alexaConfigure(); _alexaConfigure();
// Websockets
#if WEB_SUPPORT #if WEB_SUPPORT
// Websockets
wsOnSendRegister(_alexaWebSocketOnSend); wsOnSendRegister(_alexaWebSocketOnSend);
wsOnAfterParseRegister(_alexaConfigure); wsOnAfterParseRegister(_alexaConfigure);
wsOnReceiveRegister(_alexaWebSocketOnReceive);
#endif #endif
unsigned int relays = relayCount(); unsigned int relays = relayCount();
@ -80,6 +80,8 @@ void alexaSetup() {
return relayStatus(device_id); return relayStatus(device_id);
}); });
settingsRegisterKeyCheck(_alexaKeyCheck);
// Register loop // Register loop
espurnaRegisterLoop(alexaLoop); espurnaRegisterLoop(alexaLoop);


+ 2
- 2
code/espurna/api.ino View File

@ -24,7 +24,7 @@ std::vector<web_api_t> _apis;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool _apiWebSocketOnReceive(const char * key, JsonVariant& value) {
bool _apiKeyCheck(const char * key) {
return (strncmp(key, "api", 3) == 0); return (strncmp(key, "api", 3) == 0);
} }
@ -198,7 +198,7 @@ void apiSetup() {
webServer()->on("/apis", HTTP_GET, _onAPIs); webServer()->on("/apis", HTTP_GET, _onAPIs);
webServer()->on("/rpc", HTTP_GET, _onRPC); webServer()->on("/rpc", HTTP_GET, _onRPC);
wsOnSendRegister(_apiWebSocketOnSend); wsOnSendRegister(_apiWebSocketOnSend);
wsOnReceiveRegister(_apiWebSocketOnReceive);
settingsRegisterKeyCheck(_apiKeyCheck);
} }
bool apiRealTime() { bool apiRealTime() {


+ 6
- 5
code/espurna/button.ino View File

@ -36,16 +36,16 @@ void buttonMQTT(unsigned char id, uint8_t event) {
#if WEB_SUPPORT #if WEB_SUPPORT
bool _buttonWebSocketOnReceive(const char * key, JsonVariant& value) {
return (strncmp(key, "btn", 3) == 0);
}
void _buttonWebSocketOnSend(JsonObject& root) { void _buttonWebSocketOnSend(JsonObject& root) {
root["btnDelay"] = getSetting("btnDelay", BUTTON_DBLCLICK_DELAY).toInt(); root["btnDelay"] = getSetting("btnDelay", BUTTON_DBLCLICK_DELAY).toInt();
} }
#endif #endif
bool _buttonKeyCheck(const char * key) {
return (strncmp(key, "btn", 3) == 0);
}
int buttonFromRelay(unsigned int relayID) { int buttonFromRelay(unsigned int relayID) {
for (unsigned int i=0; i < _buttons.size(); i++) { for (unsigned int i=0; i < _buttons.size(); i++) {
if (_buttons[i].relayID == relayID) return i; if (_buttons[i].relayID == relayID) return i;
@ -209,9 +209,10 @@ void buttonSetup() {
// Websocket Callbacks // Websocket Callbacks
#if WEB_SUPPORT #if WEB_SUPPORT
wsOnSendRegister(_buttonWebSocketOnSend); wsOnSendRegister(_buttonWebSocketOnSend);
wsOnReceiveRegister(_buttonWebSocketOnReceive);
#endif #endif
settingsRegisterKeyCheck(_buttonKeyCheck);
// Register loop // Register loop
espurnaRegisterLoop(buttonLoop); espurnaRegisterLoop(buttonLoop);


+ 2
- 3
code/espurna/config/prototypes.h View File

@ -39,9 +39,6 @@ void wsOnActionRegister(ws_on_action_callback_f callback);
typedef std::function<void(void)> ws_on_after_parse_callback_f; typedef std::function<void(void)> ws_on_after_parse_callback_f;
void wsOnAfterParseRegister(ws_on_after_parse_callback_f callback); void wsOnAfterParseRegister(ws_on_after_parse_callback_f callback);
typedef std::function<bool(const char *, JsonVariant&)> ws_on_receive_callback_f;
void wsOnReceiveRegister(ws_on_receive_callback_f callback);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// WIFI // WIFI
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -74,6 +71,8 @@ bool settingsRestoreJson(JsonObject& data);
void settingsRegisterCommand(const String& name, void (*call)(Embedis*)); void settingsRegisterCommand(const String& name, void (*call)(Embedis*));
void settingsInject(void *data, size_t len); void settingsInject(void *data, size_t len);
Stream & settingsSerial(); Stream & settingsSerial();
typedef std::function<bool(const char *)> setting_key_check_callback_f;
void settingsRegisterKeyCheck(setting_key_check_callback_f callback);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// I2C // I2C


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


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


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


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


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


+ 4
- 4
code/espurna/domoticz.ino View File

@ -82,12 +82,12 @@ void _domoticzMqtt(unsigned int type, const char * topic, const char * payload)
}; };
#if WEB_SUPPORT
bool _domoticzWebSocketOnReceive(const char * key, JsonVariant& value) {
bool _domoticzKeyCheck(const char * key) {
return (strncmp(key, "dcz", 3) == 0); return (strncmp(key, "dcz", 3) == 0);
} }
#if WEB_SUPPORT
void _domoticzWebSocketOnSend(JsonObject& root) { void _domoticzWebSocketOnSend(JsonObject& root) {
root["dczVisible"] = 1; root["dczVisible"] = 1;
@ -163,8 +163,8 @@ void domoticzSetup() {
#if WEB_SUPPORT #if WEB_SUPPORT
wsOnSendRegister(_domoticzWebSocketOnSend); wsOnSendRegister(_domoticzWebSocketOnSend);
wsOnAfterParseRegister(_domoticzConfigure); wsOnAfterParseRegister(_domoticzConfigure);
wsOnReceiveRegister(_domoticzWebSocketOnReceive);
#endif #endif
settingsRegisterKeyCheck(_domoticzKeyCheck);
mqttRegister(_domoticzMqtt); mqttRegister(_domoticzMqtt);
} }


+ 0
- 22
code/espurna/espurna.ino View File

@ -34,23 +34,6 @@ void espurnaRegisterLoop(void (*callback)()) {
_loop_callbacks.push_back(callback); _loop_callbacks.push_back(callback);
} }
// -----------------------------------------------------------------------------
// GLOBAL CONFIG KEYS
// -----------------------------------------------------------------------------
#if WEB_SUPPORT
bool _espWebSocketOnReceive(const char * key, JsonVariant& value) {
if (strncmp(key, "admin", 5) == 0) return true;
if (strncmp(key, "hostname", 8) == 0) return true;
if (strncmp(key, "board", 5) == 0) return true;
if (strncmp(key, "loopDelay", 9) == 0) return true;
if (strncmp(key, "wtfHeap", 7) == 0) return true;
return false;
}
#endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// BOOTING // BOOTING
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -189,11 +172,6 @@ void setup() {
saveSettings(); saveSettings();
// Global configuration settings
#if WEB_SUPPORT
wsOnReceiveRegister(_espWebSocketOnReceive);
#endif
} }
void loop() { void loop() {


+ 4
- 4
code/espurna/homeassistant.ino View File

@ -229,12 +229,12 @@ void _haConfigure() {
_haSend(); _haSend();
} }
#if WEB_SUPPORT
bool _haWebSocketOnReceive(const char * key, JsonVariant& value) {
bool _haKeyCheck(const char * key) {
return (strncmp(key, "ha", 2) == 0); return (strncmp(key, "ha", 2) == 0);
} }
#if WEB_SUPPORT
void _haWebSocketOnSend(JsonObject& root) { void _haWebSocketOnSend(JsonObject& root) {
root["haVisible"] = 1; root["haVisible"] = 1;
root["haPrefix"] = getSetting("haPrefix", HOMEASSISTANT_PREFIX); root["haPrefix"] = getSetting("haPrefix", HOMEASSISTANT_PREFIX);
@ -290,7 +290,6 @@ void haSetup() {
wsOnSendRegister(_haWebSocketOnSend); wsOnSendRegister(_haWebSocketOnSend);
wsOnAfterParseRegister(_haConfigure); wsOnAfterParseRegister(_haConfigure);
wsOnActionRegister(_haWebSocketOnAction); wsOnActionRegister(_haWebSocketOnAction);
wsOnReceiveRegister(_haWebSocketOnReceive);
#endif #endif
// On MQTT connect check if we have something to send // On MQTT connect check if we have something to send
@ -302,6 +301,7 @@ void haSetup() {
_haInitCommands(); _haInitCommands();
#endif #endif
settingsRegisterKeyCheck(_haKeyCheck);
} }


+ 3
- 8
code/espurna/i2c.ino View File

@ -106,13 +106,10 @@ int _i2cClearbus(int sda, int scl) {
} }
#if WEB_SUPPORT
bool _i2cWebSocketOnReceive(const char * key, JsonVariant& value) {
bool _i2cKeyCheck(const char * key) {
return (strncmp(key, "i2c", 3) == 0); return (strncmp(key, "i2c", 3) == 0);
} }
#endif // WEB_SUPPORT
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// I2C API // I2C API
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
@ -373,10 +370,6 @@ void i2cSetup() {
Wire.begin(sda, scl); Wire.begin(sda, scl);
#endif #endif
#if WEB_SUPPORT
wsOnReceiveRegister(_i2cWebSocketOnReceive);
#endif
DEBUG_MSG_P(PSTR("[I2C] Using GPIO%u for SDA and GPIO%u for SCL\n"), sda, scl); DEBUG_MSG_P(PSTR("[I2C] Using GPIO%u for SDA and GPIO%u for SCL\n"), sda, scl);
#if I2C_CLEAR_BUS #if I2C_CLEAR_BUS
@ -387,6 +380,8 @@ void i2cSetup() {
i2cScan(); i2cScan();
#endif #endif
settingsRegisterKeyCheck(_i2cKeyCheck);
} }
#endif #endif

+ 9
- 8
code/espurna/influxdb.ino View File

@ -20,10 +20,6 @@ SyncClient _idb_client;
#if WEB_SUPPORT #if WEB_SUPPORT
bool _idbWebSocketOnReceive(const char * key, JsonVariant& value) {
return (strncmp(key, "idb", 3) == 0);
}
void _idbWebSocketOnSend(JsonObject& root) { void _idbWebSocketOnSend(JsonObject& root) {
root["idbVisible"] = 1; root["idbVisible"] = 1;
root["idbEnabled"] = getSetting("idbEnabled", INFLUXDB_ENABLED).toInt() == 1; root["idbEnabled"] = getSetting("idbEnabled", INFLUXDB_ENABLED).toInt() == 1;
@ -44,10 +40,14 @@ void _idbConfigure() {
#endif // WEB_SUPPORT #endif // WEB_SUPPORT
bool _idbKeyCheck(const char * key) {
return (strncmp(key, "idb", 3) == 0);
}
void _idbBackwards() { void _idbBackwards() {
moveSetting("idbDatabase", "idbDB"); // 1.13.1 - 2018-06-26
moveSetting("idbUserName", "idbUser"); // 1.13.1 - 2018-06-26
moveSetting("idbPassword", "idbPass"); // 1.13.1 - 2018-06-26
moveSetting("idbDatabase", "idbDB"); // 1.14.0 - 2018-06-26
moveSetting("idbUserName", "idbUser"); // 1.14.0 - 2018-06-26
moveSetting("idbPassword", "idbPass"); // 1.14.0 - 2018-06-26
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -119,9 +119,10 @@ void idbSetup() {
#if WEB_SUPPORT #if WEB_SUPPORT
wsOnSendRegister(_idbWebSocketOnSend); wsOnSendRegister(_idbWebSocketOnSend);
wsOnAfterParseRegister(_idbConfigure); wsOnAfterParseRegister(_idbConfigure);
wsOnReceiveRegister(_idbWebSocketOnReceive);
#endif #endif
settingsRegisterKeyCheck(_idbKeyCheck);
} }
#endif #endif

+ 9
- 7
code/espurna/led.ino View File

@ -59,21 +59,22 @@ void _ledBlink(unsigned char id, unsigned long delayOff, unsigned long delayOn)
} }
} }
#if WEB_SUPPORT
bool _ledWebSocketOnReceive(const char * key, JsonVariant& value) {
bool _ledKeyCheck(const char * key) {
return (strncmp(key, "led", 3) == 0); return (strncmp(key, "led", 3) == 0);
} }
#if WEB_SUPPORT
void _ledWebSocketOnSend(JsonObject& root) { void _ledWebSocketOnSend(JsonObject& root) {
if (_ledCount() == 0) return; if (_ledCount() == 0) return;
root["ledVisible"] = 1; root["ledVisible"] = 1;
root["ledMode0"] = _ledMode(0); root["ledMode0"] = _ledMode(0);
} }
#endif
#endif // WEB_SUPPORT
#if MQTT_SUPPORT #if MQTT_SUPPORT
void _ledMQTTCallback(unsigned int type, const char * topic, const char * payload) { void _ledMQTTCallback(unsigned int type, const char * topic, const char * payload) {
if (type == MQTT_CONNECT_EVENT) { if (type == MQTT_CONNECT_EVENT) {
@ -111,7 +112,8 @@ void _ledMQTTCallback(unsigned int type, const char * topic, const char * payloa
} }
} }
#endif
#endif // MQTT_SUPPORT
unsigned char _ledCount() { unsigned char _ledCount() {
return _leds.size(); return _leds.size();
@ -171,13 +173,13 @@ void ledSetup() {
#if WEB_SUPPORT #if WEB_SUPPORT
wsOnSendRegister(_ledWebSocketOnSend); wsOnSendRegister(_ledWebSocketOnSend);
wsOnAfterParseRegister(_ledConfigure); wsOnAfterParseRegister(_ledConfigure);
wsOnReceiveRegister(_ledWebSocketOnReceive);
#endif #endif
DEBUG_MSG_P(PSTR("[LED] Number of leds: %d\n"), _leds.size()); DEBUG_MSG_P(PSTR("[LED] Number of leds: %d\n"), _leds.size());
// Register loop
// Registers
espurnaRegisterLoop(ledLoop); espurnaRegisterLoop(ledLoop);
settingsRegisterKeyCheck(_ledKeyCheck);
} }


+ 17
- 17
code/espurna/light.ino View File

@ -761,11 +761,6 @@ void lightBrightnessStep(int steps) {
#if WEB_SUPPORT #if WEB_SUPPORT
bool _lightWebSocketOnReceive(const char * key, JsonVariant& value) {
if (strncmp(key, "lit", 3) == 0) return true;
return false;
}
void _lightWebSocketOnSend(JsonObject& root) { void _lightWebSocketOnSend(JsonObject& root) {
root["litVisible"] = 1; root["litVisible"] = 1;
root["mqttGroupColor"] = getSetting("mqttGroupColor"); root["mqttGroupColor"] = getSetting("mqttGroupColor");
@ -1010,18 +1005,22 @@ void _lightConfigure() {
} }
bool _lightKeyCheck(const char * key) {
return (strncmp(key, "lit", 3) == 0);
}
void _lightBackwards() { void _lightBackwards() {
moveSettings("ch", "litCH"); // 1.13.1 - 2018-06-26
moveSetting("useCSS", "litCSS"); // 1.13.1 - 2018-06-26
moveSetting("useRGB", "litRGB"); // 1.13.1 - 2018-06-26
moveSetting("useColor", "litColor"); // 1.13.1 - 2018-06-26
moveSetting("useWhite", "litWhite"); // 1.13.1 - 2018-06-26
moveSetting("useCCT", "litCCT"); // 1.13.1 - 2018-06-26
moveSetting("useGamma", "litGamma"); // 1.13.1 - 2018-06-26
moveSetting("useTransitions", "litTrans"); // 1.13.1 - 2018-06-26
moveSetting("lightTime", "litTime"); // 1.13.1 - 2018-06-26
moveSetting("brightness", "litBright"); // 1.13.1 - 2018-06-26
moveSetting("mireds", "litMireds"); // 1.13.1 - 2018-06-26
moveSettings("ch", "litCH"); // 1.14.0 - 2018-06-26
moveSetting("useCSS", "litCSS"); // 1.14.0 - 2018-06-26
moveSetting("useRGB", "litRGB"); // 1.14.0 - 2018-06-26
moveSetting("useColor", "litColor"); // 1.14.0 - 2018-06-26
moveSetting("useWhite", "litWhite"); // 1.14.0 - 2018-06-26
moveSetting("useCCT", "litCCT"); // 1.14.0 - 2018-06-26
moveSetting("useGamma", "litGamma"); // 1.14.0 - 2018-06-26
moveSetting("useTransitions", "litTrans"); // 1.14.0 - 2018-06-26
moveSetting("lightTime", "litTime"); // 1.14.0 - 2018-06-26
moveSetting("brightness", "litBright"); // 1.14.0 - 2018-06-26
moveSetting("mireds", "litMireds"); // 1.14.0 - 2018-06-26
} }
void lightSetup() { void lightSetup() {
@ -1089,7 +1088,6 @@ void lightSetup() {
_lightAPISetup(); _lightAPISetup();
wsOnSendRegister(_lightWebSocketOnSend); wsOnSendRegister(_lightWebSocketOnSend);
wsOnActionRegister(_lightWebSocketOnAction); wsOnActionRegister(_lightWebSocketOnAction);
wsOnReceiveRegister(_lightWebSocketOnReceive);
wsOnAfterParseRegister([]() { wsOnAfterParseRegister([]() {
#if LIGHT_SAVE_ENABLED == 0 #if LIGHT_SAVE_ENABLED == 0
lightSave(); lightSave();
@ -1106,6 +1104,8 @@ void lightSetup() {
_lightInitCommands(); _lightInitCommands();
#endif #endif
settingsRegisterKeyCheck(_lightKeyCheck);
} }
#endif // LIGHT_PROVIDER != LIGHT_PROVIDER_NONE #endif // LIGHT_PROVIDER != LIGHT_PROVIDER_NONE

+ 16
- 12
code/espurna/mqtt.ino View File

@ -121,7 +121,7 @@ void _mqttConnect() {
#if ASYNC_TCP_SSL_ENABLED #if ASYNC_TCP_SSL_ENABLED
bool secure = getSetting("mqttUseSSL", MQTT_SSL_ENABLED).toInt() == 1;
bool secure = getSetting("mqttSSL", MQTT_SSL_ENABLED).toInt() == 1;
_mqtt.setSecure(secure); _mqtt.setSecure(secure);
if (secure) { if (secure) {
DEBUG_MSG_P(PSTR("[MQTT] Using SSL\n")); DEBUG_MSG_P(PSTR("[MQTT] Using SSL\n"));
@ -149,7 +149,7 @@ void _mqttConnect() {
#if ASYNC_TCP_SSL_ENABLED #if ASYNC_TCP_SSL_ENABLED
bool secure = getSetting("mqttUseSSL", MQTT_SSL_ENABLED).toInt() == 1;
bool secure = getSetting("mqttSSL", MQTT_SSL_ENABLED).toInt() == 1;
if (secure) { if (secure) {
DEBUG_MSG_P(PSTR("[MQTT] Using SSL\n")); DEBUG_MSG_P(PSTR("[MQTT] Using SSL\n"));
if (_mqtt_client_secure.connect(host, port)) { if (_mqtt_client_secure.connect(host, port)) {
@ -244,13 +244,17 @@ void _mqttConfigure() {
} else { } else {
_mqtt_enabled = getSetting("mqttEnabled", MQTT_ENABLED).toInt() == 1; _mqtt_enabled = getSetting("mqttEnabled", MQTT_ENABLED).toInt() == 1;
} }
_mqtt_use_json = (getSetting("mqttUseJson", MQTT_USE_JSON).toInt() == 1);
_mqtt_use_json = (getSetting("mqttJson", MQTT_USE_JSON).toInt() == 1);
mqttQueueTopic(MQTT_TOPIC_JSON); mqttQueueTopic(MQTT_TOPIC_JSON);
_mqtt_reconnect_delay = MQTT_RECONNECT_DELAY_MIN; _mqtt_reconnect_delay = MQTT_RECONNECT_DELAY_MIN;
} }
bool _mqttKeyCheck(const char * key) {
return (strncmp(key, "mqtt", 3) == 0);
}
void _mqttBackwards() { void _mqttBackwards() {
// 1.13.0 - 2018-05-30 // 1.13.0 - 2018-05-30
@ -260,7 +264,11 @@ void _mqttBackwards() {
setSetting("mqttTopic", mqttTopic); setSetting("mqttTopic", mqttTopic);
} }
moveSetting("mqttPassword", "mqttPass"); // 1.13.1 - 2018-06-26
moveSetting("mqttPassword", "mqttPass"); // 1.14.0 - 2018-06-26
moveSetting("mqttUseJson", "mqttJson"); // 1.14.0 - 2018-06-27
moveSetting("mqttUseSSL", "mqttSSL"); // 1.14.0 - 2018-06-27
delSetting("mqttOnDisc"); // 1.14.0 - 2018-06-27
} }
@ -312,10 +320,6 @@ unsigned long _mqttNextMessageId() {
#if WEB_SUPPORT #if WEB_SUPPORT
bool _mqttWebSocketOnReceive(const char * key, JsonVariant& value) {
return (strncmp(key, "mqtt", 3) == 0);
}
void _mqttWebSocketOnSend(JsonObject& root) { void _mqttWebSocketOnSend(JsonObject& root) {
root["mqttVisible"] = 1; root["mqttVisible"] = 1;
root["mqttStatus"] = mqttConnected(); root["mqttStatus"] = mqttConnected();
@ -330,11 +334,11 @@ void _mqttWebSocketOnSend(JsonObject& root) {
root["mqttQoS"] = _mqtt_qos; root["mqttQoS"] = _mqtt_qos;
#if ASYNC_TCP_SSL_ENABLED #if ASYNC_TCP_SSL_ENABLED
root["mqttsslVisible"] = 1; root["mqttsslVisible"] = 1;
root["mqttUseSSL"] = getSetting("mqttUseSSL", MQTT_SSL_ENABLED).toInt() == 1;
root["mqttSSL"] = getSetting("mqttSSL", MQTT_SSL_ENABLED).toInt() == 1;
root["mqttFP"] = getSetting("mqttFP", MQTT_SSL_FINGERPRINT); root["mqttFP"] = getSetting("mqttFP", MQTT_SSL_FINGERPRINT);
#endif #endif
root["mqttTopic"] = getSetting("mqttTopic", MQTT_TOPIC); root["mqttTopic"] = getSetting("mqttTopic", MQTT_TOPIC);
root["mqttUseJson"] = getSetting("mqttUseJson", MQTT_USE_JSON).toInt() == 1;
root["mqttJson"] = getSetting("mqttJson", MQTT_USE_JSON).toInt() == 1;
} }
#endif #endif
@ -818,15 +822,15 @@ void mqttSetup() {
#if WEB_SUPPORT #if WEB_SUPPORT
wsOnSendRegister(_mqttWebSocketOnSend); wsOnSendRegister(_mqttWebSocketOnSend);
wsOnAfterParseRegister(_mqttConfigure); wsOnAfterParseRegister(_mqttConfigure);
wsOnReceiveRegister(_mqttWebSocketOnReceive);
#endif #endif
#if TERMINAL_SUPPORT #if TERMINAL_SUPPORT
_mqttInitCommands(); _mqttInitCommands();
#endif #endif
// Register loop
// Register
espurnaRegisterLoop(mqttLoop); espurnaRegisterLoop(mqttLoop);
settingsRegisterKeyCheck(_mqttKeyCheck);
} }


+ 10
- 10
code/espurna/nofuss.ino View File

@ -22,17 +22,13 @@ bool _nofussEnabled = false;
#if WEB_SUPPORT #if WEB_SUPPORT
bool _nofussWebSocketOnReceive(const char * key, JsonVariant& value) {
return (strncmp(key, "nof", 6) == 0);
}
void _nofussWebSocketOnSend(JsonObject& root) { void _nofussWebSocketOnSend(JsonObject& root) {
root["nofVisible"] = 1; root["nofVisible"] = 1;
root["nofEnabled"] = getSetting("nofEnabled", NOFUSS_ENABLED).toInt() == 1; root["nofEnabled"] = getSetting("nofEnabled", NOFUSS_ENABLED).toInt() == 1;
root["nofServer"] = getSetting("nofServer", NOFUSS_SERVER); root["nofServer"] = getSetting("nofServer", NOFUSS_SERVER);
} }
#endif
#endif // WEB_SUPPORT
void _nofussConfigure() { void _nofussConfigure() {
@ -72,10 +68,14 @@ void _nofussConfigure() {
} }
bool _nofussKeyCheck(const char * key) {
return (strncmp(key, "nof", 6) == 0);
}
void _nofussBackwards() { void _nofussBackwards() {
moveSettings("nofussServer", "nofServer"); // 1.13.1 2018-06-26
moveSettings("nofussEnabled", "nofEnabled"); // 1.13.1 2018-06-26
moveSettings("nofussInterval", "nofInterval"); // 1.13.1 2018-06-26
moveSettings("nofussServer", "nofServer"); // 1.14.0 2018-06-26
moveSettings("nofussEnabled", "nofEnabled"); // 1.14.0 2018-06-26
moveSettings("nofussInterval", "nofInterval"); // 1.14.0 2018-06-26
} }
#if TERMINAL_SUPPORT #if TERMINAL_SUPPORT
@ -164,15 +164,15 @@ void nofussSetup() {
#if WEB_SUPPORT #if WEB_SUPPORT
wsOnSendRegister(_nofussWebSocketOnSend); wsOnSendRegister(_nofussWebSocketOnSend);
wsOnAfterParseRegister(_nofussConfigure); wsOnAfterParseRegister(_nofussConfigure);
wsOnReceiveRegister(_nofussWebSocketOnReceive);
#endif #endif
#if TERMINAL_SUPPORT #if TERMINAL_SUPPORT
_nofussInitCommands(); _nofussInitCommands();
#endif #endif
// Register loop
// Register
espurnaRegisterLoop(nofussLoop); espurnaRegisterLoop(nofussLoop);
settingsRegisterKeyCheck(_nofussKeyCheck);
} }


+ 6
- 6
code/espurna/ntp.ino View File

@ -25,10 +25,6 @@ bool _ntp_configure = false;
#if WEB_SUPPORT #if WEB_SUPPORT
bool _ntpWebSocketOnReceive(const char * key, JsonVariant& value) {
return (strncmp(key, "ntp", 3) == 0);
}
void _ntpWebSocketOnSend(JsonObject& root) { void _ntpWebSocketOnSend(JsonObject& root) {
root["ntpVisible"] = 1; root["ntpVisible"] = 1;
root["ntpStatus"] = (timeStatus() == timeSet); root["ntpStatus"] = (timeStatus() == timeSet);
@ -116,6 +112,10 @@ void _ntpLoop() {
} }
bool _ntpKeyCheck(const char * key) {
return (strncmp(key, "ntp", 3) == 0);
}
void _ntpBackwards() { void _ntpBackwards() {
// 1.12.0 - 2018-01-21 // 1.12.0 - 2018-01-21
@ -186,12 +186,12 @@ void ntpSetup() {
#if WEB_SUPPORT #if WEB_SUPPORT
wsOnSendRegister(_ntpWebSocketOnSend); wsOnSendRegister(_ntpWebSocketOnSend);
wsOnReceiveRegister(_ntpWebSocketOnReceive);
wsOnAfterParseRegister([]() { _ntp_configure = true; }); wsOnAfterParseRegister([]() { _ntp_configure = true; });
#endif #endif
// Register loop
// Register
espurnaRegisterLoop(_ntpLoop); espurnaRegisterLoop(_ntpLoop);
settingsRegisterKeyCheck(_ntpKeyCheck);
} }


+ 4
- 6
code/espurna/ota.ino View File

@ -199,14 +199,10 @@ void _otaInitCommands() {
#endif // TERMINAL_SUPPORT #endif // TERMINAL_SUPPORT
#if WEB_SUPPORT
bool _otaWebSocketOnReceive(const char * key, JsonVariant& value) {
bool _otaKeyCheck(const char * key) {
return (strncmp(key, "ota", 3) == 0); return (strncmp(key, "ota", 3) == 0);
} }
#endif // WEB_SUPPORT
void _otaBackwards() { void _otaBackwards() {
moveSetting("otafs", "otaFS"); moveSetting("otafs", "otaFS");
} }
@ -220,13 +216,15 @@ void otaSetup() {
#if WEB_SUPPORT #if WEB_SUPPORT
wsOnAfterParseRegister(_otaConfigure); wsOnAfterParseRegister(_otaConfigure);
wsOnReceiveRegister(_otaWebSocketOnReceive);
#endif #endif
#if TERMINAL_SUPPORT #if TERMINAL_SUPPORT
_otaInitCommands(); _otaInitCommands();
#endif #endif
// Register settings key check
settingsRegisterKeyCheck(_otaKeyCheck);
// Register loop // Register loop
espurnaRegisterLoop(_otaLoop); espurnaRegisterLoop(_otaLoop);


+ 6
- 7
code/espurna/relay.ino View File

@ -414,7 +414,10 @@ unsigned char relayParsePayload(const char * payload) {
} }
// BACKWARDS COMPATIBILITY
bool _relayKeyCheck(const char * key) {
return (strncmp(key, "rly", 3) == 0);
}
void _relayBackwards() { void _relayBackwards() {
// 1.11.0 - 2017-12-26 // 1.11.0 - 2017-12-26
@ -431,7 +434,7 @@ void _relayBackwards() {
delSetting("relayPulseMode"); delSetting("relayPulseMode");
delSetting("relayPulseTime"); delSetting("relayPulseTime");
// 1.13.1 - 2018-06-26
// 1.14.0 - 2018-06-26
moveSettings("relayBoot", "rlyBoot"); moveSettings("relayBoot", "rlyBoot");
moveSettings("relayPulse", "rlyPulse"); moveSettings("relayPulse", "rlyPulse");
moveSettings("relayTime", "rlyTime"); moveSettings("relayTime", "rlyTime");
@ -510,10 +513,6 @@ void _relayConfigure() {
#if WEB_SUPPORT #if WEB_SUPPORT
bool _relayWebSocketOnReceive(const char * key, JsonVariant& value) {
return (strncmp(key, "rly", 3) == 0);
}
void _relayWebSocketUpdate(JsonObject& root) { void _relayWebSocketUpdate(JsonObject& root) {
JsonArray& relay = root.createNestedArray("relayStatus"); JsonArray& relay = root.createNestedArray("relayStatus");
for (unsigned char i=0; i<relayCount(); i++) { for (unsigned char i=0; i<relayCount(); i++) {
@ -593,7 +592,6 @@ void relaySetupWS() {
wsOnSendRegister(_relayWebSocketOnStart); wsOnSendRegister(_relayWebSocketOnStart);
wsOnActionRegister(_relayWebSocketOnAction); wsOnActionRegister(_relayWebSocketOnAction);
wsOnAfterParseRegister(_relayConfigure); wsOnAfterParseRegister(_relayConfigure);
wsOnReceiveRegister(_relayWebSocketOnReceive);
} }
#endif // WEB_SUPPORT #endif // WEB_SUPPORT
@ -948,6 +946,7 @@ void relaySetup() {
_relayBoot(); _relayBoot();
_relayLoop(); _relayLoop();
settingsRegisterKeyCheck(_relayKeyCheck);
espurnaRegisterLoop(_relayLoop); espurnaRegisterLoop(_relayLoop);
#if WEB_SUPPORT #if WEB_SUPPORT


+ 6
- 5
code/espurna/scheduler.ino View File

@ -17,10 +17,6 @@ Module key prefix: sch
#if WEB_SUPPORT #if WEB_SUPPORT
bool _schWebSocketOnReceive(const char * key, JsonVariant& value) {
return (strncmp(key, "sch", 3) == 0);
}
void _schWebSocketOnSend(JsonObject &root){ void _schWebSocketOnSend(JsonObject &root){
if (relayCount() > 0) { if (relayCount() > 0) {
@ -49,6 +45,10 @@ void _schWebSocketOnSend(JsonObject &root){
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool _schKeyCheck(const char * key) {
return (strncmp(key, "sch", 3) == 0);
}
void _schConfigure() { void _schConfigure() {
bool delete_flag = false; bool delete_flag = false;
@ -217,10 +217,11 @@ void schSetup() {
// Update websocket clients // Update websocket clients
#if WEB_SUPPORT #if WEB_SUPPORT
wsOnSendRegister(_schWebSocketOnSend); wsOnSendRegister(_schWebSocketOnSend);
wsOnReceiveRegister(_schWebSocketOnReceive);
wsOnAfterParseRegister(_schConfigure); wsOnAfterParseRegister(_schConfigure);
#endif #endif
settingsRegisterKeyCheck(_schKeyCheck);
// Register loop // Register loop
espurnaRegisterLoop(_schLoop); espurnaRegisterLoop(_schLoop);


+ 30
- 24
code/espurna/sensor.ino View File

@ -97,17 +97,6 @@ double _magnitudeProcess(unsigned char type, double value) {
#if WEB_SUPPORT #if WEB_SUPPORT
bool _sensorWebSocketOnReceive(const char * key, JsonVariant& value) {
if (strncmp(key, "sns", 3) == 0) return true;
if (strncmp(key, "pwr", 3) == 0) return true;
if (strncmp(key, "ene", 3) == 0) return true;
if (strncmp(key, "cur", 3) == 0) return true;
if (strncmp(key, "vol", 3) == 0) return true;
if (strncmp(key, "tmp", 3) == 0) return true;
if (strncmp(key, "hum", 3) == 0) return true;
return false;
}
void _sensorWebSocketSendData(JsonObject& root) { void _sensorWebSocketSendData(JsonObject& root) {
char buffer[10]; char buffer[10];
@ -842,20 +831,36 @@ void _sensorConfigure() {
} }
bool _sensorKeyCheck(const char * key) {
if (strncmp(key, "sns", 3) == 0) return true;
if (strncmp(key, "pwr", 3) == 0) return true;
if (strncmp(key, "ene", 3) == 0) return true;
if (strncmp(key, "cur", 3) == 0) return true;
if (strncmp(key, "vol", 3) == 0) return true;
if (strncmp(key, "tmp", 3) == 0) return true;
if (strncmp(key, "hum", 3) == 0) return true;
if (strncmp(key, "hlw", 3) == 0) return true;
return false;
}
void _sensorBackwards() { void _sensorBackwards() {
moveSetting("powerUnits", "pwrUnits"); // 1.12.5 - 2018-04-03 moveSetting("powerUnits", "pwrUnits"); // 1.12.5 - 2018-04-03
moveSetting("tmpCorrection", "tmpOffset"); // 1.13.1 - 2018-06-26
moveSetting("humCorrection", "humOffset"); // 1.13.1 - 2018-06-26
moveSetting("energyUnits", "eneUnits"); // 1.13.1 - 2018-06-26
moveSetting("pwrRatioC", "curRatio"); // 1.13.1 - 2018-06-26
moveSetting("pwrRatioP", "pwrRatio"); // 1.13.1 - 2018-06-26
moveSetting("pwrRatioV", "volRatio"); // 1.13.1 - 2018-06-26
moveSetting("pwrVoltage", "volNominal"); // 1.13.1 - 2018-06-26
moveSetting("pwrExpectedP", "pwrExpected"); // 1.13.1 - 2018-06-26
moveSetting("pwrExpectedC", "curExpected"); // 1.13.1 - 2018-06-26
moveSetting("pwrExpectedV", "volExpected"); // 1.13.1 - 2018-06-26
moveSetting("pwrResetCalibration", "snsResetCalibration"); // 1.13.1 - 2018-06-26
moveSetting("pwrResetE", "eneReset"); // 1.13.1 - 2018-06-26
moveSetting("tmpCorrection", "tmpOffset"); // 1.14.0 - 2018-06-26
moveSetting("humCorrection", "humOffset"); // 1.14.0 - 2018-06-26
moveSetting("energyUnits", "eneUnits"); // 1.14.0 - 2018-06-26
moveSetting("pwrRatioC", "curRatio"); // 1.14.0 - 2018-06-26
moveSetting("pwrRatioP", "pwrRatio"); // 1.14.0 - 2018-06-26
moveSetting("pwrRatioV", "volRatio"); // 1.14.0 - 2018-06-26
moveSetting("pwrVoltage", "volNominal"); // 1.14.0 - 2018-06-26
moveSetting("pwrExpectedP", "pwrExpected"); // 1.14.0 - 2018-06-26
moveSetting("pwrExpectedC", "curExpected"); // 1.14.0 - 2018-06-26
moveSetting("pwrExpectedV", "volExpected"); // 1.14.0 - 2018-06-26
moveSetting("pwrResetCalibration", "snsResetCalibration"); // 1.14.0 - 2018-06-26
moveSetting("pwrResetE", "eneReset"); // 1.14.0 - 2018-06-26
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -950,7 +955,6 @@ void sensorSetup() {
// Websockets // Websockets
wsOnSendRegister(_sensorWebSocketStart); wsOnSendRegister(_sensorWebSocketStart);
wsOnReceiveRegister(_sensorWebSocketOnReceive);
wsOnSendRegister(_sensorWebSocketSendData); wsOnSendRegister(_sensorWebSocketSendData);
wsOnAfterParseRegister(_sensorConfigure); wsOnAfterParseRegister(_sensorConfigure);
@ -963,6 +967,8 @@ void sensorSetup() {
_sensorInitCommands(); _sensorInitCommands();
#endif #endif
settingsRegisterKeyCheck(_sensorKeyCheck);
// Register loop // Register loop
espurnaRegisterLoop(sensorLoop); espurnaRegisterLoop(sensorLoop);


+ 57
- 0
code/espurna/settings.ino View File

@ -26,6 +26,8 @@ EmbedisWrap embedis(_serial, TERMINAL_BUFFER_SIZE);
bool _settings_save = false; bool _settings_save = false;
std::vector<setting_key_check_callback_f> _setting_key_check_callbacks;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Reverse engineering EEPROM storage format // Reverse engineering EEPROM storage format
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -40,6 +42,13 @@ unsigned long settingsSize() {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool settingsKeyExists(const char * key) {
for (unsigned char i = 0; i < _setting_key_check_callbacks.size(); i++) {
if ((_setting_key_check_callbacks[i])(key)) return true;
}
return false;
}
unsigned int settingsKeyCount() { unsigned int settingsKeyCount() {
unsigned count = 0; unsigned count = 0;
unsigned pos = SPI_FLASH_SEC_SIZE - 1; unsigned pos = SPI_FLASH_SEC_SIZE - 1;
@ -107,6 +116,16 @@ std::vector<String> _settingsKeys() {
return keys; return keys;
} }
bool _settingsKeyCheck(const char * key) {
if (strncmp(key, "admin", 5) == 0) return true;
if (strncmp(key, "hostname", 8) == 0) return true;
if (strncmp(key, "board", 5) == 0) return true;
if (strncmp(key, "loopDelay", 9) == 0) return true;
if (strncmp(key, "wtfHeap", 7) == 0) return true;
if (strncmp(key, "cfg", 3) == 0) return true;
return false;
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Commands // Commands
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -163,6 +182,28 @@ void _settingsKeysCommand() {
} }
void _settingsCleanCommand(bool do_delete) {
// Get sorted list of keys
std::vector<String> keys = _settingsKeys();
unsigned int count = 0;
for (unsigned int i=0; i<keys.size(); i++) {
if (!settingsKeyExists((keys[i]).c_str())) {
if (do_delete) {
delSetting(keys[i]);
DEBUG_MSG_P(PSTR("> %s deleted\n"), (keys[i]).c_str());
} else {
DEBUG_MSG_P(PSTR("> %s is safe to delete\n"), (keys[i]).c_str());
}
++count;
}
}
DEBUG_MSG_P(PSTR("%u unknown key(s) found\n"), count);
}
void _settingsFactoryResetCommand() { void _settingsFactoryResetCommand() {
for (unsigned int i = 0; i < SPI_FLASH_SEC_SIZE; i++) { for (unsigned int i = 0; i < SPI_FLASH_SEC_SIZE; i++) {
EEPROMr.write(i, 0xFF); EEPROMr.write(i, 0xFF);
@ -180,6 +221,15 @@ void _settingsInitCommands() {
}); });
#endif #endif
settingsRegisterCommand(F("CLEAN"), [](Embedis* e) {
bool do_delete = false;
if (e->argc > 1) {
do_delete = String(e->argv[1]).toInt() == 1;
}
_settingsCleanCommand(do_delete);
DEBUG_MSG_P(PSTR("+OK\n"));
});
settingsRegisterCommand(F("COMMANDS"), [](Embedis* e) { settingsRegisterCommand(F("COMMANDS"), [](Embedis* e) {
_settingsHelpCommand(); _settingsHelpCommand();
DEBUG_MSG_P(PSTR("+OK\n")); DEBUG_MSG_P(PSTR("+OK\n"));
@ -443,6 +493,10 @@ void settingsRegisterCommand(const String& name, void (*call)(Embedis*)) {
Embedis::command(name, call); Embedis::command(name, call);
}; };
void settingsRegisterKeyCheck(setting_key_check_callback_f callback) {
_setting_key_check_callbacks.push_back(callback);
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Initialization // Initialization
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -479,6 +533,9 @@ void settingsSetup() {
#endif // SERIAL_RX_ENABLED #endif // SERIAL_RX_ENABLED
#endif // TERMINAL_SUPPORT #endif // TERMINAL_SUPPORT
// Register key check
settingsRegisterKeyCheck(_settingsKeyCheck);
// Register loop // Register loop
espurnaRegisterLoop(settingsLoop); espurnaRegisterLoop(settingsLoop);


+ 2444
- 2444
code/espurna/static/index.all.html.gz.h
File diff suppressed because it is too large
View File


+ 2317
- 2317
code/espurna/static/index.light.html.gz.h
File diff suppressed because it is too large
View File


+ 1982
- 1982
code/espurna/static/index.rfbridge.html.gz.h
File diff suppressed because it is too large
View File


+ 2021
- 2021
code/espurna/static/index.sensor.html.gz.h
File diff suppressed because it is too large
View File


+ 1939
- 1939
code/espurna/static/index.small.html.gz.h
File diff suppressed because it is too large
View File


+ 7
- 6
code/espurna/telnet.ino View File

@ -24,10 +24,6 @@ bool _telnetFirst = true;
#if WEB_SUPPORT #if WEB_SUPPORT
bool _telnetWebSocketOnReceive(const char * key, JsonVariant& value) {
return (strncmp(key, "telt", 3) == 0);
}
void _telnetWebSocketOnSend(JsonObject& root) { void _telnetWebSocketOnSend(JsonObject& root) {
root["telVisible"] = 1; root["telVisible"] = 1;
root["telSTA"] = getSetting("telSTA", TELNET_STA).toInt() == 1; root["telSTA"] = getSetting("telSTA", TELNET_STA).toInt() == 1;
@ -162,8 +158,12 @@ void _telnetNewClient(AsyncClient *client) {
} }
bool _telnetKeyCheck(const char * key) {
return (strncmp(key, "telt", 3) == 0);
}
void _telnetBackwards() { void _telnetBackwards() {
moveSetting("telnetSTA", "telSTA"); // 1.13.1 -- 2018-06-26
moveSetting("telnetSTA", "telSTA"); // 1.14.0 -- 2018-06-26
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -195,9 +195,10 @@ void telnetSetup() {
#if WEB_SUPPORT #if WEB_SUPPORT
wsOnSendRegister(_telnetWebSocketOnSend); wsOnSendRegister(_telnetWebSocketOnSend);
wsOnReceiveRegister(_telnetWebSocketOnReceive);
#endif #endif
settingsRegisterKeyCheck(_telnetKeyCheck);
DEBUG_MSG_P(PSTR("[TELNET] Listening on port %d\n"), TELNET_PORT); DEBUG_MSG_P(PSTR("[TELNET] Listening on port %d\n"), TELNET_PORT);
} }


+ 5
- 4
code/espurna/thinkspeak.ino View File

@ -34,12 +34,12 @@ unsigned long _tspk_last_flush = 0;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#if WEB_SUPPORT
bool _tspkWebSocketOnReceive(const char * key, JsonVariant& value) {
bool _tspkKeyCheck(const char * key) {
return (strncmp(key, "tspk", 4) == 0); return (strncmp(key, "tspk", 4) == 0);
} }
#if WEB_SUPPORT
void _tspkWebSocketOnSend(JsonObject& root) { void _tspkWebSocketOnSend(JsonObject& root) {
unsigned char visible = 0; unsigned char visible = 0;
@ -262,7 +262,6 @@ void tspkSetup() {
#if WEB_SUPPORT #if WEB_SUPPORT
wsOnSendRegister(_tspkWebSocketOnSend); wsOnSendRegister(_tspkWebSocketOnSend);
wsOnAfterParseRegister(_tspkConfigure); wsOnAfterParseRegister(_tspkConfigure);
wsOnReceiveRegister(_tspkWebSocketOnReceive);
#endif #endif
DEBUG_MSG_P(PSTR("[THINGSPEAK] Async %s, SSL %s\n"), DEBUG_MSG_P(PSTR("[THINGSPEAK] Async %s, SSL %s\n"),
@ -270,6 +269,8 @@ void tspkSetup() {
THINGSPEAK_USE_SSL ? "ENABLED" : "DISABLED" THINGSPEAK_USE_SSL ? "ENABLED" : "DISABLED"
); );
settingsRegisterKeyCheck(_tspkKeyCheck);
// Register loop // Register loop
espurnaRegisterLoop(tspkLoop); espurnaRegisterLoop(tspkLoop);


+ 5
- 4
code/espurna/web.ino View File

@ -367,9 +367,8 @@ void _webWebSocketOnSend(JsonObject& root) {
root["webPort"] = webPort(); root["webPort"] = webPort();
} }
bool _webWebSocketOnReceive(const char * key, JsonVariant& value) {
if (strncmp(key, "web", 3) == 0) return true;
return false;
bool _webKeyCheck(const char * key) {
return (strncmp(key, "web", 3) == 0);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -459,7 +458,9 @@ void webSetup() {
// Websocket Callbacks // Websocket Callbacks
wsOnSendRegister(_webWebSocketOnSend); wsOnSendRegister(_webWebSocketOnSend);
wsOnReceiveRegister(_webWebSocketOnReceive);
// Settings key check register
settingsRegisterKeyCheck(_webKeyCheck);
} }


+ 9
- 6
code/espurna/wifi.ino View File

@ -425,11 +425,6 @@ void _wifiInitCommands() {
#if WEB_SUPPORT #if WEB_SUPPORT
bool _wifiWebSocketOnReceive(const char * key, JsonVariant& value) {
if (strncmp(key, "wifi", 4) == 0) return true;
return false;
}
void _wifiWebSocketOnSend(JsonObject& root) { void _wifiWebSocketOnSend(JsonObject& root) {
root["maxNetworks"] = WIFI_MAX_NETWORKS; root["maxNetworks"] = WIFI_MAX_NETWORKS;
root["wifiScan"] = getSetting("wifiScan", WIFI_SCAN_NETWORKS).toInt() == 1; root["wifiScan"] = getSetting("wifiScan", WIFI_SCAN_NETWORKS).toInt() == 1;
@ -452,7 +447,13 @@ void _wifiWebSocketOnAction(uint32_t client_id, const char * action, JsonObject&
#endif #endif
bool _wifiKeyCheck(const char * key) {
return (strncmp(key, "wifi", 4) == 0);
}
void _wifiBackwards() { void _wifiBackwards() {
// 1.14.0 - 2018-06-27
moveSettings("ssid", "wifiName"); moveSettings("ssid", "wifiName");
moveSettings("pass", "wifiPass"); moveSettings("pass", "wifiPass");
moveSettings("ip", "wifiIP"); moveSettings("ip", "wifiIP");
@ -460,6 +461,7 @@ void _wifiBackwards() {
moveSettings("mask", "wifiMask"); moveSettings("mask", "wifiMask");
moveSettings("dns", "wifiDNS"); moveSettings("dns", "wifiDNS");
moveSetting("apmode", "wifiMode"); moveSetting("apmode", "wifiMode");
delSetting("wifiGain");
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -613,7 +615,6 @@ void wifiSetup() {
#if WEB_SUPPORT #if WEB_SUPPORT
wsOnSendRegister(_wifiWebSocketOnSend); wsOnSendRegister(_wifiWebSocketOnSend);
wsOnReceiveRegister(_wifiWebSocketOnReceive);
wsOnAfterParseRegister(_wifiConfigure); wsOnAfterParseRegister(_wifiConfigure);
wsOnActionRegister(_wifiWebSocketOnAction); wsOnActionRegister(_wifiWebSocketOnAction);
#endif #endif
@ -622,6 +623,8 @@ void wifiSetup() {
_wifiInitCommands(); _wifiInitCommands();
#endif #endif
settingsRegisterKeyCheck(_wifiKeyCheck);
// Register loop // Register loop
espurnaRegisterLoop(wifiLoop); espurnaRegisterLoop(wifiLoop);


+ 7
- 19
code/espurna/ws.ino View File

@ -23,7 +23,6 @@ Ticker _web_defer;
std::vector<ws_on_send_callback_f> _ws_on_send_callbacks; std::vector<ws_on_send_callback_f> _ws_on_send_callbacks;
std::vector<ws_on_action_callback_f> _ws_on_action_callbacks; std::vector<ws_on_action_callback_f> _ws_on_action_callbacks;
std::vector<ws_on_after_parse_callback_f> _ws_on_after_parse_callbacks; std::vector<ws_on_after_parse_callback_f> _ws_on_after_parse_callbacks;
std::vector<ws_on_receive_callback_f> _ws_on_receive_callbacks;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Private methods // Private methods
@ -225,14 +224,7 @@ void _wsParse(AsyncWebSocketClient *client, uint8_t * payload, size_t length) {
} }
// Check if key has to be processed // Check if key has to be processed
bool found = false;
for (unsigned char i = 0; i < _ws_on_receive_callbacks.size(); i++) {
found |= (_ws_on_receive_callbacks[i])(key.c_str(), value);
// TODO: remove this to call all OnReceiveCallbacks with the
// current key/value
if (found) break;
}
if (!found) {
if (!settingsKeyExists(key.c_str())) {
delSetting(key); delSetting(key);
continue; continue;
} }
@ -294,11 +286,8 @@ void _wsUpdate(JsonObject& root) {
#endif #endif
} }
bool _wsOnReceive(const char * key, JsonVariant& value) {
if (strncmp(key, "ws", 2) == 0) return true;
if (strncmp(key, "admin", 5) == 0) return true;
if (strncmp(key, "hostname", 8) == 0) return true;
return false;
bool _wsKeyCheck(const char * key) {
return (strncmp(key, "ws", 2) == 0);
} }
void _wsOnStart(JsonObject& root) { void _wsOnStart(JsonObject& root) {
@ -412,10 +401,6 @@ void wsOnSendRegister(ws_on_send_callback_f callback) {
_ws_on_send_callbacks.push_back(callback); _ws_on_send_callbacks.push_back(callback);
} }
void wsOnReceiveRegister(ws_on_receive_callback_f callback) {
_ws_on_receive_callbacks.push_back(callback);
}
void wsOnActionRegister(ws_on_action_callback_f callback) { void wsOnActionRegister(ws_on_action_callback_f callback) {
_ws_on_action_callbacks.push_back(callback); _ws_on_action_callbacks.push_back(callback);
} }
@ -497,8 +482,11 @@ void wsSetup() {
#endif #endif
wsOnSendRegister(_wsOnStart); wsOnSendRegister(_wsOnStart);
wsOnReceiveRegister(_wsOnReceive);
settingsRegisterKeyCheck(_wsKeyCheck);
espurnaRegisterLoop(_wsLoop); espurnaRegisterLoop(_wsLoop);
} }
#endif // WEB_SUPPORT #endif // WEB_SUPPORT

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

@ -199,12 +199,12 @@ function addValue(data, name, value) {
// These fields will always be a list of values // These fields will always be a list of values
var is_group = [ var is_group = [
"wifiName", "wifiPass", "wifiGW", "wifiMask", "wifiIP", "wifiDNS",
"schEnabled", "schSwitch","schAction","schType","schHour","schMinute","schWDs","schUTC",
"rlyBoot", "rlyPulse", "rlyTime",
"mqttGroup", "mqttGroupInv", "rlyOnDisc",
"dczRelayIdx", "dczMagnitude",
"tspkRelay", "tspkMagnitude",
"wifiName","wifiPass","wifiGW","wifiMask","wifiIP","wifiDNS",
"schEnabled","schSwitch","schAction","schType","schHour","schMinute","schWDs","schUTC",
"rlyBoot","rlyPulse","rlyTime","rlyOnDisc",
"mqttGroup","mqttGroupInv",
"dczRelayIdx","dczMagnitude",
"tspkRelay","tspkMagnitude",
"ledMode", "ledMode",
"adminPass" "adminPass"
]; ];


+ 2
- 2
code/html/index.html View File

@ -721,7 +721,7 @@
<div class="pure-g module module-mqttssl"> <div class="pure-g module module-mqttssl">
<label class="pure-u-1 pure-u-lg-1-4">Use secure connection (SSL)</label> <label class="pure-u-1 pure-u-lg-1-4">Use secure connection (SSL)</label>
<div class="pure-u-1 pure-u-lg-1-4"><input type="checkbox" name="mqttUseSSL" tabindex="29" /></div>
<div class="pure-u-1 pure-u-lg-1-4"><input type="checkbox" name="mqttSSL" tabindex="29" /></div>
</div> </div>
<div class="pure-g module module-mqttssl"> <div class="pure-g module module-mqttssl">
@ -757,7 +757,7 @@
<div class="pure-g"> <div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">Use JSON payload</label> <label class="pure-u-1 pure-u-lg-1-4">Use JSON payload</label>
<div class="pure-u-1 pure-u-lg-3-4"><input type="checkbox" name="mqttUseJson" tabindex="32" /></div>
<div class="pure-u-1 pure-u-lg-3-4"><input type="checkbox" name="mqttJson" tabindex="32" /></div>
<div class="pure-u-1 pure-u-lg-1-4"></div> <div class="pure-u-1 pure-u-lg-1-4"></div>
<div class="pure-u-1 pure-u-lg-3-4 hint"> <div class="pure-u-1 pure-u-lg-3-4 hint">
All messages (except the device status) will be included in a JSON payload along with the timestamp and hostname All messages (except the device status) will be included in a JSON payload along with the timestamp and hostname


Loading…
Cancel
Save