This commit is contained in:
interfisch 2021-10-31 14:07:16 +01:00
commit 2353fea4f6
2 changed files with 54 additions and 23 deletions

View File

@ -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
@ -115,7 +115,7 @@ lib_deps =
#Wohnzimmer Air Quality
[env:sensoresp2]
platform = espressif8266
platform = espressif8266 @ 2.5.0
board = d1_mini
framework = arduino
@ -144,7 +144,7 @@ lib_deps =
#Wohnzimmer
[env:sensoresp3]
platform = espressif8266
platform = espressif8266 @ 2.5.0
board = d1_mini
framework = arduino
@ -175,7 +175,7 @@ lib_deps =
#Schlafzimmer
[env:sensoresp4]
platform = espressif8266
platform = espressif8266 @ 2.5.0
board = d1_mini
framework = arduino
@ -214,11 +214,12 @@ lib_deps =
#Kueche
[env:sensoresp5]
platform = espressif8266
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 =
@ -242,22 +243,24 @@ 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
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

View File

@ -241,12 +241,12 @@
#include <VL53L1X.h>
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
@ -602,7 +608,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
@ -1129,9 +1138,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)) {
@ -1142,18 +1151,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();
}
@ -1164,10 +1182,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();
}
@ -1323,6 +1345,12 @@ void loopHandler() {
}
#endif
#ifdef SENSOR_VL53L1X
if (vl53l1xinit_ok) {
loop_VL53L1X();
}
#endif
#ifdef SENSOR_ANEMOMETER
loop_anemometer();
#endif