diff --git a/src/HotWaterController.cpp b/src/HotWaterController.cpp index 5c6b444..3350a8b 100644 --- a/src/HotWaterController.cpp +++ b/src/HotWaterController.cpp @@ -81,12 +81,11 @@ unsigned long pumpstart_tc = 0; unsigned long pumpstop_tc = 0; -boolean flow = false; +boolean flowChanged = false; boolean flowOn = false; -boolean pump = false; +boolean pumpChanged = false; boolean pumpOn = false; -boolean pumpRan = false; -boolean pumpEnabled = true; +boolean pumpEnabled = true; // controls pump duty cycle // FSM enum FSM {S0,S1,S2,S3}; @@ -124,7 +123,7 @@ void hotwater_loop () { switch (state){ case S0: - if (flow && pumpEnabled) { + if (flowChanged && pumpEnabled) { state = S1; if (DEBUG) DEBUGSTATE(state) DPRINT("pump start @ "); @@ -141,7 +140,7 @@ void hotwater_loop () { } break; case S2: - if (!flow) { // wait for flow to stop; don't need to keep pumping! + if (!flowChanged) { // wait for flow to stop; don't need to keep pumping! state = S3; if (DEBUG) DEBUGSTATE(state) //totalflow = Tflow; @@ -168,9 +167,9 @@ void hotwater_loop () { if (intflag1_FLOW) { if (ticktime > flowstart_tc + FLOW_THLD) { // delay to avoid bounces generating more interrupts if (FLOWING) { - flow = true; // set flow state 2000mS after interrupt IF still flowing + flowChanged = true; // set flow state 2000mS after interrupt IF still flowing } else { // flow didn't last longer than the threshold! - flow = false; + flowChanged = false; flowstart_tc = 0; // reset } intflag1_FLOW = false; // clear interrupt. @@ -181,15 +180,15 @@ void hotwater_loop () { // record flowstop time - if ((flow == true) && (NOTFLOWING) && (flowstop_tc == 0)) { + if ((flowChanged == true) && (NOTFLOWING) && (flowstop_tc == 0)) { flowstop_tc = ticktime; // only set flowstopped time once! DPRINTLN("flow stop"); } // flow stop - if ((flow == true) && (flowstop_tc > 0)){ + if ((flowChanged == true) && (flowstop_tc > 0)){ if (ticktime > flowstop_tc + 20){ // flow state changes 2 sec after flowstopped - flow = false; + flowChanged = false; flowstop_tc = 0; } } @@ -231,7 +230,7 @@ void hotwater_loop () { Serial.print(state); Serial.print(" "); Serial.print(intflag1_FLOW); - Serial.print(flow); + Serial.print(flowChanged); Serial.print("\t"); Serial.print(flowstart_tc); Serial.print("\t"); diff --git a/src/MQTTClientPump.cpp b/src/MQTTClientPump.cpp index 9439868..db89a3c 100644 --- a/src/MQTTClientPump.cpp +++ b/src/MQTTClientPump.cpp @@ -78,9 +78,9 @@ const char subtopic[] = "arduino/state"; volatile extern unsigned long ticktime; // timer interrupt volatile extern unsigned int ticknum; // wifi checked when this is > wifiTick -extern boolean flow; +extern boolean flowChanged; extern boolean flowOn; -extern boolean pump; +extern boolean pumpChanged; extern boolean pumpOn; // these are wifi timestamps @@ -154,9 +154,9 @@ void mqtt_loop() { */ // record flow - if (flow) { + if (flowChanged) { mqtt_connect(); - if (flowOn) { // pin is LOW + if (flowOn) { flowstarted = WiFi.getTime(); mqttClient.beginMessage(topic); mqttClient.print("start flow event@: "); @@ -164,8 +164,8 @@ void mqtt_loop() { DPRINTLN(); mqttClient.print(flowstarted); mqttClient.endMessage(); - flow = false; // once is enough - } else { // pin is HIGH + flowChanged = false; // once is enough + } else { flowstopped = WiFi.getTime(); mqttClient.beginMessage(topic); mqttClient.print("stop flow event@: "); @@ -179,9 +179,9 @@ void mqtt_loop() { // record pump activity - if (pump) { + if (pumpChanged) { mqtt_connect(); - if (pumpOn) { // pin is LOW + if (pumpOn) { pumpstarted = WiFi.getTime(); mqttClient.beginMessage(topic); mqttClient.print("start pump event@: "); @@ -189,7 +189,7 @@ void mqtt_loop() { DPRINTLN(); mqttClient.print(pumpstarted); mqttClient.endMessage(); - } else { // pin is HIGH + } else { pumpstopped = WiFi.getTime(); mqttClient.beginMessage(topic); mqttClient.print("stop pump event@: "); diff --git a/src/main.cpp b/src/main.cpp index 4a0e0f4..adbbb32 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,6 +37,6 @@ void setup() { } void loop() { - mqtt_loop(); hotwater_loop(); + mqtt_loop(); }