mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
Портируем Bme280
This commit is contained in:
@@ -102,10 +102,46 @@
|
||||
"type": "Reading",
|
||||
"subtype": "Bmp280p",
|
||||
"id": "Press3",
|
||||
"widget": "anydataPress",
|
||||
"widget": "anydataMm",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Давление",
|
||||
"int": 15,
|
||||
"addr": "0x76"
|
||||
},
|
||||
{
|
||||
"name": "9. Cенсор температуры Bme280",
|
||||
"num": 9,
|
||||
"type": "Reading",
|
||||
"subtype": "Bme280t",
|
||||
"id": "tmp3",
|
||||
"widget": "anydataTmp",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Температура",
|
||||
"int": 15,
|
||||
"addr": "0x76"
|
||||
},
|
||||
{
|
||||
"name": "10. Cенсор давления Bme280",
|
||||
"num": 10,
|
||||
"type": "Reading",
|
||||
"subtype": "Bme280p",
|
||||
"id": "Press3",
|
||||
"widget": "anydataMm",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Давление",
|
||||
"int": 15,
|
||||
"addr": "0x76"
|
||||
},
|
||||
{
|
||||
"name": "11. Cенсор влажности Bme280",
|
||||
"num": 11,
|
||||
"type": "Reading",
|
||||
"subtype": "Bme280h",
|
||||
"id": "Hum3",
|
||||
"widget": "anydataHum",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Влажность",
|
||||
"int": 15,
|
||||
"addr": "0x76"
|
||||
}
|
||||
]
|
||||
@@ -31,6 +31,7 @@ lib_deps =
|
||||
robtillaart/SHT2x@^0.1.1
|
||||
beegee-tokyo/DHT sensor library for ESPx
|
||||
adafruit/Adafruit BMP280 Library
|
||||
adafruit/Adafruit BME280 Library
|
||||
monitor_filters = esp8266_exception_decoder
|
||||
upload_speed = 921600
|
||||
monitor_speed = 115200
|
||||
@@ -47,6 +48,7 @@ lib_deps =
|
||||
robtillaart/SHT2x@^0.1.1
|
||||
beegee-tokyo/DHT sensor library for ESPx
|
||||
adafruit/Adafruit BMP280 Library
|
||||
adafruit/Adafruit BME280 Library
|
||||
monitor_filters = esp32_exception_decoder
|
||||
upload_speed = 921600
|
||||
monitor_speed = 115200
|
||||
|
||||
@@ -7,6 +7,7 @@ void* getAPI_Ds18b20(String subtype, String params);
|
||||
void* getAPI_Sht20(String subtype, String params);
|
||||
void* getAPI_Dht1122(String subtype, String params);
|
||||
void* getAPI_Bmp280(String subtype, String params);
|
||||
void* getAPI_Bme280(String subtype, String params);
|
||||
//============================================================================================
|
||||
|
||||
void* getAPI(String subtype, String params) {
|
||||
@@ -18,6 +19,7 @@ void* getAPI(String subtype, String params) {
|
||||
if ((tmpAPI = getAPI_Sht20(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Dht1122(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Bmp280(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Bme280(subtype, params)) != nullptr) return tmpAPI;
|
||||
//================================================================================================================
|
||||
|
||||
return nullptr;
|
||||
|
||||
94
src/modules/Bme280.cpp
Normal file
94
src/modules/Bme280.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
/******************************************************************
|
||||
Used Adafruit BME280 Driver (Barometric Pressure Sensor)
|
||||
Support for BME280
|
||||
https://github.com/adafruit/Adafruit_BME280_Library
|
||||
******************************************************************/
|
||||
|
||||
|
||||
#include "Global.h"
|
||||
#include "Classes/IoTSensor.h"
|
||||
|
||||
#include <Adafruit_BME280.h>
|
||||
#include <map>
|
||||
|
||||
|
||||
std::map<String, Adafruit_BME280*> bmes;
|
||||
|
||||
class Bme280t : public IoTSensor {
|
||||
private:
|
||||
Adafruit_BME280* _bme;
|
||||
|
||||
public:
|
||||
Bme280t(Adafruit_BME280* bme, String parameters): IoTSensor(parameters) {
|
||||
_bme = bme;
|
||||
}
|
||||
|
||||
void doByInterval() {
|
||||
float value = _bme->readTemperature();
|
||||
if (value < 145) regEvent(value, "Bme280t");
|
||||
else SerialPrint("E", "Sensor Bme280t", "Error");
|
||||
}
|
||||
|
||||
~Bme280t();
|
||||
};
|
||||
|
||||
|
||||
class Bme280h : public IoTSensor {
|
||||
private:
|
||||
Adafruit_BME280* _bme;
|
||||
|
||||
public:
|
||||
Bme280h(Adafruit_BME280* bme, String parameters): IoTSensor(parameters) {
|
||||
_bme = bme;
|
||||
}
|
||||
|
||||
void doByInterval() {
|
||||
float value = _bme->readHumidity();
|
||||
if (value < 100) regEvent(value, "Bme280h");
|
||||
else SerialPrint("E", "Sensor Bme280h", "Error");
|
||||
}
|
||||
|
||||
~Bme280h();
|
||||
};
|
||||
|
||||
|
||||
class Bme280p : public IoTSensor {
|
||||
private:
|
||||
Adafruit_BME280* _bme;
|
||||
|
||||
public:
|
||||
Bme280p(Adafruit_BME280* bme, String parameters): IoTSensor(parameters) {
|
||||
_bme = bme;
|
||||
}
|
||||
|
||||
void doByInterval() {
|
||||
float value = _bme->readPressure();
|
||||
if (value > 0) {
|
||||
value = value / 1.333224 / 100;
|
||||
regEvent(value, "Bme280p");
|
||||
} else SerialPrint("E", "Sensor Bme280p", "Error");
|
||||
}
|
||||
|
||||
~Bme280p();
|
||||
};
|
||||
|
||||
|
||||
void* getAPI_Bme280(String subtype, String param) {
|
||||
String addr;
|
||||
jsonRead(param, "addr", addr);
|
||||
|
||||
if (bmes.find(addr) == bmes.end()) {
|
||||
bmes[addr] = new Adafruit_BME280();
|
||||
bmes[addr]->begin(hexStringToUint8(addr));
|
||||
}
|
||||
|
||||
if (subtype == F("Bme280t")) {
|
||||
return new Bme280t(bmes[addr], param);
|
||||
} else if (subtype == F("Bme280h")) {
|
||||
return new Bme280h(bmes[addr], param);
|
||||
} else if (subtype == F("Bme280p")) {
|
||||
return new Bme280p(bmes[addr], param);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user