add espcommander

This commit is contained in:
Siwat Sirichai 2019-08-21 21:14:48 +07:00
parent 3c810d9b4e
commit 29f7545e2f
2 changed files with 23 additions and 6 deletions

View File

@ -1,3 +1,4 @@
#include <LiquidCrystal_I2C.h> #include <LiquidCrystal_I2C.h>
#include <PubSubClient.h> #include <PubSubClient.h>
#include <MqttWildcard.h> #include <MqttWildcard.h>
@ -69,7 +70,22 @@ void updatemqtt() {
mqtt.publish("/waterishos/node" + nodename + "/flowrate2", String(sensor2.getCurrentFlowrate())); mqtt.publish("/waterishos/node" + nodename + "/flowrate2", String(sensor2.getCurrentFlowrate()));
mqtt.publish("/waterishos/node" + nodename + "/volume2", String(sensor2.getTotalVolume())); 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() { void setup() {
lcd.begin(); lcd.begin();
writelcd(" Siwat INC (tm) "," Waterish OS"); writelcd(" Siwat INC (tm) "," Waterish OS");

View File

@ -1,14 +1,15 @@
#include <ArduinoJson.h>
// Copyright Siwat INC(tm) 2019 // Copyright Siwat INC(tm) 2019
// Created by Siwat Sirichai // Created by Siwat Sirichai
// ESPCommander EXTENDED v1.2 // 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; StaticJsonDocument<200> doc;
DeserializationError error = deserializeJson(doc, json); DeserializationError error = deserializeJson(doc, rawcommand);
if (error) { if (error) {
Serial.print(F("deserializeJson() failed: ")); Serial.print(F("deserializeJson() failed: "));
Serial.println(error.c_str()); Serial.println(error.c_str());
return; return;
} }
String command = doc["command"]; const char* command = doc["command"];
String value = doc["value"]; const char* value = doc["value"];
} }