Skip to content

Commit 4d1a15a

Browse files
authored
Bosch sensors improvements (#515)
1 parent c74956d commit 4d1a15a

File tree

7 files changed

+40
-5
lines changed

7 files changed

+40
-5
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ SensorMotion | 1 | Motion sensor, wake up the board and report w
109109
SensorDs18b20 | 1+ | DS18B20 sensor, return the temperature based on the attached sensor | https://github.com/milesburton/Arduino-Temperature-Control-Library
110110
SensorBH1750 | 1 | BH1750 sensor, return light level in lux | https://github.com/claws/BH1750
111111
SensorMLX90614 | 2 | MLX90614 contactless temperature sensor, return ambient and object temperature | https://github.com/adafruit/Adafruit-MLX90614-Library
112-
SensorBME280 | 4 | BME280 sensor, return temperature/humidity/pressure based on the attached BME280 sensor | https://github.com/adafruit/Adafruit_BME280_Library
113-
SensorBMP085 | 3 | BMP085 sensor, return temperature and pressure | https://github.com/adafruit/Adafruit-BMP085-Library
114-
SensorBMP180 | 3 | BMP180 sensor, return temperature and pressure | https://github.com/adafruit/Adafruit-BMP085-Library
115-
SensorBMP280 | 3 | BMP280 sensor, return temperature/pressure based on the attached BMP280 sensor | https://github.com/adafruit/Adafruit_BMP280_Library
112+
SensorBME280 | 4 | BME280 sensor, return temperature/humidity/pressure based on the attached BME280 sensor | https://github.com/adafruit/Adafruit_BME280_Library / https://github.com/adafruit/Adafruit_Sensor
113+
SensorBMP085 | 3 | BMP085 sensor, return temperature and pressure | https://github.com/adafruit/Adafruit-BMP085-Library / https://github.com/adafruit/Adafruit_Sensor
114+
SensorBMP180 | 3 | BMP180 sensor, return temperature and pressure | https://github.com/adafruit/Adafruit-BMP085-Library / https://github.com/adafruit/Adafruit_Sensor
115+
SensorBMP280 | 3 | BMP280 sensor, return temperature/pressure based on the attached BMP280 sensor | https://github.com/adafruit/Adafruit_BMP280_Library / https://github.com/adafruit/Adafruit_Sensor
116116
SensorSonoff | 1 | Sonoff wireless smart switch | https://github.com/thomasfredericks/Bounce2
117117
SensorHCSR04 | 1 | HC-SR04 sensor, return the distance between the sensor and an object | https://github.com/mysensors/MySensorsArduinoExamples/tree/master/libraries/NewPing
118118
SensorMCP9808 | 1 | MCP9808 sensor, measure the temperature through the attached module | https://github.com/adafruit/Adafruit_MCP9808_Library

examples/Template/Template.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ NodeManager. Just uncomment the settings you need and the sensors you want to ad
259259
//#include <sensors/SensorMLX90614.h>
260260
//SensorMLX90614 mlx90614;
261261

262+
//#define NODEMANAGER_SENSOR_BOSCH_LITE
262263
//#include <sensors/SensorBME280.h>
263264
//SensorBME280 bme280;
264265

sensors/SensorBME280.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,17 @@ class SensorBME280: public SensorBosch {
3737
public:
3838
SensorBME280(uint8_t child_id = 0): SensorBosch(child_id) {
3939
_name = "BME280";
40+
#if !defined(NODEMANAGER_SENSOR_BOSCH_LITE)
4041
children.allocateBlocks(4);
42+
#else
43+
children.allocateBlocks(3);
44+
#endif
4145
new Child(this,FLOAT,nodeManager.getAvailableChildId(child_id),S_TEMP,V_TEMP,_name);
4246
new Child(this,FLOAT,child_id > 0 ? nodeManager.getAvailableChildId(child_id+1) : nodeManager.getAvailableChildId(child_id),S_HUM,V_HUM,_name);
4347
new Child(this,FLOAT,child_id > 0 ? nodeManager.getAvailableChildId(child_id+2) : nodeManager.getAvailableChildId(child_id),S_BARO,V_PRESSURE,_name);
48+
#if !defined(NODEMANAGER_SENSOR_BOSCH_LITE)
4449
new Child(this,STRING,child_id > 0 ? nodeManager.getAvailableChildId(child_id+3) : nodeManager.getAvailableChildId(child_id),S_BARO,V_FORECAST,_name);
50+
#endif
4551
};
4652

4753
// set custom sampling to the sensor
@@ -80,11 +86,13 @@ class SensorBME280: public SensorBosch {
8086
// store the value
8187
child->setValue(pressure);
8288
}
89+
#if !defined(NODEMANAGER_SENSOR_BOSCH_LITE)
8390
// Forecast Sensor
8491
else if (child->getType() == V_FORECAST) {
8592
float pressure = _bm->readPressure() / 100.0F;
8693
child->setValue(_forecast(pressure));
8794
}
95+
#endif
8896
};
8997
};
9098
#endif

