From 29f7545e2f01e05813bd4dce9ba2caa4c41d3e8b Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Wed, 21 Aug 2019 21:14:48 +0700 Subject: [PATCH] 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"]; }