fix send mqtt errors only when mqtt enabled
This commit is contained in:
parent
111758b4ae
commit
70b0b0f1a8
3 changed files with 108 additions and 49 deletions
|
@ -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
|
|
@ -8,7 +8,7 @@
|
|||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:esp32doit-devkit-v1_NFT]
|
||||
[env:esp32doit-devkit-v1_NFT_2024]
|
||||
platform = espressif32
|
||||
board = esp32doit-devkit-v1
|
||||
framework = arduino
|
||||
|
@ -50,6 +50,7 @@ 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_port = /dev/ttyACM1
|
||||
|
||||
monitor_speed = 115200
|
||||
|
||||
|
@ -86,3 +87,49 @@ lib_deps =
|
|||
256dpi/MQTT@^2.5.2
|
||||
pololu/VL53L0X@^1.3.1
|
||||
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
|
59
src/main.cpp
59
src/main.cpp
|
@ -9,57 +9,19 @@ unsigned long last_check=0;
|
|||
#include "wifi_functions.h"
|
||||
|
||||
bool debug=false; //print Serial information
|
||||
bool mqtt=true;
|
||||
bool eccalibrationoutput=false; //serial output for ec calibration
|
||||
bool mqtt=false;
|
||||
bool eccalibrationoutput=true; //serial output for ec calibration
|
||||
/* Write to file with:
|
||||
sudo stty -F /dev/ttyUSB0 115200
|
||||
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)
|
||||
|
||||
|
||||
|
||||
|
||||
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 "ADS1X15.h"
|
||||
|
||||
|
@ -155,7 +117,9 @@ void setup() {
|
|||
//init ADS1115
|
||||
if (!ADS.begin()) {
|
||||
Serial.println("Error:"); delay(2000); Serial.println("ADS1115 Init Error!");
|
||||
if (mqtt){
|
||||
publishInfo("error/general","ADS1115 Init Error");
|
||||
}
|
||||
adsenabled=false;
|
||||
}
|
||||
if (adsenabled){
|
||||
|
@ -307,11 +271,12 @@ void loop() {
|
|||
pixels.setPixelColor(0, pixels.Color(0,0,0));
|
||||
pixels.show();
|
||||
#endif
|
||||
Serial.print(CLIENT_ID); Serial.print(",");
|
||||
Serial.print(loopmillis); Serial.print(",");
|
||||
Serial.print(tempCmean_reservoir); Serial.print(",");
|
||||
Serial.print(ec_calib_adc); Serial.print(",");
|
||||
Serial.print(ec_adc); Serial.print(",");
|
||||
Serial.print(ec_adc_adjusted); Serial.print(",");
|
||||
Serial.print(ec_adc_adjusted);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
@ -326,12 +291,16 @@ void loop() {
|
|||
if (!valueError && valuesStabilized) { //error just appeared
|
||||
if (tempCmean_reservoir==DEVICE_DISCONNECTED_C) {
|
||||
Serial.println("valueError tempCmean_reservoir");
|
||||
if (mqtt){
|
||||
publishInfo("error/temperature","valueError tempCmean_reservoir");
|
||||
}
|
||||
}
|
||||
if (tempCmean_case==DEVICE_DISCONNECTED_C) {
|
||||
Serial.println("valueError tempCmean_case");
|
||||
if (mqtt){
|
||||
publishInfo("error/temperature","valueError tempCmean_case");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -347,9 +316,11 @@ void loop() {
|
|||
if (!valueError && valuesStabilized) { //error just appeared
|
||||
if (ec==EC_UNAVAILABLE){
|
||||
Serial.println("valueError ec");
|
||||
if (mqtt){
|
||||
publishInfo("error/ec","valueError ec");
|
||||
}
|
||||
}
|
||||
}
|
||||
valueError=true;
|
||||
_noErrorsDuringLoop=false;
|
||||
}
|
||||
|
@ -360,8 +331,10 @@ void loop() {
|
|||
if (distance_unsuccessful_count>20) {
|
||||
if (!valueError && valuesStabilized) { //error just appeared
|
||||
Serial.println("valueError distance");
|
||||
if (mqtt){
|
||||
publishInfo("error/waterlevel","valueError distance");
|
||||
}
|
||||
}
|
||||
valueError=true;
|
||||
_noErrorsDuringLoop=false;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue