mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-04-01 12:59:12 +03:00
Меняем структуру FS для хранения модулей и добавляем скрипт сборки модулей для интеграции в меню и библиотеки
This commit is contained in:
97
src/modules/sensors/Bme280/Bme280.cpp
Normal file
97
src/modules/sensors/Bme280/Bme280.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
/******************************************************************
|
||||
Used Adafruit BME280 Driver (Barometric Pressure Sensor)
|
||||
Support for BME280
|
||||
https://github.com/adafruit/Adafruit_BME280_Library
|
||||
******************************************************************/
|
||||
|
||||
#include "Global.h"
|
||||
#include "classes/IoTItem.h"
|
||||
|
||||
#include <Adafruit_BME280.h>
|
||||
#include <map>
|
||||
|
||||
std::map<String, Adafruit_BME280*> bmes;
|
||||
|
||||
class Bme280t : public IoTItem {
|
||||
private:
|
||||
Adafruit_BME280* _bme;
|
||||
|
||||
public:
|
||||
Bme280t(Adafruit_BME280* bme, String parameters) : IoTItem(parameters) {
|
||||
_bme = bme;
|
||||
}
|
||||
|
||||
void doByInterval() {
|
||||
value.valD = _bme->readTemperature();
|
||||
if (value.valD < 145)
|
||||
regEvent(value.valD, "Bme280t");
|
||||
else
|
||||
SerialPrint("E", "Sensor Bme280t", "Error");
|
||||
}
|
||||
|
||||
~Bme280t() {};
|
||||
};
|
||||
|
||||
class Bme280h : public IoTItem {
|
||||
private:
|
||||
Adafruit_BME280* _bme;
|
||||
|
||||
public:
|
||||
Bme280h(Adafruit_BME280* bme, String parameters) : IoTItem(parameters) {
|
||||
_bme = bme;
|
||||
}
|
||||
|
||||
void doByInterval() {
|
||||
value.valD = _bme->readHumidity();
|
||||
if (value.valD < 100)
|
||||
regEvent(value.valD, "Bme280h");
|
||||
else
|
||||
SerialPrint("E", "Sensor Bme280h", "Error");
|
||||
}
|
||||
|
||||
~Bme280h() {};
|
||||
};
|
||||
|
||||
class Bme280p : public IoTItem {
|
||||
private:
|
||||
Adafruit_BME280* _bme;
|
||||
|
||||
public:
|
||||
Bme280p(Adafruit_BME280* bme, String parameters) : IoTItem(parameters) {
|
||||
_bme = bme;
|
||||
}
|
||||
|
||||
void doByInterval() {
|
||||
value.valD = _bme->readPressure();
|
||||
if (value.valD > 0) {
|
||||
value.valD = value.valD / 1.333224 / 100;
|
||||
regEvent(value.valD, "Bme280p");
|
||||
} else
|
||||
SerialPrint("E", "Sensor Bme280p", "Error");
|
||||
}
|
||||
|
||||
~Bme280p() {};
|
||||
};
|
||||
|
||||
|
||||
void* getAPI_Bme280(String subtype, String param) {
|
||||
if (subtype == F("Bme280t") || subtype == F("Bme280h") || subtype == F("Bme280p")) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
41
src/modules/sensors/Bme280/items.json
Normal file
41
src/modules/sensors/Bme280/items.json
Normal file
@@ -0,0 +1,41 @@
|
||||
[
|
||||
{
|
||||
"name": "Cенсор температуры Bme280",
|
||||
"num": 9,
|
||||
"type": "Reading",
|
||||
"subtype": "Bme280t",
|
||||
"id": "tmp3",
|
||||
"widget": "anydataTmp",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Температура",
|
||||
"int": 15,
|
||||
"addr": "0x77",
|
||||
"round": 1
|
||||
},
|
||||
{
|
||||
"name": "Cенсор давления Bme280",
|
||||
"num": 10,
|
||||
"type": "Reading",
|
||||
"subtype": "Bme280p",
|
||||
"id": "Press3",
|
||||
"widget": "anydataMm",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Давление",
|
||||
"int": 15,
|
||||
"addr": "0x77",
|
||||
"round": 1
|
||||
},
|
||||
{
|
||||
"name": "Cенсор влажности Bme280",
|
||||
"num": 11,
|
||||
"type": "Reading",
|
||||
"subtype": "Bme280h",
|
||||
"id": "Hum3",
|
||||
"widget": "anydataHum",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Влажность",
|
||||
"int": 15,
|
||||
"addr": "0x77",
|
||||
"round": 1
|
||||
}
|
||||
]
|
||||
8
src/modules/sensors/Bme280/platformio.ini
Normal file
8
src/modules/sensors/Bme280/platformio.ini
Normal file
@@ -0,0 +1,8 @@
|
||||
[env:esp8266_4mb]
|
||||
lib_deps =
|
||||
adafruit/Adafruit BME280 Library
|
||||
|
||||
[env:esp32_4mb]
|
||||
lib_deps =
|
||||
adafruit/Adafruit BME280 Library
|
||||
|
||||
Reference in New Issue
Block a user