sensors/SensorBMP085.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,16 @@ class SensorBMP085: public SensorBosch {
3535
public:
3636
SensorBMP085(uint8_t child_id = 0): SensorBosch(child_id) {
3737
_name = "BMP085";
38+
#if !defined(NODEMANAGER_SENSOR_BOSCH_LITE)
3839
children.allocateBlocks(3);
40+
#else
41+
children.allocateBlocks(2);
42+
#endif
3943
new Child(this,FLOAT,nodeManager.getAvailableChildId(child_id),S_TEMP,V_TEMP,_name);
4044
new Child(this,FLOAT,child_id > 0 ? nodeManager.getAvailableChildId(child_id+1) : nodeManager.getAvailableChildId(child_id),S_BARO,V_PRESSURE,_name);
45+
#if !defined(NODEMANAGER_SENSOR_BOSCH_LITE)
4146
new Child(this,STRING,child_id > 0 ? nodeManager.getAvailableChildId(child_id+2) : nodeManager.getAvailableChildId(child_id),S_BARO,V_FORECAST,_name);
47+
#endif
4248
};
4349

4450
// define what to do during setup
@@ -65,11 +71,13 @@ class SensorBMP085: public SensorBosch {
6571
// store the value
6672
child->setValue(pressure);
6773
}
74+
#if !defined(NODEMANAGER_SENSOR_BOSCH_LITE)
6875
// Forecast Sensor
6976
else if (child->getType() == V_FORECAST) {
7077
float pressure = _bm->readPressure() / 100.0F;
7178
child->setValue(_forecast(pressure));
7279
}
80+
#endif
7381
};
7482
};
7583
#endif

sensors/SensorBMP180.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ class SensorBMP180: public SensorBMP085 {
3131
_name = "BMP180";
3232
children.get(1)->setDescription(_name);
3333
children.get(2)->setDescription(_name);
34+
#if !defined(NODEMANAGER_SENSOR_BOSCH_LITE)
3435
children.get(3)->setDescription(_name);
36+
#endif
3537
};
3638
};
3739
#endif

sensors/SensorBMP280.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,16 @@ class SensorBMP280: public SensorBosch {
3636
public:
3737
SensorBMP280(uint8_t child_id = 0): SensorBosch(child_id) {
3838
_name = "BMP280";
39+
#if !defined(NODEMANAGER_SENSOR_BOSCH_LITE)
3940
children.allocateBlocks(3);
41+
#else
42+
children.allocateBlocks(2);
43+
#endif
4044
new Child(this,FLOAT,nodeManager.getAvailableChildId(child_id),S_TEMP,V_TEMP,_name);
4145
new Child(this,FLOAT,child_id > 0 ? nodeManager.getAvailableChildId(child_id+1) : nodeManager.getAvailableChildId(child_id),S_BARO,V_PRESSURE,_name);
46+
#if !defined(NODEMANAGER_SENSOR_BOSCH_LITE)
4247
new Child(this,STRING,child_id > 0 ? nodeManager.getAvailableChildId(child_id+2) : nodeManager.getAvailableChildId(child_id),S_BARO,V_FORECAST,_name);
48+
#endif
4349

4450
};
4551

@@ -67,11 +73,13 @@ class SensorBMP280: public SensorBosch {
6773
// store the value
6874
child->setValue(pressure);
6975
}
76+
#if !defined(NODEMANAGER_SENSOR_BOSCH_LITE)
7077
// Forecast Sensor
7178
else if (child->getType() == V_FORECAST) {
7279
float pressure = _bm->readPressure() / 100.0F;
7380
child->setValue(_forecast(pressure));
7481
}
82+
#endif
7583
};
7684
};
7785
#endif

sensors/SensorBosch.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
class SensorBosch: public Sensor {
2727
protected:
28+
#if !defined(NODEMANAGER_SENSOR_BOSCH_LITE)
2829
const char* _weather[6] = { "stable", "sunny", "cloudy", "unstable", "thunderstorm", "unknown" };
2930
int _forecast_samples_count = 5;
3031
float* _forecast_samples;
@@ -33,18 +34,23 @@ class SensorBosch: public Sensor {
3334
float _pressure_avg2;
3435
float _dP_dt;
3536
bool _first_round = true;
36-
37+
#endif
38+
3739
public:
3840
SensorBosch(uint8_t child_id = 0): Sensor(-1) {
3941
_name = "BOSCH";
42+
#if !defined(NODEMANAGER_SENSOR_BOSCH_LITE)
4043
// initialize the forecast samples array
4144
_forecast_samples = new float[_forecast_samples_count];
45+
#endif
4246
};
4347

48+
#if !defined(NODEMANAGER_SENSOR_BOSCH_LITE)
4449
// [101] define how many pressure samples to keep track of for calculating the forecast (default: 5)
4550
void setForecastSamplesCount(int value) {
4651
_forecast_samples_count = value;
4752
};
53+
#endif
4854

4955
// search for a given chip on i2c bus (emulating Adafruit's init() function)
5056
uint8_t detectI2CAddress(uint8_t chip_id) {
@@ -84,6 +90,7 @@ class SensorBosch: public Sensor {
8490
#endif
8591

8692
protected:
93+
#if !defined(NODEMANAGER_SENSOR_BOSCH_LITE)
8794
// returns the average of the latest pressure samples
8895
float _getLastPressureSamplesAverage() {
8996
float avg = 0;
@@ -158,5 +165,6 @@ class SensorBosch: public Sensor {
158165
else forecast = 5;
159166
return _weather[forecast];
160167
};
168+
#endif
161169
};
162170
#endif

0 commit comments

Comments
 (0)