From 5673cb5b8c9993ab143278ec33b4459819e01574 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Wed, 21 Aug 2019 21:01:13 +0700 Subject: [PATCH 1/3] Preparing ESPCommander Intergration --- .../WaterishOS-core3.0.ino | 2 ++ .../config.h | 0 WaterishOS-core3.0/espcommander.cpp | 14 ++++++++++++++ .../lcdcontrol.h | 0 4 files changed, 16 insertions(+) rename WaterishOS-core2.0/WaterishOS-core2.0.ino => WaterishOS-core3.0/WaterishOS-core3.0.ino (97%) rename {WaterishOS-core2.0 => WaterishOS-core3.0}/config.h (100%) create mode 100644 WaterishOS-core3.0/espcommander.cpp rename {WaterishOS-core2.0 => WaterishOS-core3.0}/lcdcontrol.h (100%) diff --git a/WaterishOS-core2.0/WaterishOS-core2.0.ino b/WaterishOS-core3.0/WaterishOS-core3.0.ino similarity index 97% rename from WaterishOS-core2.0/WaterishOS-core2.0.ino rename to WaterishOS-core3.0/WaterishOS-core3.0.ino index fb0c0ca..6ea9a87 100644 --- a/WaterishOS-core2.0/WaterishOS-core2.0.ino +++ b/WaterishOS-core3.0/WaterishOS-core3.0.ino @@ -69,6 +69,7 @@ void updatemqtt() { mqtt.publish("/waterishos/node" + nodename + "/flowrate2", String(sensor2.getCurrentFlowrate())); mqtt.publish("/waterishos/node" + nodename + "/volume2", String(sensor2.getTotalVolume())); } +#include "espcommander.cpp" void setup() { lcd.begin(); writelcd(" Siwat INC (tm) "," Waterish OS"); @@ -117,6 +118,7 @@ void setup() { writelcd(" Telemetry Node","siwatsystem.com"); if (client.connect("waterishos",telemetryuser,telemetrykey)) { writelcd(" Telemetry Node","Connected"); + mqtt.subscribe("/waterishos/node" + nodename + "command", espcommander); delay(1000); } else { writelcd(" Telemetry Node"," Failed Offline"); diff --git a/WaterishOS-core2.0/config.h b/WaterishOS-core3.0/config.h similarity index 100% rename from WaterishOS-core2.0/config.h rename to WaterishOS-core3.0/config.h diff --git a/WaterishOS-core3.0/espcommander.cpp b/WaterishOS-core3.0/espcommander.cpp new file mode 100644 index 0000000..3dfc5b2 --- /dev/null +++ b/WaterishOS-core3.0/espcommander.cpp @@ -0,0 +1,14 @@ +// Copyright Siwat INC(tm) 2019 +// Created by Siwat Sirichai +// ESPCommander EXTENDED v1.2 +void espcommander(String topic, String command) { //the command is in json format! + StaticJsonDocument<200> doc; + DeserializationError error = deserializeJson(doc, json); + if (error) { + Serial.print(F("deserializeJson() failed: ")); + Serial.println(error.c_str()); + return; + } + String command = doc["command"]; + String value = doc["value"]; +} diff --git a/WaterishOS-core2.0/lcdcontrol.h b/WaterishOS-core3.0/lcdcontrol.h similarity index 100% rename from WaterishOS-core2.0/lcdcontrol.h rename to WaterishOS-core3.0/lcdcontrol.h From 29f7545e2f01e05813bd4dce9ba2caa4c41d3e8b Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Wed, 21 Aug 2019 21:14:48 +0700 Subject: [PATCH 2/3] add espcommander --- WaterishOS-core3.0/WaterishOS-core3.0.ino | 18 +++++++++++++++++- WaterishOS-core3.0/espcommander.cpp | 11 ++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/WaterishOS-core3.0/WaterishOS-core3.0.ino b/WaterishOS-core3.0/WaterishOS-core3.0.ino index 6ea9a87..e5d5225 100644 --- a/WaterishOS-core3.0/WaterishOS-core3.0.ino +++ b/WaterishOS-core3.0/WaterishOS-core3.0.ino @@ -1,3 +1,4 @@ + #include #include #include @@ -69,7 +70,22 @@ void updatemqtt() { mqtt.publish("/waterishos/node" + nodename + "/flowrate2", String(sensor2.getCurrentFlowrate())); mqtt.publish("/waterishos/node" + nodename + "/volume2", String(sensor2.getTotalVolume())); } -#include "espcommander.cpp" +// Copyright Siwat INC(tm) 2019 +// Created by Siwat Sirichai +// ESPCommander EXTENDED v1.2 +// For Legal Distribution of this code, the comment must not be removed! +void espcommander(String topic, String rawcommand) { + StaticJsonDocument<200> doc; + DeserializationError error = deserializeJson(doc, rawcommand); + if (error) { + Serial.print(F("deserializeJson() failed: ")); + Serial.println(error.c_str()); + return; + } + const char* command = doc["command"]; + const char* value = doc["value"]; +} +//END OF ESPCOMMANDER CODE void setup() { lcd.begin(); writelcd(" Siwat INC (tm) "," Waterish OS"); diff --git a/WaterishOS-core3.0/espcommander.cpp b/WaterishOS-core3.0/espcommander.cpp index 3dfc5b2..8bf128e 100644 --- a/WaterishOS-core3.0/espcommander.cpp +++ b/WaterishOS-core3.0/espcommander.cpp @@ -1,14 +1,15 @@ +#include // Copyright Siwat INC(tm) 2019 // Created by Siwat Sirichai // ESPCommander EXTENDED v1.2 -void espcommander(String topic, String command) { //the command is in json format! +void espcommander(String topic, String rawcommand) { StaticJsonDocument<200> doc; - DeserializationError error = deserializeJson(doc, json); + DeserializationError error = deserializeJson(doc, rawcommand); if (error) { Serial.print(F("deserializeJson() failed: ")); Serial.println(error.c_str()); return; - } - String command = doc["command"]; - String value = doc["value"]; + } + const char* command = doc["command"]; + const char* value = doc["value"]; } From 9c557b1f8e66fa35a7483279f0b0f920ba07c0ad Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Wed, 21 Aug 2019 21:19:57 +0700 Subject: [PATCH 3/3] Fix bugs --- WaterishOS-core3.0/WaterishOS-core3.0.ino | 2 +- WaterishOS-core3.0/espcommander.cpp | 15 --------------- 2 files changed, 1 insertion(+), 16 deletions(-) delete mode 100644 WaterishOS-core3.0/espcommander.cpp diff --git a/WaterishOS-core3.0/WaterishOS-core3.0.ino b/WaterishOS-core3.0/WaterishOS-core3.0.ino index e5d5225..99159a5 100644 --- a/WaterishOS-core3.0/WaterishOS-core3.0.ino +++ b/WaterishOS-core3.0/WaterishOS-core3.0.ino @@ -1,4 +1,4 @@ - +#include #include #include #include diff --git a/WaterishOS-core3.0/espcommander.cpp b/WaterishOS-core3.0/espcommander.cpp deleted file mode 100644 index 8bf128e..0000000 --- a/WaterishOS-core3.0/espcommander.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include -// Copyright Siwat INC(tm) 2019 -// Created by Siwat Sirichai -// ESPCommander EXTENDED v1.2 -void espcommander(String topic, String rawcommand) { - StaticJsonDocument<200> doc; - DeserializationError error = deserializeJson(doc, rawcommand); - if (error) { - Serial.print(F("deserializeJson() failed: ")); - Serial.println(error.c_str()); - return; - } - const char* command = doc["command"]; - const char* value = doc["value"]; -}