diff --git a/data_svelte/items.json b/data_svelte/items.json index 2437d262..70f84c8b 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -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" } ] \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 5fb418d2..50924368 100644 --- a/platformio.ini +++ b/platformio.ini @@ -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 diff --git a/src/modules/API.cpp b/src/modules/API.cpp index 9628fd87..24ff97aa 100644 --- a/src/modules/API.cpp +++ b/src/modules/API.cpp @@ -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; diff --git a/src/modules/Bme280.cpp b/src/modules/Bme280.cpp new file mode 100644 index 00000000..09317cb0 --- /dev/null +++ b/src/modules/Bme280.cpp @@ -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 +#include + + +std::map 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; + } +}