mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
Портируем сенсор Bmp280
This commit is contained in:
@@ -53,7 +53,7 @@
|
||||
"type": "Reading",
|
||||
"subtype": "Sht20h",
|
||||
"id": "Hum2",
|
||||
"widget": "anydataTmp",
|
||||
"widget": "anydataHum",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Влажность",
|
||||
"int": 15
|
||||
@@ -77,11 +77,35 @@
|
||||
"type": "Reading",
|
||||
"subtype": "Dht1122h",
|
||||
"id": "Hum3",
|
||||
"widget": "anydataTmp",
|
||||
"widget": "anydataHum",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Влажность",
|
||||
"int": 15,
|
||||
"pin": 0,
|
||||
"senstype": "dht11"
|
||||
},
|
||||
{
|
||||
"name": "7. Cенсор температуры Bmp280",
|
||||
"num": 7,
|
||||
"type": "Reading",
|
||||
"subtype": "Bmp280t",
|
||||
"id": "tmp3",
|
||||
"widget": "anydataTmp",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Температура",
|
||||
"int": 15,
|
||||
"addr": "0x76"
|
||||
},
|
||||
{
|
||||
"name": "8. Cенсор давления Bmp280",
|
||||
"num": 8,
|
||||
"type": "Reading",
|
||||
"subtype": "Bmp280p",
|
||||
"id": "Press3",
|
||||
"widget": "anydataPress",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Давление",
|
||||
"int": 15,
|
||||
"addr": "0x76"
|
||||
}
|
||||
]
|
||||
@@ -30,6 +30,7 @@ lib_deps =
|
||||
milesburton/DallasTemperature@^3.9.1
|
||||
robtillaart/SHT2x@^0.1.1
|
||||
beegee-tokyo/DHT sensor library for ESPx
|
||||
adafruit/Adafruit BMP280 Library
|
||||
monitor_filters = esp8266_exception_decoder
|
||||
upload_speed = 921600
|
||||
monitor_speed = 115200
|
||||
@@ -45,6 +46,7 @@ lib_deps =
|
||||
milesburton/DallasTemperature@^3.9.1
|
||||
robtillaart/SHT2x@^0.1.1
|
||||
beegee-tokyo/DHT sensor library for ESPx
|
||||
adafruit/Adafruit BMP280 Library
|
||||
monitor_filters = esp32_exception_decoder
|
||||
upload_speed = 921600
|
||||
monitor_speed = 115200
|
||||
|
||||
@@ -6,6 +6,7 @@ void* getAPI_AnalogAdc(String subtype, String params);
|
||||
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(String subtype, String params) {
|
||||
@@ -16,6 +17,7 @@ void* getAPI(String subtype, String params) {
|
||||
if ((tmpAPI = getAPI_Ds18b20(subtype, params)) != nullptr) return tmpAPI;
|
||||
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;
|
||||
//================================================================================================================
|
||||
|
||||
return nullptr;
|
||||
|
||||
73
src/modules/Bmp280.cpp
Normal file
73
src/modules/Bmp280.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/******************************************************************
|
||||
Used Adafruit BMP280 Driver (Barometric Pressure Sensor)
|
||||
Support for BMP280
|
||||
https://github.com/adafruit/Adafruit_BMP280_Library
|
||||
******************************************************************/
|
||||
|
||||
|
||||
#include "Global.h"
|
||||
#include "Classes/IoTSensor.h"
|
||||
|
||||
#include <Adafruit_BMP280.h>
|
||||
#include <map>
|
||||
|
||||
|
||||
std::map<String, Adafruit_BMP280*> bmps;
|
||||
|
||||
class Bmp280t : public IoTSensor {
|
||||
private:
|
||||
Adafruit_BMP280* _bmp;
|
||||
|
||||
public:
|
||||
Bmp280t(Adafruit_BMP280* bmp, String parameters): IoTSensor(parameters) {
|
||||
_bmp = bmp;
|
||||
}
|
||||
|
||||
void doByInterval() {
|
||||
float value = _bmp->readTemperature();
|
||||
if (String(value) != "nan") regEvent(value, "Bmp280t");
|
||||
else SerialPrint("E", "Sensor DHTt", "Error");
|
||||
}
|
||||
|
||||
~Bmp280t();
|
||||
};
|
||||
|
||||
|
||||
class Bmp280p : public IoTSensor {
|
||||
private:
|
||||
Adafruit_BMP280* _bmp;
|
||||
|
||||
public:
|
||||
Bmp280p(Adafruit_BMP280* bmp, String parameters): IoTSensor(parameters) {
|
||||
_bmp = bmp;
|
||||
}
|
||||
|
||||
void doByInterval() {
|
||||
float value = _bmp->readPressure();
|
||||
if (String(value) != "nan") {
|
||||
value = value / 1.333224 / 100;
|
||||
regEvent(value, "Bmp280p");
|
||||
} else SerialPrint("E", "Sensor DHTh", "Error");
|
||||
}
|
||||
|
||||
~Bmp280p();
|
||||
};
|
||||
|
||||
|
||||
void* getAPI_Bmp280(String subtype, String param) {
|
||||
String addr;
|
||||
jsonRead(param, "addr", addr);
|
||||
|
||||
if (bmps.find(addr) == bmps.end()) {
|
||||
bmps[addr] = new Adafruit_BMP280();
|
||||
bmps[addr]->begin(hexStringToUint8(addr));
|
||||
}
|
||||
|
||||
if (subtype == F("Bmp280t")) {
|
||||
return new Bmp280t(bmps[addr], param);
|
||||
} else if (subtype == F("Bmp280p")) {
|
||||
return new Bmp280p(bmps[addr], param);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user