fix send mqtt errors only when mqtt enabled

This commit is contained in:
interfisch 2025-04-10 20:05:34 +02:00
parent 111758b4ae
commit 70b0b0f1a8
3 changed files with 108 additions and 49 deletions

View file

@ -120,4 +120,43 @@ float mapf(float x, float in_min, float in_max, float out_min, float out_max)
} }
void i2cscan()
{
byte error, address;
int nDevices;
delay(500);
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
}
#endif #endif

View file

@ -8,7 +8,7 @@
; Please visit documentation for the other options and examples ; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html ; https://docs.platformio.org/page/projectconf.html
[env:esp32doit-devkit-v1_NFT] [env:esp32doit-devkit-v1_NFT_2024]
platform = espressif32 platform = espressif32
board = esp32doit-devkit-v1 board = esp32doit-devkit-v1
framework = arduino framework = arduino
@ -50,6 +50,7 @@ platform = platformio/espressif32@^6.7
board = esp32-s3-devkitm-1 board = esp32-s3-devkitm-1
;Devboard is ESP32-S3-DevKitC-1 (N16R8). board=esp32-s3-devkitm-1 works fine ;Devboard is ESP32-S3-DevKitC-1 (N16R8). board=esp32-s3-devkitm-1 works fine
framework = arduino framework = arduino
monitor_port = /dev/ttyACM1
monitor_speed = 115200 monitor_speed = 115200
@ -86,3 +87,49 @@ lib_deps =
256dpi/MQTT@^2.5.2 256dpi/MQTT@^2.5.2
pololu/VL53L0X@^1.3.1 pololu/VL53L0X@^1.3.1
adafruit/Adafruit NeoPixel adafruit/Adafruit NeoPixel
[env:esp32-s3-devkitm-1_NFT]
platform = platformio/espressif32@^6.7
board = esp32-s3-devkitm-1
;Devboard is ESP32-S3-DevKitC-1 (N16R8). board=esp32-s3-devkitm-1 works fine
framework = arduino
monitor_speed = 115200
monitor_port = /dev/ttyACM0
build_flags=
'-D CLIENT_ID="hydroponic-NFT"'
-D PIN_BUTTON=12
-D EC_PIN_RELAY_PROBE=35
-D EC_PIN_FREQ=38
-D EC_CALIBRATION_POLYNOM={8.718380956513695,-0.026463423062356713,3.425216464107108e-05,-4.069826379094172e-09,2.478900495960682e-13}
-D EC_CALIBRATION_LINEARIZE_BELOW_ADC=2000
-D EC_CALIBRATION_LINEAR_LOWADC=728
-D EC_CALIBRATION_LINEAR_LOWEC=0
-D FLOW_PIN=17
-D ONE_WIRE_BUS_PIN=18
-D THERMOMETER_ADDR_RESERVOIR={0x28,0xFF,0x6F,0x19,0x72,0x16,0x05,0x44}
-D THERMOMETER_ADDR_CASE={0x28,0xFF,0x64,0x0E,0x75,0x90,0xDE,0x02}
-D PIN_SDA=1
-D PIN_SCL=2
-D WATERLEVEL_OFFSET=500.0
-D WATERLEVEL_FACTOR=-1.0
-D RES_AREA=20*20*3.1416
lib_deps =
https://github.com/milesburton/Arduino-Temperature-Control-Library/
https://github.com/emilv/ArduinoSort/
robtillaart/ADS1X15@^0.3.9
256dpi/MQTT@^2.5.2
pololu/VL53L0X@^1.3.1
adafruit/Adafruit NeoPixel

View file

