From 68c10a43343110c4e8efc3e7edc5e3a7e5086179 Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Sat, 9 Feb 2019 15:42:44 +0300 Subject: [PATCH 1/2] Allow saving heartbeat settings from web --- code/espurna/mqtt.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/code/espurna/mqtt.ino b/code/espurna/mqtt.ino index 4c8f3e56..c44c36b0 100644 --- a/code/espurna/mqtt.ino +++ b/code/espurna/mqtt.ino @@ -316,7 +316,9 @@ unsigned long _mqttNextMessageId() { #if WEB_SUPPORT bool _mqttWebSocketOnReceive(const char * key, JsonVariant& value) { - return (strncmp(key, "mqtt", 3) == 0); + if (strncmp(key, "mqtt", 3) == 0) return true; + if (strncmp(key, "hb", 2) == 0) return true; + return false; } void _mqttWebSocketOnSend(JsonObject& root) { From 385d7360a75208f973d686d47a974a8df896e134 Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Sat, 9 Feb 2019 18:53:14 +0300 Subject: [PATCH 2/2] move to the system module --- code/espurna/mqtt.ino | 4 +--- code/espurna/system.ino | 10 ++++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/code/espurna/mqtt.ino b/code/espurna/mqtt.ino index c44c36b0..4c8f3e56 100644 --- a/code/espurna/mqtt.ino +++ b/code/espurna/mqtt.ino @@ -316,9 +316,7 @@ unsigned long _mqttNextMessageId() { #if WEB_SUPPORT bool _mqttWebSocketOnReceive(const char * key, JsonVariant& value) { - if (strncmp(key, "mqtt", 3) == 0) return true; - if (strncmp(key, "hb", 2) == 0) return true; - return false; + return (strncmp(key, "mqtt", 3) == 0); } void _mqttWebSocketOnSend(JsonObject& root) { diff --git a/code/espurna/system.ino b/code/espurna/system.ino index 27b2d4dd..791ba99c 100644 --- a/code/espurna/system.ino +++ b/code/espurna/system.ino @@ -86,6 +86,12 @@ void _systemSetupHeartbeat() { _heartbeat_interval = getSetting("hbInterval", HEARTBEAT_INTERVAL).toInt(); } +#if WEB_SUPPORT + bool _systemWebSocketOnReceive(const char * key, JsonVariant& value) { + return (strncmp(key, "hb", 2) == 0); + } +#endif + void systemLoop() { // ------------------------------------------------------------------------- @@ -182,6 +188,10 @@ void systemSetup() { systemCheck(false); #endif + #if WEB_SUPPORT + wsOnReceiveRegister(_systemWebSocketOnReceive); + #endif + // Init device-specific hardware _systemSetupSpecificHardware();