diff --git a/src/HotWaterController.cpp b/src/HotWaterController.cpp index 42a9ebe..5c6b444 100644 --- a/src/HotWaterController.cpp +++ b/src/HotWaterController.cpp @@ -48,6 +48,7 @@ DPRINTLN(); \ #define PUMP_ON digitalWrite(PUMP_PIN,LOW) #define PUMP_OFF digitalWrite(PUMP_PIN,HIGH) +// == water into the water heater = hot water demand when LOW #define FLOW_PIN 11 // this is INT0 #define FLOWING digitalRead(FLOW_PIN)==LOW #define NOTFLOWING digitalRead(FLOW_PIN)==HIGH @@ -64,9 +65,6 @@ void flowstate(); -bool notRun = true; - - /* * ticks are each 100mS so uint is 6553.5 seconds = 109.2 min * ticktime 32 bit 0.1sec rollover is 13 years @@ -84,6 +82,7 @@ unsigned long pumpstop_tc = 0; boolean flow = false; +boolean flowOn = false; boolean pump = false; boolean pumpOn = false; boolean pumpRan = false; @@ -100,7 +99,6 @@ volatile extern unsigned int ticknum; - void hotwater_setup() { pinMode(PUMP_PIN, OUTPUT); pinMode(FLOW_PIN, INPUT_PULLUP); @@ -176,7 +174,7 @@ void hotwater_loop () { flowstart_tc = 0; // reset } intflag1_FLOW = false; // clear interrupt. - if (DEBUG) Serial.println("flow interrupt"); + DPRINTLN("flow interrupt"); } } diff --git a/src/MQTTClientPump.cpp b/src/MQTTClientPump.cpp index 0daa0db..9439868 100644 --- a/src/MQTTClientPump.cpp +++ b/src/MQTTClientPump.cpp @@ -28,14 +28,13 @@ #endif /* SERIAL_DEBUGGING */ - #include #include #include - #include + #include "arduino_secrets.h" /////// sensitive data in arduino_secrets.h char ssid[] = SECRET_SSID; @@ -48,14 +47,10 @@ char pw[] = SECRET_PW; #define LED_PIN 13 -#define FLOW_PIN 11 // this is INT0 -// == water into the water heater = hot water demand when LOW +#define toggleLED digitalWrite(LED_PIN, !digitalRead(LED_PIN)) #define RATE 10 // Hz == 100mS -#define FLOWING digitalRead(FLOW_PIN)==LOW -#define NOTFLOWING digitalRead(FLOW_PIN)==HIGH - void wifi_connect(); void mqtt_connect(); @@ -84,6 +79,7 @@ volatile extern unsigned long ticktime; // timer interrupt volatile extern unsigned int ticknum; // wifi checked when this is > wifiTick extern boolean flow; +extern boolean flowOn; extern boolean pump; extern boolean pumpOn; @@ -102,10 +98,6 @@ unsigned long lasttimestamp = 0; const unsigned int wifiTick = 100; //(interval/RATE); -void toggleLED(){ - digitalWrite(LED_PIN, isLEDOn); - isLEDOn = !isLEDOn; -} void mqtt_setup() { int countdownMS; @@ -164,13 +156,13 @@ void mqtt_loop() { // record flow if (flow) { mqtt_connect(); - if (FLOWING) { // pin is LOW + if (flowOn) { // pin is LOW flowstarted = WiFi.getTime(); mqttClient.beginMessage(topic); mqttClient.print("start flow event@: "); DPRINT(flowstarted); DPRINTLN(); - mqttClient.print(WiFi.getTime()); + mqttClient.print(flowstarted); mqttClient.endMessage(); flow = false; // once is enough } else { // pin is HIGH @@ -179,14 +171,14 @@ void mqtt_loop() { mqttClient.print("stop flow event@: "); DPRINT(flowstopped); DPRINTLN(); - mqttClient.print(WiFi.getTime()); + mqttClient.print(flowstopped); mqttClient.endMessage(); } mqttClient.stop(); } - // process pump interrupt + // record pump activity if (pump) { mqtt_connect(); if (pumpOn) { // pin is LOW @@ -195,7 +187,7 @@ void mqtt_loop() { mqttClient.print("start pump event@: "); DPRINT(pumpstarted); DPRINTLN(); - mqttClient.print(WiFi.getTime()); + mqttClient.print(pumpstarted); mqttClient.endMessage(); } else { // pin is HIGH pumpstopped = WiFi.getTime(); @@ -203,7 +195,7 @@ void mqtt_loop() { mqttClient.print("stop pump event@: "); DPRINT(pumpstopped); DPRINTLN(); - mqttClient.print(WiFi.getTime()); + mqttClient.print(pumpstopped); mqttClient.endMessage(); } mqttClient.stop(); @@ -224,12 +216,7 @@ void mqtt_loop() { // blink LED @ 1Hz if ((ticktime % 10) == 0) { - if (notToggled) { // ticks are every 100mS. only toggle ONCE - toggleLED(); - notToggled = false; - } - } else { - notToggled = true; + digitalWrite(LED_PIN, !digitalRead(LED_PIN)); } @@ -256,7 +243,7 @@ void wifi_connect() { DPRINT("!"); for (int i=0; i<20; i++){ // 2 sec delay with 10hz blink delay(100); - toggleLED(); + toggleLED; } } } @@ -272,7 +259,7 @@ void mqtt_connect() { DPRINTLN(mqttClient.connectError()); for (int i=0; i<10; i++){ // 2 sec delay with 5hz blink delay(200); - toggleLED(); + toggleLED; } } }