This repository has been archived by the owner on Apr 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Module_BME280.cpp
55 lines (43 loc) · 1.45 KB
/
Module_BME280.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "Module_BME280.h"
BME280I2C bme;
void setup_bcm280_module() {
while(!bme.begin())
{
Serial.println("Could not find BME280 sensor!");
delay(1000);
}
switch(bme.chipModel())
{
case BME280::ChipModel_BME280:
Serial.println("Found BME280 with humidity sensor.");
break;
case BME280::ChipModel_BMP280:
Serial.println("Found BMP280 sensor without humidity.");
break;
default:
Serial.println("Error! Found UNKNOWN sensor model!");
}
}
void formatBmeSensorData(JsonDocument& target, const char *uid, int rssi) {
float temp(NAN), humi(NAN), pres(NAN);
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
BME280::PresUnit presUnit(BME280::PresUnit_hPa);
bme.read(pres, temp, humi, tempUnit, presUnit);
// Clip some decimals
double temperature = 0.01 * (int)(temp * 100);
double humidity = 0.01 * (int)(humi * 100);
double pressure = 0.001 * (int)(pres * 1000);
target["id"] = uid;
target["name"] = BME_SENSOR_NAME;
target["temperature"] = temperature;
target["humidity"] = humidity;
target["pressure"] = pressure;
target["signal_strength"] = rssi;
}
void printBME280Data(void (*callb) (float, float, float)) {
float temp(NAN), hum(NAN), pres(NAN);
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
BME280::PresUnit presUnit(BME280::PresUnit_hPa);
bme.read(pres, temp, hum, tempUnit, presUnit);
callb(temp, hum, pres);
}