From ff5b9c66bf2fa21bdbd99f9896ff93ddb09a771b Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Mon, 12 Aug 2019 21:43:37 +0700 Subject: [PATCH 1/5] Update WaterishOS-core2.0.ino --- WaterishOS-core2.0/WaterishOS-core2.0.ino | 37 +++-------------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/WaterishOS-core2.0/WaterishOS-core2.0.ino b/WaterishOS-core2.0/WaterishOS-core2.0.ino index ba81637..fb0c0ca 100644 --- a/WaterishOS-core2.0/WaterishOS-core2.0.ino +++ b/WaterishOS-core2.0/WaterishOS-core2.0.ino @@ -38,8 +38,6 @@ boolean online = true; boolean sensorstate[12]; boolean lastsensorstate[12]; boolean firstrun = true; -FlowMeter sensorA[6] = FlowMeter(14); -FlowMeter sensorB[6] = FlowMeter(3); FlowMeter sensor1 = FlowMeter(12); FlowMeter sensor2 = FlowMeter(13); volatile boolean awakenByInterrupt = false; @@ -53,26 +51,7 @@ void writelcd(String line1, String line2){ } void updatelcd() { - writelcd("Waterish OS S[A]",String((int)sensorA[0].getCurrentFlowrate())+" "+String((int)sensorA[1].getCurrentFlowrate())+" "+String((int)sensorA[2].getCurrentFlowrate())+" "+String((int)sensorA[3].getCurrentFlowrate())+" "+String((int)sensorA[4].getCurrentFlowrate())+" "+String((int)sensorA[5].getCurrentFlowrate())); - delay(1000); - writelcd("Waterish OS S[B]",String((int)sensorB[0].getCurrentFlowrate())+" "+String((int)sensorB[1].getCurrentFlowrate())+" "+String((int)sensorB[2].getCurrentFlowrate())+" "+String((int)sensorB[3].getCurrentFlowrate())+" "+String((int)sensorB[4].getCurrentFlowrate())+" "+String((int)sensorB[5].getCurrentFlowrate())); - delay(1000); - writelcd("Waterish OS INTN",String((int)sensor1.getCurrentFlowrate())+" "+String((int)sensor2.getCurrentFlowrate())); -} - -void ICACHE_RAM_ATTR readA() { - uint8_t pin = mcp.getLastInterruptPin(); - uint8_t val = mcp.getLastInterruptPinValue(); - sensorA[pin].count(); - mqtt.publish("/waterishos/debug", "Aterupt"); - for (int counter=0; counter <= 15; counter++)mcp.digitalRead(counter); - Serial.print("A interupted"+String((int)digitalRead(14))); -} -void ICACHE_RAM_ATTR readB() { - uint8_t pin = mcp.getLastInterruptPin(); - uint8_t val = mcp.getLastInterruptPinValue(); - for (int sid = 8; sid < 13; sid++)sensorB[sid - 8].count(); - for (int counter=0; counter <= 15; counter++)mcp.digitalRead(counter); + writelcd("1: "+String((int)sensor1.getCurrentFlowrate())+"L/h "+String(sensor1.getTotalVolume())+"L","2:"+String((int)sensor2.getCurrentFlowrate())+"L/h "+String(sensor2.getTotalVolume())+"L"); } void ICACHE_RAM_ATTR read1() { sensor1.count(); @@ -81,16 +60,10 @@ void ICACHE_RAM_ATTR read2() { sensor2.count(); } void collectdata() { - for (int sid = 0; sid <= 5; sid++)sensorA[sid].tick(1000); - for (int sid = 8; sid < 13; sid++)sensorB[sid - 8].tick(1000); sensor1.tick(1000); sensor2.tick(1000); } void updatemqtt() { - for (int counter=0; counter <= 5; counter++)mqtt.publish("/waterishos/node" + nodename + "/flowrateA/" + String(counter+1), String(sensorA[counter].getCurrentFlowrate())); - for (int counter=0; counter <= 5; counter++)mqtt.publish("/waterishos/node" + nodename + "/volumeA/" + String(counter+1), String(sensorA[counter].getTotalVolume())); - for (int counter=0; counter <= 5; counter++)mqtt.publish("/waterishos/node" + nodename + "/flowrateB/" + String(counter+1), String(sensorB[counter].getCurrentFlowrate())); - for (int counter=0; counter <= 5; counter++)mqtt.publish("/waterishos/node" + nodename + "/volumeB/" + String(counter+1), String(sensorB[counter].getTotalVolume())); mqtt.publish("/waterishos/node" + nodename + "/flowrate1", String(sensor1.getCurrentFlowrate())); mqtt.publish("/waterishos/node" + nodename + "/volume1", String(sensor1.getTotalVolume())); mqtt.publish("/waterishos/node" + nodename + "/flowrate2", String(sensor2.getCurrentFlowrate())); @@ -122,14 +95,14 @@ void setup() { pinMode(14, INPUT_PULLUP); pinMode(12, INPUT); pinMode(13, INPUT); - attachInterrupt(digitalPinToInterrupt(14), readA, RISING); - attachInterrupt(digitalPinToInterrupt(1), readB, RISING); attachInterrupt(digitalPinToInterrupt(12), read1, RISING); attachInterrupt(digitalPinToInterrupt(13), read2, RISING); delay(1000); writelcd("Boot Sequence P3","Waking Processor"); + delay(1000); + writelcd(" SETTINGS.H","co-processor:OFF"); + delay(3000); mcp.begin(); - mcp.setupInterrupts(true, false, LOW); for (int i = 0; i <= 15; i++) { mcp.pinMode(i, INPUT); @@ -155,7 +128,7 @@ void setup() { if(online)mqttupdater.onRun(updatemqtt); if(online)mqttupdater.setInterval(1000); lcdmanager.onRun(updatelcd); - lcdmanager.setInterval(1000); + lcdmanager.setInterval(250); threadControl.add(&datacollector); threadControl.add(&lcdmanager); if(online)threadControl.add(&mqttupdater); -- 2.40.1 From 4ea1442f6cc3a60cf380eb9710072af0624eefff Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Mon, 19 Aug 2019 01:18:04 +0000 Subject: [PATCH 2/5] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ed8f7d3..6544188 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# WaterishOS-Revision2.0x \ No newline at end of file +# WaterishOS-Revision2.0x + This is Waterish OS Revision 2 for Board v2 based on esp8266 \ No newline at end of file -- 2.40.1 From 5673cb5b8c9993ab143278ec33b4459819e01574 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Wed, 21 Aug 2019 21:01:13 +0700 Subject: [PATCH 3/5] 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 -- 2.40.1 From 29f7545e2f01e05813bd4dce9ba2caa4c41d3e8b Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Wed, 21 Aug 2019 21:14:48 +0700 Subject: [PATCH 4/5] 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"]; } -- 2.40.1 From 9c557b1f8e66fa35a7483279f0b0f920ba07c0ad Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Wed, 21 Aug 2019 21:19:57 +0700 Subject: [PATCH 5/5] 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"]; -} -- 2.40.1