add valueerror debug outputs

This commit is contained in:
interfisch 2024-05-13 20:32:14 +02:00
parent 3c8e67ba32
commit 504286b30f
4 changed files with 68 additions and 16 deletions

View File

@ -224,10 +224,10 @@ void ec_loop(unsigned long loopmillis) {
last_read_ec=loopmillis;
if (loopmillis>ec_last_change_relay+EC_RELAY_SWITCH_SETTLETIME) { //values have settled
Serial.print("Get ADC Reading");
//Serial.print("Get ADC Reading");
uint16_t value = ADS.readADC(EC_ADS_CHANNEL);
Serial.print(". Write to pos ");
Serial.println(ec_array_pos);
//Serial.print(". Write to pos ");
//Serial.println(ec_array_pos);

View File

@ -42,8 +42,8 @@ VL53L0X sensorA;
float waterlevelAMean_array[WATERLEVELMEAN_SIZE];
uint16_t waterlevelAMean_array_pos=0;
float waterlevelA=WATERLEVEL_UNAVAILABLE; //distance from floor to water surface [mm]
float watervolumeA=WATERLEVEL_UNAVAILABLE; //calculated Volume in Reservoir
float waterlevelA=WATERLEVEL_UNAVAILABLE;
float watervolumeA=WATERLEVEL_UNAVAILABLE;
//Calibration
@ -102,16 +102,30 @@ float waterlevelB_heightToVolume(float distance);
mqttValueTiming timing_waterlevelA;
mqttValueTiming timing_waterlevelB;
void waterlevel_setup() {
void waterlevel_shutdownSensors() {
pinMode(PIN_VL53L0X_XSHUT_A, OUTPUT);
digitalWrite(PIN_VL53L0X_XSHUT_A, LOW); //pull to GND
pinMode(PIN_VL53L0X_XSHUT_B, OUTPUT);
digitalWrite(PIN_VL53L0X_XSHUT_B, LOW); //pull to GND
}
void waterlevel_enableSensor(uint8_t sensorid) {
switch (sensorid){
case 0:
pinMode(PIN_VL53L0X_XSHUT_A, INPUT); //Enable Sensor A
break;
case 1:
pinMode(PIN_VL53L0X_XSHUT_B, INPUT); //Enable Sensor B
break;
}
}
void waterlevel_setup() {
waterlevel_shutdownSensors();
delay(100);
@ -162,14 +176,14 @@ void waterlevel_setup() {
timing_waterlevelA.maxtime=60*60*1000;
timing_waterlevelB.minchange=0.0;
timing_waterlevelB.maxchange=3.0;
timing_waterlevelB.mintime=30*000;
timing_waterlevelB.maxchange=0.5;
timing_waterlevelB.mintime=10*000;
timing_waterlevelB.maxtime=60*60*1000;
pinMode(PIN_VL53L0X_XSHUT_B, INPUT); //Enable Sensor B first, to change its address
waterlevel_enableSensor(1); //1==B //Enable Sensor B first, to change its address
delay(50);
Wire.begin();
Wire.begin(21,22);
Serial.print("I2C Clock Speed=");
Serial.println(Wire.getClock());
@ -212,7 +226,7 @@ void waterlevel_setup() {
// Stop driving this sensor's XSHUT low. This should allow the carrier
// board to pull it high. (We do NOT want to drive XSHUT high since it is
// not level shifted.) Then wait a bit for the sensor to start up.
pinMode(PIN_VL53L0X_XSHUT_A, INPUT);
waterlevel_enableSensor(0);
delay(50);
//Initialize Sensor A after SensorB's address was changed

View File

@ -60,7 +60,6 @@ void connect() {
client.subscribe((String)client_id+"/ec/trigger");
client.subscribe((String)client_id+"/errorack");
client.subscribe((String)client_id+"/reboot");
// client.unsubscribe("/hello");
}

View File

@ -5,6 +5,7 @@ bool valueError=false;
unsigned long last_check=0;
#include "wifi_functions.h"
bool debug=false; //print Serial information
@ -23,7 +24,6 @@ bool valuesStabilized=false; //gets set true when values are stable (avaeraging
#include "helpfunctions.h"
#include "ADS1X15.h"
ADS1115 ADS(0x48);
// ######## Temperature
@ -35,6 +35,7 @@ ADS1115 ADS(0x48);
// ######## EC
ADS1115 ADS(0x48);
#include "ec.h"
@ -49,6 +50,7 @@ ADS1115 ADS(0x48);
#define PIN_BUTTON 12
#define PIN_LED 13
@ -69,6 +71,7 @@ void setup() {
Serial.println("Setup Waterlevel");
waterlevel_setup();
//init ADS1115
if (!ADS.begin()) {
Serial.println("Error:"); delay(2000); Serial.println("ADS1115 Init Error!");
@ -118,6 +121,8 @@ void setup() {
void loop() {
unsigned long loopmillis=millis();
enableTiming=true; //reactivate
ec_loop(loopmillis);
@ -198,6 +203,22 @@ void loop() {
bool _noErrorsDuringLoop=true;
if (tempCmean_reservoir_a==DEVICE_DISCONNECTED_C || tempCmean_reservoir_b==DEVICE_DISCONNECTED_C || tempCmean_case==DEVICE_DISCONNECTED_C) {
if (!valueError && valuesStabilized) { //error just appeared
if (tempCmean_reservoir_a==DEVICE_DISCONNECTED_C) {
Serial.println("valueError tempCmean_reservoir_a");
publishInfo("error/temperature","valueError tempCmean_reservoir_a");
}
if (tempCmean_reservoir_b==DEVICE_DISCONNECTED_C) {
Serial.println("valueError tempCmean_reservoir_b");
publishInfo("error/temperature","valueError tempCmean_reservoir_b");
}
if (tempCmean_case==DEVICE_DISCONNECTED_C) {
Serial.println("valueError tempCmean_case");
publishInfo("error/temperature","valueError tempCmean_case");
}
}
valueError=true;
_noErrorsDuringLoop=false;
}
@ -207,6 +228,16 @@ void loop() {
valueError=true;
}*/
if (ec_A==EC_UNAVAILABLE || ec_B==EC_UNAVAILABLE){
if (!valueError && valuesStabilized) { //error just appeared
if (ec_A==EC_UNAVAILABLE){
Serial.println("valueError ecA");
publishInfo("error/ec","valueError ecA");
}
if (ec_B==EC_UNAVAILABLE){
Serial.println("valueError ecB");
publishInfo("error/ec","valueError ecB");
}
}
valueError=true;
_noErrorsDuringLoop=false;
}
@ -214,10 +245,18 @@ void loop() {
if (distanceA_unsuccessful_count>20) {
if (!valueError && valuesStabilized) { //error just appeared
Serial.println("valueError distanceA");
publishInfo("error/waterlevel","valueError distanceA");
}
valueError=true;
_noErrorsDuringLoop=false;
}
if (distanceB_unsuccessful_count>20) {
if (!valueError && valuesStabilized) { //error just appeared
Serial.println("valueError distanceB");
publishInfo("error/waterlevel","valueError distanceB");
}
valueError=true;
_noErrorsDuringLoop=false;
}