@ -9,57 +9,19 @@ 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
bool mqtt=true; bool mqtt=false;
bool eccalibrationoutput=false; //serial output for ec calibration bool eccalibrationoutput=true; //serial output for ec calibration
/* Write to file with: /* Write to file with:
sudo stty -F /dev/ttyUSB0 115200 sudo stty -F /dev/ttyUSB0 115200
cat /dev/ttyUSB0 | tee received.txt cat /dev/ttyUSB0 | tee received.txt
falls nicht geht, vorher einmal kurz per screen verbinden
*/ */
bool valuesStabilized=false; //gets set true when values are stable (avaeraging arrays filled) bool valuesStabilized=false; //gets set true when values are stable (avaeraging arrays filled)
void i2cscan()
{
byte error, address;
int nDevices;
delay(500);
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
}
#include "helpfunctions.h" #include "helpfunctions.h"
#include "ADS1X15.h" #include "ADS1X15.h"
@ -155,7 +117,9 @@ void setup() {
//init ADS1115 //init ADS1115
if (!ADS.begin()) { if (!ADS.begin()) {
Serial.println("Error:"); delay(2000); Serial.println("ADS1115 Init Error!"); Serial.println("Error:"); delay(2000); Serial.println("ADS1115 Init Error!");
if (mqtt){
publishInfo("error/general","ADS1115 Init Error"); publishInfo("error/general","ADS1115 Init Error");
}
adsenabled=false; adsenabled=false;
} }
if (adsenabled){ if (adsenabled){
@ -307,11 +271,12 @@ void loop() {
pixels.setPixelColor(0, pixels.Color(0,0,0)); pixels.setPixelColor(0, pixels.Color(0,0,0));
pixels.show(); pixels.show();
#endif #endif
Serial.print(CLIENT_ID); Serial.print(",");
Serial.print(loopmillis); Serial.print(","); Serial.print(loopmillis); Serial.print(",");
Serial.print(tempCmean_reservoir); Serial.print(","); Serial.print(tempCmean_reservoir); Serial.print(",");
Serial.print(ec_calib_adc); Serial.print(","); Serial.print(ec_calib_adc); Serial.print(",");
Serial.print(ec_adc); Serial.print(","); Serial.print(ec_adc); Serial.print(",");
Serial.print(ec_adc_adjusted); Serial.print(","); Serial.print(ec_adc_adjusted);
Serial.println(); Serial.println();
} }
@ -326,12 +291,16 @@ void loop() {
if (!valueError && valuesStabilized) { //error just appeared if (!valueError && valuesStabilized) { //error just appeared
if (tempCmean_reservoir==DEVICE_DISCONNECTED_C) { if (tempCmean_reservoir==DEVICE_DISCONNECTED_C) {
Serial.println("valueError tempCmean_reservoir"); Serial.println("valueError tempCmean_reservoir");
if (mqtt){
publishInfo("error/temperature","valueError tempCmean_reservoir"); publishInfo("error/temperature","valueError tempCmean_reservoir");
} }
}
if (tempCmean_case==DEVICE_DISCONNECTED_C) { if (tempCmean_case==DEVICE_DISCONNECTED_C) {
Serial.println("valueError tempCmean_case"); Serial.println("valueError tempCmean_case");
if (mqtt){
publishInfo("error/temperature","valueError tempCmean_case"); publishInfo("error/temperature","valueError tempCmean_case");
} }
}
} }
@ -347,9 +316,11 @@ void loop() {
if (!valueError && valuesStabilized) { //error just appeared if (!valueError && valuesStabilized) { //error just appeared
if (ec==EC_UNAVAILABLE){ if (ec==EC_UNAVAILABLE){
Serial.println("valueError ec"); Serial.println("valueError ec");
if (mqtt){
publishInfo("error/ec","valueError ec"); publishInfo("error/ec","valueError ec");
} }
} }
}
valueError=true; valueError=true;
_noErrorsDuringLoop=false; _noErrorsDuringLoop=false;
} }
@ -360,8 +331,10 @@ void loop() {
if (distance_unsuccessful_count>20) { if (distance_unsuccessful_count>20) {
if (!valueError && valuesStabilized) { //error just appeared if (!valueError && valuesStabilized) { //error just appeared
Serial.println("valueError distance"); Serial.println("valueError distance");
if (mqtt){
publishInfo("error/waterlevel","valueError distance"); publishInfo("error/waterlevel","valueError distance");
} }
}
valueError=true; valueError=true;
_noErrorsDuringLoop=false; _noErrorsDuringLoop=false;
} }