Template
timing tweak
This commit is contained in:
+38
-39
@@ -96,43 +96,6 @@ void hotwater_setup() {
|
|||||||
|
|
||||||
// loop() is called repeatedly
|
// loop() is called repeatedly
|
||||||
void hotwater_loop () {
|
void hotwater_loop () {
|
||||||
|
|
||||||
switch (state){
|
|
||||||
case S0: //wait for flow threshold before turning pump on
|
|
||||||
if (flowChanged && pumpEnabled) {
|
|
||||||
state = S1;
|
|
||||||
if (FSM_DEBUG) DEBUGSTATE(state)
|
|
||||||
DPRINT("pump start @ ");
|
|
||||||
DPRINTLN(ticktime);
|
|
||||||
pumpOn = true;
|
|
||||||
pumpEnabled = false;
|
|
||||||
pumpstart_tc = ticktime;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case S1: //wait for pump off
|
|
||||||
if (!pumpOn) {
|
|
||||||
state = S2;
|
|
||||||
if (FSM_DEBUG) DEBUGSTATE(state)
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case S2: //wait for flow to stop
|
|
||||||
if (!flowChanged) { // wait for flow to stop; don't need to keep pumping!
|
|
||||||
state = S3;
|
|
||||||
if (FSM_DEBUG) DEBUGSTATE(state)
|
|
||||||
//totalflow = Tflow;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case S3: //wait for hysteresis time before cycling again
|
|
||||||
if (pumpEnabled) { // limit duty cycle
|
|
||||||
state = S0;
|
|
||||||
if (FSM_DEBUG) DEBUGSTATE(state)
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
} // FSM
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// process interrupt
|
// process interrupt
|
||||||
if (intflag_FLOW) {
|
if (intflag_FLOW) {
|
||||||
if (FLOWING){
|
if (FLOWING){
|
||||||
@@ -144,19 +107,20 @@ void hotwater_loop () {
|
|||||||
DPRINTLN("flow interrupt");
|
DPRINTLN("flow interrupt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (millis()+DEBOUNCE > FLOW_eventtime){ // this is a debounce
|
if (millis()+DEBOUNCE > FLOW_eventtime){ // this is a debounce
|
||||||
flowChanged = true;
|
flowChanged = true;
|
||||||
FLOW_eventtime = ULONG_MAX;
|
FLOW_eventtime = ULONG_MAX;
|
||||||
}
|
}
|
||||||
// record flowstart time
|
// record flowstart time
|
||||||
if ((flowChanged == true) && (FLOWING) && (flowstart_tc == 0)) {
|
if ((flowChanged == true) && (FLOWING) && (flowstart_tc == 0)) {
|
||||||
flowstart_tc = ticktime; // only set flowstarted time once!
|
flowstart_tc = ticktime;
|
||||||
DPRINTLN("flow start");
|
DPRINTLN("flow start");
|
||||||
}
|
}
|
||||||
|
|
||||||
// flow start
|
// flow start
|
||||||
if ((flowChanged == true) && (flowstart_tc > 0)){
|
if ((flowChanged == true) && (flowstart_tc > 0)){
|
||||||
if(ticktime > flowstart_tc){
|
if(ticktime > flowstart_tc + TWOSECONDS){ // flow state changes 2 sec after flowstopped
|
||||||
flowChanged = false;
|
flowChanged = false;
|
||||||
reportFlowChange = true;
|
reportFlowChange = true;
|
||||||
flowOn = true;
|
flowOn = true;
|
||||||
@@ -192,6 +156,7 @@ void hotwater_loop () {
|
|||||||
flowstart_tc = 0;
|
flowstart_tc = 0;
|
||||||
pumpstart_tc = 0;
|
pumpstart_tc = 0;
|
||||||
pumpstop_tc = ticktime;
|
pumpstop_tc = ticktime;
|
||||||
|
reportPumpChange = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,4 +196,38 @@ void hotwater_loop () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (state){
|
||||||
|
case S0: //wait for flow threshold before turning pump on
|
||||||
|
if (flowOn && pumpEnabled) {
|
||||||
|
state = S1;
|
||||||
|
if (FSM_DEBUG) DEBUGSTATE(state)
|
||||||
|
DPRINT("pump start @ ");
|
||||||
|
DPRINTLN(ticktime);
|
||||||
|
pumpOn = true;
|
||||||
|
pumpEnabled = false;
|
||||||
|
pumpstart_tc = ticktime;
|
||||||
|
reportPumpChange = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case S1: //wait for pump off
|
||||||
|
if (!pumpOn) {
|
||||||
|
state = S2;
|
||||||
|
if (FSM_DEBUG) DEBUGSTATE(state)
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case S2: //wait for flow to stop
|
||||||
|
if (!flowOn) { // wait for flow to stop; don't need to keep pumping!
|
||||||
|
state = S3;
|
||||||
|
if (FSM_DEBUG) DEBUGSTATE(state)
|
||||||
|
//totalflow = Tflow;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case S3: //wait for hysteresis time before cycling again
|
||||||
|
if (pumpEnabled) { // limit duty cycle
|
||||||
|
state = S0;
|
||||||
|
if (FSM_DEBUG) DEBUGSTATE(state)
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
} // FSM
|
||||||
|
|
||||||
} // end loop()
|
} // end loop()
|
||||||
|
|||||||
+13
-22
@@ -134,52 +134,43 @@ void mqtt_loop() {
|
|||||||
// record flow
|
// record flow
|
||||||
if (reportFlowChange) {
|
if (reportFlowChange) {
|
||||||
mqtt_connect();
|
mqtt_connect();
|
||||||
|
mqttClient.beginMessage(topic);
|
||||||
if (flowOn) {
|
if (flowOn) {
|
||||||
flowstarted = WiFi.getTime();
|
flowstarted = WiFi.getTime();
|
||||||
mqttClient.beginMessage(topic);
|
|
||||||
mqttClient.print("start flow event@: ");
|
mqttClient.print("start flow event@: ");
|
||||||
DPRINT(flowstarted);
|
DPRINTLN(flowstarted);
|
||||||
DPRINTLN();
|
mqttClient.print(flowstarted);
|
||||||
mqttClient.print(flowstarted);
|
|
||||||
mqttClient.endMessage();
|
|
||||||
reportFlowChange = false; // do once
|
|
||||||
} else {
|
} else {
|
||||||
flowstopped = WiFi.getTime();
|
flowstopped = WiFi.getTime();
|
||||||
mqttClient.beginMessage(topic);
|
|
||||||
mqttClient.print("stop flow event@: ");
|
mqttClient.print("stop flow event@: ");
|
||||||
DPRINT(flowstopped);
|
DPRINTLN(flowstopped);
|
||||||
DPRINTLN();
|
|
||||||
mqttClient.print(flowstopped);
|
mqttClient.print(flowstopped);
|
||||||
mqttClient.endMessage();
|
|
||||||
reportFlowChange = false; // do once
|
|
||||||
}
|
}
|
||||||
|
mqttClient.endMessage();
|
||||||
mqttClient.stop();
|
mqttClient.stop();
|
||||||
|
reportFlowChange = false; // do once
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// record pump activity
|
// record pump activity
|
||||||
if (pumpChanged) {
|
if (reportPumpChange) {
|
||||||
mqtt_connect();
|
mqtt_connect();
|
||||||
|
mqttClient.beginMessage(topic);
|
||||||
if (pumpOn) {
|
if (pumpOn) {
|
||||||
pumpstarted = WiFi.getTime();
|
pumpstarted = WiFi.getTime();
|
||||||
mqttClient.beginMessage(topic);
|
|
||||||
mqttClient.print("start pump event@: ");
|
mqttClient.print("start pump event@: ");
|
||||||
DPRINT(pumpstarted);
|
DPRINTLN(pumpstarted);
|
||||||
DPRINTLN();
|
|
||||||
mqttClient.print(pumpstarted);
|
mqttClient.print(pumpstarted);
|
||||||
mqttClient.endMessage();
|
|
||||||
pumpChanged = false; // once is enough
|
|
||||||
} else {
|
} else {
|
||||||
pumpstopped = WiFi.getTime();
|
pumpstopped = WiFi.getTime();
|
||||||
mqttClient.beginMessage(topic);
|
mqttClient.beginMessage(topic);
|
||||||
mqttClient.print("stop pump event@: ");
|
mqttClient.print("stop pump event@: ");
|
||||||
DPRINT(pumpstopped);
|
DPRINTLN(pumpstopped);
|
||||||
DPRINTLN();
|
|
||||||
mqttClient.print(pumpstopped);
|
mqttClient.print(pumpstopped);
|
||||||
mqttClient.endMessage();
|
}
|
||||||
pumpChanged = false; // once is enough
|
mqttClient.endMessage();
|
||||||
}
|
|
||||||
mqttClient.stop();
|
mqttClient.stop();
|
||||||
|
reportPumpChange = false; // do once
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ void hotwater_loop();
|
|||||||
volatile boolean intflag_FLOW = false; // external GPIO interrupt (event)
|
volatile boolean intflag_FLOW = false; // external GPIO interrupt (event)
|
||||||
volatile unsigned long ticktime = 0;
|
volatile unsigned long ticktime = 0;
|
||||||
volatile unsigned int ticknum = 0;
|
volatile unsigned int ticknum = 0;
|
||||||
volatile unsigned long FLOW_eventtime = 0;
|
volatile unsigned long FLOW_eventtime = ULONG_MAX;
|
||||||
|
|
||||||
unsigned long FLOW_starttime;
|
unsigned long FLOW_starttime;
|
||||||
unsigned long FLOW_stoptime;
|
unsigned long FLOW_stoptime;
|
||||||
|
|||||||
Reference in New Issue
Block a user