From 5d47246bda44e10e9918db29dfab223c3b25eabe Mon Sep 17 00:00:00 2001 From: Fisch Date: Wed, 13 Oct 2021 17:24:04 +0200 Subject: [PATCH 1/2] fix homie error with current esp version --- platformio.ini | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/platformio.ini b/platformio.ini index 9b497d9..a32e17d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -17,13 +17,13 @@ #data_dir=data_sensoresp2 #data_dir=data_sensoresp3 #data_dir=data_sensoresp4 -data_dir=data_sensoresp5 +#data_dir=data_sensoresp5 #data_dir=data_sensoresp3dprinter #Outdoor [env:sensoresp0] -platform = espressif8266 +platform = espressif8266 @ 2.5.0 #using old esp version, because of "obsolete API, use ::begin(WiFiClient, url)" error. Try again if fix available in platformio over vscode board = d1_mini framework = arduino @@ -72,7 +72,7 @@ lib_deps = #Arbeitszimmer [env:sensoresp1] -platform = espressif8266 +platform = espressif8266 @ 2.5.0 board = d1_mini framework = arduino @@ -111,7 +111,7 @@ lib_deps = #Wohnzimmer Air Quality [env:sensoresp2] -platform = espressif8266 +platform = espressif8266 @ 2.5.0 board = d1_mini framework = arduino @@ -140,7 +140,7 @@ lib_deps = #Wohnzimmer [env:sensoresp3] -platform = espressif8266 +platform = espressif8266 @ 2.5.0 board = d1_mini framework = arduino @@ -171,7 +171,7 @@ lib_deps = #Schlafzimmer [env:sensoresp4] -platform = espressif8266 +platform = espressif8266 @ 2.5.0 board = d1_mini framework = arduino @@ -210,7 +210,7 @@ lib_deps = #Kueche [env:sensoresp5] -platform = espressif8266 +platform = espressif8266 @ 2.5.0 board = d1_mini framework = arduino @@ -242,18 +242,19 @@ build_flags = -D dataBH1750_senddelaymax=1000*60*2 + lib_deps = adafruit/DHT sensor library@1.3.10 claws/BH1750@1.1.4 - ArduinoJson@6.16.1 #dependency of homie. using older version because of "ambiguous overload for operator|" error - Homie@3.0.0 + ArduinoJson@6.16.1 + marvinroger/Homie @ ^3.0.1 pololu/VL53L1X @ ^1.3.0 #3D Printer [env:sensoresp3dprinter] -platform = espressif8266 +platform = espressif8266 @ 2.5.0 board = d1_mini framework = arduino From c588c99cd7da583a4227c00b132bd87fd789a881 Mon Sep 17 00:00:00 2001 From: Fisch Date: Wed, 13 Oct 2021 19:01:22 +0200 Subject: [PATCH 2/2] implement vl53l1x tof sensor --- platformio.ini | 8 +++++--- src/main.cpp | 48 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/platformio.ini b/platformio.ini index a32e17d..1cd616f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -214,7 +214,8 @@ platform = espressif8266 @ 2.5.0 board = d1_mini framework = arduino -monitor_port = /dev/ttyUSB0 +#monitor_port = /dev/ttyUSB0 +monitor_port = COM3 monitor_speed = 115200 build_flags = @@ -238,8 +239,9 @@ build_flags = -D dataBH1750_senddelaymax=1000*60*2 -D SENSOR_VL53L1X - -D dataBH1750_minchange=10.0 - -D dataBH1750_senddelaymax=1000*60*2 + -D dataVL53L1X_minchange=100 + -D dataVL53L1X_senddelaymax=1000*30 + -D dataVL53L1X_readdelay=1000 diff --git a/src/main.cpp b/src/main.cpp index b5570a5..42e06a0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -236,12 +236,12 @@ struct sensordata #include VL53L1X vl53l1x; bool vl53l1xinit_ok=false; - struct sensordata dataVL53L1X_range; - struct sensordata dataVL53L1X_peak_signal_count_rate; - struct sensordata dataVL53L1X_ambient_count_rate; + struct sensordata dataVL53L1X; uint16_t value_vl53l1x_range; + unsigned long lastread_vl53l1x=0; + VL53L1X::RangeStatus lastsentvalue_vl53l1x_status; #endif #ifdef SENSOR_ANEMOMETER @@ -487,10 +487,16 @@ void setup() { vl53l1xinit_ok=true; vl53l1x.setDistanceMode(VL53L1X::Long); vl53l1x.setMeasurementTimingBudget(50000); - vl53l1x.startContinuous(50); //This period should be at least as long as the timing budget. + vl53l1x.startContinuous(1000); //This period should be at least as long as the timing budget. } - #ifdef dataVL53L1X_range_minchange - dataVL53L1X_range.minchange=dataVL53L1X_range_minchange; + #ifdef dataVL53L1X_minchange + dataVL53L1X.minchange=dataVL53L1X_minchange; + #endif + #ifdef dataVL53L1X_senddelaymax + dataVL53L1X.senddelaymax=dataVL53L1X_senddelaymax; + #endif + #ifdef dataVL53L1X_readdelay + dataVL53L1X.readdelay=dataVL53L1X_readdelay; #endif #endif @@ -608,7 +614,10 @@ void setup() { #endif #ifdef SENSOR_VL53L1X - sensorNode.advertise("range"); + sensorNode.advertise("tofstatus"); + sensorNode.advertise("tofrange"); + sensorNode.advertise("tofpeaksignal"); + sensorNode.advertise("tofambient"); #endif #ifdef SENSOR_ANEMOMETER @@ -1200,9 +1209,9 @@ void loop_TCS34725_colortemp() #ifdef SENSOR_VL53L1X -void loop_VL53L1X_range() +void loop_VL53L1X() { - sensordata &d=dataVL53L1X_range; + sensordata &d=dataVL53L1X; bool _changed=false; if (millis() >= (d.lastreadtime+d.readdelay)) { @@ -1213,18 +1222,27 @@ void loop_VL53L1X_range() } value_vl53l1x_range=vl53l1x.ranging_data.range_mm; + + /* for debugging Serial.print("range: "); Serial.print(vl53l1x.ranging_data.range_mm); Serial.print("\tstatus: "); Serial.print(VL53L1X::rangeStatusToString(vl53l1x.ranging_data.range_status)); + Serial.print("\tstatus="); + Serial.print(vl53l1x.ranging_data.range_status); Serial.print("\tpeak signal: "); Serial.print(vl53l1x.ranging_data.peak_signal_count_rate_MCPS); Serial.print("\tambient: "); Serial.print(vl53l1x.ranging_data.ambient_count_rate_MCPS); + Serial.println(); + */ if (abs((int)d.lastsentvalue-value_vl53l1x_range)>=d.minchange){ //int abs _changed=true; } + if (lastsentvalue_vl53l1x_status!=vl53l1x.ranging_data.range_status) { //sensor status changed + _changed=true; + } d.lastreadtime=millis(); } @@ -1235,10 +1253,14 @@ void loop_VL53L1X_range() Homie.getLogger() << "range vl53l1x " << ": " << value_vl53l1x_range << endl; - sensorNode.setProperty("range").send(String(value_vl53l1x_range)); + sensorNode.setProperty("tofstatus").send(VL53L1X::rangeStatusToString(vl53l1x.ranging_data.range_status)); + sensorNode.setProperty("tofrange").send(String(value_vl53l1x_range)); + sensorNode.setProperty("tofpeaksignal").send(String(vl53l1x.ranging_data.peak_signal_count_rate_MCPS)); + sensorNode.setProperty("tofambient").send(String(vl53l1x.ranging_data.ambient_count_rate_MCPS)); d.lastsentvalue=value_vl53l1x_range; + lastsentvalue_vl53l1x_status=vl53l1x.ranging_data.range_status; d.lastsent=millis(); } @@ -1394,6 +1416,12 @@ void loopHandler() { } #endif + #ifdef SENSOR_VL53L1X + if (vl53l1xinit_ok) { + loop_VL53L1X(); + } + #endif + #ifdef SENSOR_ANEMOMETER loop_anemometer(); #endif