From 89aefdda4391f12f6fee62e5e4413eb9d6f32926 Mon Sep 17 00:00:00 2001 From: Phat Nguyen Date: Sat, 8 Jun 2024 12:01:42 +0700 Subject: [PATCH 1/2] fix type --- src/AgConfigure.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/AgConfigure.cpp b/src/AgConfigure.cpp index 0173edb..bd60edd 100644 --- a/src/AgConfigure.cpp +++ b/src/AgConfigure.cpp @@ -235,7 +235,7 @@ bool Configuration::parse(String data, bool isLocal) { bool changed = false; /** Get ConfigurationControl */ - String lasCtrl = jconfig[jprop_configurationControl]; + String lastCtrl = jconfig[jprop_configurationControl]; if (isLocal) { if (JSON.typeof_(root[jprop_configurationControl]) == "string") { String ctrl = root[jprop_configurationControl]; @@ -248,7 +248,7 @@ bool Configuration::parse(String data, bool isLocal) { ctrl == String(CONFIGURATION_CONTROL_NAME [ConfigurationControl::ConfigurationControlCloud])) { - if (ctrl != lasCtrl) { + if (ctrl != lastCtrl) { jconfig[jprop_configurationControl] = ctrl; changed = true; } @@ -270,7 +270,7 @@ bool Configuration::parse(String data, bool isLocal) { if (changed) { changed = false; saveConfig(); - configLogInfo(String(jprop_configurationControl), lasCtrl, + configLogInfo(String(jprop_configurationControl), lastCtrl, jconfig[jprop_configurationControl]); } From d4ea03f39e66addbbbdff7b761e71c35e8699299 Mon Sep 17 00:00:00 2001 From: Phat Nguyen Date: Sat, 8 Jun 2024 12:28:17 +0700 Subject: [PATCH 2/2] Handle `configurationControl` set `cloud` return success --- src/AgConfigure.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/AgConfigure.cpp b/src/AgConfigure.cpp index bd60edd..81cab16 100644 --- a/src/AgConfigure.cpp +++ b/src/AgConfigure.cpp @@ -236,6 +236,9 @@ bool Configuration::parse(String data, bool isLocal) { /** Get ConfigurationControl */ String lastCtrl = jconfig[jprop_configurationControl]; + const char *msg = "Monitor set to accept only configuration from the " + "cloud. Use property configurationControl to change."; + if (isLocal) { if (JSON.typeof_(root[jprop_configurationControl]) == "string") { String ctrl = root[jprop_configurationControl]; @@ -250,7 +253,17 @@ bool Configuration::parse(String data, bool isLocal) { [ConfigurationControl::ConfigurationControlCloud])) { if (ctrl != lastCtrl) { jconfig[jprop_configurationControl] = ctrl; - changed = true; + saveConfig(); + configLogInfo(String(jprop_configurationControl), lastCtrl, + jconfig[jprop_configurationControl]); + } + + /** Check to return result if configurationControl is 'cloud' */ + if (ctrl == + String(CONFIGURATION_CONTROL_NAME + [ConfigurationControl::ConfigurationControlCloud])) { + failedMessage = String(msg); + return true; } } else { failedMessage = @@ -267,18 +280,11 @@ bool Configuration::parse(String data, bool isLocal) { } } - if (changed) { - changed = false; - saveConfig(); - configLogInfo(String(jprop_configurationControl), lastCtrl, - jconfig[jprop_configurationControl]); - } - + /** Ignore all configuration value if 'configurationControl' is 'cloud' */ if (jconfig[jprop_configurationControl] == String(CONFIGURATION_CONTROL_NAME [ConfigurationControl::ConfigurationControlCloud])) { - failedMessage = "Monitor set to accept only configuration from the " - "cloud. Use property configurationControl to change."; + failedMessage = String(msg); jsonInvalid(); return false; }