From 13731236562396bbbcee9ec2ffc66d063eda7e9c Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Sat, 10 Aug 2019 18:25:07 +0700 Subject: [PATCH] add 2 Firmware Variant, LCDGUI and core --- WaterishOS-core2.0/WaterishOS-core2.0.ino | 96 +++++++++++++++++++ WaterishOS-core2.0/config.h | 6 ++ WaterishOS-lcdgui2.0/WaterishOS-lcdgui2.0.ino | 96 +++++++++++++++++++ WaterishOS-lcdgui2.0/config.h | 6 ++ 4 files changed, 204 insertions(+) create mode 100644 WaterishOS-core2.0/WaterishOS-core2.0.ino create mode 100644 WaterishOS-core2.0/config.h create mode 100644 WaterishOS-lcdgui2.0/WaterishOS-lcdgui2.0.ino create mode 100644 WaterishOS-lcdgui2.0/config.h diff --git a/WaterishOS-core2.0/WaterishOS-core2.0.ino b/WaterishOS-core2.0/WaterishOS-core2.0.ino new file mode 100644 index 0000000..4b46de7 --- /dev/null +++ b/WaterishOS-core2.0/WaterishOS-core2.0.ino @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include +#include +#include +#include +#include +Adafruit_MCP23017 mcp; +long tslr=0; +WiFiClient espClient; +PubSubClient client("siwatsystem.com", 1883, espClient); +PubSubClientTools mqtt(client); +ThreadController threadControl = ThreadController(); +Thread mqttupdater = Thread(); +Thread datacollector = Thread(); +boolean online=true; +FlowMeter sensorA[6]= FlowMeter(1); +FlowMeter sensorB[6]= FlowMeter(3); +volatile boolean awakenByInterrupt = false; +void readA(){ + uint8_t pin=mcp.getLastInterruptPin(); + uint8_t val=mcp.getLastInterruptPinValue(); + for(int sid=0;sid<=5;sid++)sensorA[sid].count(); +} +void readB(){ + uint8_t pin=mcp.getLastInterruptPin(); + uint8_t val=mcp.getLastInterruptPinValue(); + for(int sid=8;sid<13;sid++)sensorB[sid-8].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); +} +void updatemqtt(){ + for(int counter;counter<=6;counter++)mqtt.publish("/waterishos/node"+nodename+"/flowrateA/"+counter,String(sensorA[counter].getCurrentFlowrate())); + for(int counter;counter<=6;counter++)mqtt.publish("/waterishos/node"+nodename+"/volumeA/"+counter,String(sensorA[counter].getTotalVolume())); + for(int counter;counter<=6;counter++)mqtt.publish("/waterishos/node"+nodename+"/flowrateB/"+counter,String(sensorB[counter].getCurrentFlowrate())); + for(int counter;counter<=6;counter++)mqtt.publish("/waterishos/node"+nodename+"/volumeB/"+counter,String(sensorB[counter].getTotalVolume()));} +void setup(){ + WiFi.mode(WIFI_STA); + WiFi.begin(ssid, password); + int connectionattempt=0; + while(WiFi.status() != WL_CONNECTED) + { + //wait for it ... (Wait for Wifi Connection) + connectionattempt++; + delay(500); + if(connectionattempt>=20){ + online=false; + break; + } + } + attachInterrupt(digitalPinToInterrupt(1),readA,FALLING); + attachInterrupt(digitalPinToInterrupt(3),readB,FALLING); + pinMode(1, FUNCTION_3); + pinMode(3, FUNCTION_3); + pinMode(1,INPUT); + pinMode(3,INPUT); + mcp.begin(); + mcp.setupInterrupts(true,false,LOW); + for(int i=0;i<=15;i++) + { + mcp.pinMode(i, INPUT); + mcp.setupInterruptPin(i,RISING); + } + datacollector.onRun(collectdata); + datacollector.setInterval(1000); + mqttupdater.onRun(updatemqtt); + mqttupdater.setInterval(1000); + threadControl.add(&datacollector); + threadControl.add(&mqttupdater); + } + +void loop(){ + client.loop(); + threadControl.run(); +} diff --git a/WaterishOS-core2.0/config.h b/WaterishOS-core2.0/config.h new file mode 100644 index 0000000..270f23e --- /dev/null +++ b/WaterishOS-core2.0/config.h @@ -0,0 +1,6 @@ +const String ssid = ""; +const String password = ""; +const byte InteruptPinA=1; +const byte InteruptPinB=3; +const byte arduinoInterrupt=1; +const String nodename="devkit"; diff --git a/WaterishOS-lcdgui2.0/WaterishOS-lcdgui2.0.ino b/WaterishOS-lcdgui2.0/WaterishOS-lcdgui2.0.ino new file mode 100644 index 0000000..4b46de7 --- /dev/null +++ b/WaterishOS-lcdgui2.0/WaterishOS-lcdgui2.0.ino @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include +#include +#include +#include +#include +Adafruit_MCP23017 mcp; +long tslr=0; +WiFiClient espClient; +PubSubClient client("siwatsystem.com", 1883, espClient); +PubSubClientTools mqtt(client); +ThreadController threadControl = ThreadController(); +Thread mqttupdater = Thread(); +Thread datacollector = Thread(); +boolean online=true; +FlowMeter sensorA[6]= FlowMeter(1); +FlowMeter sensorB[6]= FlowMeter(3); +volatile boolean awakenByInterrupt = false; +void readA(){ + uint8_t pin=mcp.getLastInterruptPin(); + uint8_t val=mcp.getLastInterruptPinValue(); + for(int sid=0;sid<=5;sid++)sensorA[sid].count(); +} +void readB(){ + uint8_t pin=mcp.getLastInterruptPin(); + uint8_t val=mcp.getLastInterruptPinValue(); + for(int sid=8;sid<13;sid++)sensorB[sid-8].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); +} +void updatemqtt(){ + for(int counter;counter<=6;counter++)mqtt.publish("/waterishos/node"+nodename+"/flowrateA/"+counter,String(sensorA[counter].getCurrentFlowrate())); + for(int counter;counter<=6;counter++)mqtt.publish("/waterishos/node"+nodename+"/volumeA/"+counter,String(sensorA[counter].getTotalVolume())); + for(int counter;counter<=6;counter++)mqtt.publish("/waterishos/node"+nodename+"/flowrateB/"+counter,String(sensorB[counter].getCurrentFlowrate())); + for(int counter;counter<=6;counter++)mqtt.publish("/waterishos/node"+nodename+"/volumeB/"+counter,String(sensorB[counter].getTotalVolume()));} +void setup(){ + WiFi.mode(WIFI_STA); + WiFi.begin(ssid, password); + int connectionattempt=0; + while(WiFi.status() != WL_CONNECTED) + { + //wait for it ... (Wait for Wifi Connection) + connectionattempt++; + delay(500); + if(connectionattempt>=20){ + online=false; + break; + } + } + attachInterrupt(digitalPinToInterrupt(1),readA,FALLING); + attachInterrupt(digitalPinToInterrupt(3),readB,FALLING); + pinMode(1, FUNCTION_3); + pinMode(3, FUNCTION_3); + pinMode(1,INPUT); + pinMode(3,INPUT); + mcp.begin(); + mcp.setupInterrupts(true,false,LOW); + for(int i=0;i<=15;i++) + { + mcp.pinMode(i, INPUT); + mcp.setupInterruptPin(i,RISING); + } + datacollector.onRun(collectdata); + datacollector.setInterval(1000); + mqttupdater.onRun(updatemqtt); + mqttupdater.setInterval(1000); + threadControl.add(&datacollector); + threadControl.add(&mqttupdater); + } + +void loop(){ + client.loop(); + threadControl.run(); +} diff --git a/WaterishOS-lcdgui2.0/config.h b/WaterishOS-lcdgui2.0/config.h new file mode 100644 index 0000000..270f23e --- /dev/null +++ b/WaterishOS-lcdgui2.0/config.h @@ -0,0 +1,6 @@ +const String ssid = ""; +const String password = ""; +const byte InteruptPinA=1; +const byte InteruptPinB=3; +const byte arduinoInterrupt=1; +const String nodename="devkit";