add reboot via mqtt
This commit is contained in:
parent
f20d6a528f
commit
5958942d9f
|
@ -7,3 +7,4 @@
|
||||||
.piolibdeps
|
.piolibdeps
|
||||||
.clang_complete
|
.clang_complete
|
||||||
.gcc-flags.json
|
.gcc-flags.json
|
||||||
|
messung/*
|
||||||
|
|
|
@ -80,6 +80,11 @@ void messageReceived(String &topic, String &payload) {
|
||||||
valueError=false;
|
valueError=false;
|
||||||
Serial.println("Reset value error flag");
|
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) {
|
bool mqtt_loop(unsigned long loopmillis) {
|
||||||
|
|
33
src/main.cpp
33
src/main.cpp
|
@ -3,11 +3,14 @@
|
||||||
|
|
||||||
/*TODO
|
/*TODO
|
||||||
mqtt function_: valueerror quittieren
|
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"
|
#include "wifi_functions.h"
|
||||||
|
|
||||||
bool debug=false; //print Serial information
|
bool debug=false; //print Serial information
|
||||||
|
@ -18,6 +21,8 @@ sudo stty -F /dev/ttyUSB0 115200
|
||||||
cat /dev/ttyUSB0 | tee received.txt
|
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;
|
last_check=loopmillis;
|
||||||
|
|
||||||
|
|
||||||
|
bool _noErrorsDuringLoop=true;
|
||||||
|
|
||||||
if (tempCmean_reservoir_a==DEVICE_DISCONNECTED_C || tempCmean_reservoir_b==DEVICE_DISCONNECTED_C || tempCmean_case==DEVICE_DISCONNECTED_C) {
|
if (tempCmean_reservoir_a==DEVICE_DISCONNECTED_C || tempCmean_reservoir_b==DEVICE_DISCONNECTED_C || tempCmean_case==DEVICE_DISCONNECTED_C) {
|
||||||
valueError=true;
|
valueError=true;
|
||||||
|
_noErrorsDuringLoop=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -210,6 +216,7 @@ void loop() {
|
||||||
}*/
|
}*/
|
||||||
if (ec_A==EC_UNAVAILABLE || ec_B==EC_UNAVAILABLE){
|
if (ec_A==EC_UNAVAILABLE || ec_B==EC_UNAVAILABLE){
|
||||||
valueError=true;
|
valueError=true;
|
||||||
|
_noErrorsDuringLoop=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -219,9 +226,11 @@ void loop() {
|
||||||
|
|
||||||
if (distanceA_unsuccessful_count>20) {
|
if (distanceA_unsuccessful_count>20) {
|
||||||
valueError=true;
|
valueError=true;
|
||||||
|
_noErrorsDuringLoop=false;
|
||||||
}
|
}
|
||||||
if (distanceB_unsuccessful_count>20) {
|
if (distanceB_unsuccessful_count>20) {
|
||||||
valueError=true;
|
valueError=true;
|
||||||
|
_noErrorsDuringLoop=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -298,8 +307,11 @@ void loop() {
|
||||||
Serial.println();
|
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;
|
static float last_flow_a=0;
|
||||||
|
if (valuesStabilized){
|
||||||
if (flow_a==0.0 && last_flow_a!=flow_a) {
|
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
|
publishValueTimedOverride("nft/flow",flow_a,2,timing_flow_a,loopmillis); //publish without waiting if flow is 0
|
||||||
}else{
|
}else{
|
||||||
publishValueTimed("nft/flow",flow_a,2,timing_flow_a,loopmillis);
|
publishValueTimed("nft/flow",flow_a,2,timing_flow_a,loopmillis);
|
||||||
}
|
}
|
||||||
last_flow_a=flow_a;
|
last_flow_a=flow_a;
|
||||||
|
}
|
||||||
|
|
||||||
static float last_flow_b=0;
|
static float last_flow_b=0;
|
||||||
|
if (valuesStabilized){
|
||||||
if (flow_b==0.0 && last_flow_b!=flow_b) {
|
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
|
publishValueTimedOverride("db/flow",flow_b,2,timing_flow_b,loopmillis); //publish without waiting if flow is 0
|
||||||
}else{
|
}else{
|
||||||
publishValueTimed("db/flow",flow_b,2,timing_flow_b,loopmillis);
|
publishValueTimed("db/flow",flow_b,2,timing_flow_b,loopmillis);
|
||||||
}
|
}
|
||||||
last_flow_b=flow_b;
|
last_flow_b=flow_b;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue