add reboot via mqtt

This commit is contained in:
interfisch 2024-05-12 09:37:24 +02:00
parent f20d6a528f
commit 5958942d9f
3 changed files with 40 additions and 19 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@
.piolibdeps
.clang_complete
.gcc-flags.json
messung/*

View File

@ -80,6 +80,11 @@ void messageReceived(String &topic, String &payload) {
valueError=false;
Serial.println("Reset value error flag");
}
if (topic==((String)client_id+"/reboot") && payload=="true") { //error acknowledge
Serial.println("Reboot by mqtt");
delay(100);
ESP.restart();
}
}
bool mqtt_loop(unsigned long loopmillis) {

View File

@ -3,11 +3,14 @@
/*TODO
mqtt function_: valueerror quittieren
mqtt function: device reboot
check if sendallnext_flag does anything
Do not send first flow value (when filter aray is not full)
*/
bool valueError=false;
unsigned long last_check=0;
#include "wifi_functions.h"
bool debug=false; //print Serial information
@ -18,6 +21,8 @@ sudo stty -F /dev/ttyUSB0 115200
cat /dev/ttyUSB0 | tee received.txt
*/
bool valuesStabilized=false; //gets set true when values are stable (avaeraging arrays filled)
@ -51,9 +56,6 @@ ADS1115 ADS(0x48);
bool valueError=false;
unsigned long last_check=0;
@ -200,8 +202,12 @@ void loop() {
last_check=loopmillis;
bool _noErrorsDuringLoop=true;
if (tempCmean_reservoir_a==DEVICE_DISCONNECTED_C || tempCmean_reservoir_b==DEVICE_DISCONNECTED_C || tempCmean_case==DEVICE_DISCONNECTED_C) {
valueError=true;
_noErrorsDuringLoop=false;
}
/*
@ -210,6 +216,7 @@ void loop() {
}*/
if (ec_A==EC_UNAVAILABLE || ec_B==EC_UNAVAILABLE){
valueError=true;
_noErrorsDuringLoop=false;
}
@ -219,9 +226,11 @@ void loop() {
if (distanceA_unsuccessful_count>20) {
valueError=true;
_noErrorsDuringLoop=false;
}
if (distanceB_unsuccessful_count>20) {
valueError=true;
_noErrorsDuringLoop=false;
}
@ -298,8 +307,11 @@ void loop() {
Serial.println();
if (_noErrorsDuringLoop && !valuesStabilized) {
valuesStabilized=true; //gets only set to true once
valueError=false; //clear error flag once after boot
Serial.println("Values Stable, clear error flag");
}
}
@ -334,21 +346,24 @@ void loop() {
static float last_flow_a=0;
if (valuesStabilized){
if (flow_a==0.0 && last_flow_a!=flow_a) {
publishValueTimedOverride("nft/flow",flow_a,2,timing_flow_a,loopmillis); //publish without waiting if flow is 0
}else{
publishValueTimed("nft/flow",flow_a,2,timing_flow_a,loopmillis);
}
last_flow_a=flow_a;
}
static float last_flow_b=0;
if (valuesStabilized){
if (flow_b==0.0 && last_flow_b!=flow_b) {
publishValueTimedOverride("db/flow",flow_b,2,timing_flow_b,loopmillis); //publish without waiting if flow is 0
}else{
publishValueTimed("db/flow",flow_b,2,timing_flow_b,loopmillis);
}
last_flow_b=flow_b;
}