mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
Уточняем ИД модуля для GY21
This commit is contained in:
59
src/modules/sensors/GY21/GY21.cpp
Normal file
59
src/modules/sensors/GY21/GY21.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
/******************************************************************
|
||||
Used GY21 Driver (temperature and humidity sensor)
|
||||
Support for HTY21 , SHT21 , Si7021
|
||||
https://github.com/adafruit/Adafruit_AHTX0
|
||||
|
||||
adapted for version 4 Alecs Alecs
|
||||
******************************************************************/
|
||||
#include "Global.h"
|
||||
#include "classes/IoTItem.h"
|
||||
|
||||
#include "Wire.h"
|
||||
#include "GY21.h"
|
||||
|
||||
GY21* sensor = nullptr;
|
||||
|
||||
class GY21t : public IoTItem {
|
||||
public:
|
||||
GY21t(String parameters): IoTItem(parameters) { }
|
||||
|
||||
void doByInterval() {
|
||||
//wire->read();
|
||||
value.valD = sensor->GY21_Temperature();
|
||||
if (value.valD < 300) regEvent(value.valD, "GY21"); // TODO: найти способ понимания ошибки получения данных
|
||||
else SerialPrint("E", "Sensor GY21t", "Error");
|
||||
}
|
||||
|
||||
~GY21t() {};
|
||||
};
|
||||
|
||||
class GY21h : public IoTItem {
|
||||
public:
|
||||
GY21h(String parameters): IoTItem(parameters) { }
|
||||
|
||||
void doByInterval() {
|
||||
//sht->read();
|
||||
value.valD = sensor->GY21_Humidity();
|
||||
if (value.valD != 0) regEvent(value.valD, "GY21h"); // TODO: найти способ понимания ошибки получения данных
|
||||
else SerialPrint("E", "Sensor GY21h", "Error");
|
||||
}
|
||||
|
||||
~GY21h() {};
|
||||
};
|
||||
|
||||
void* getAPI_GY21(String subtype, String param) {
|
||||
if (subtype == F("GY21t") || subtype == F("GY21h")) {
|
||||
if (!sensor) {
|
||||
sensor = new GY21;
|
||||
if (sensor) Wire.begin(SDA, SCL);
|
||||
}
|
||||
|
||||
if (subtype == F("GY21t")) {
|
||||
return new GY21t(param);
|
||||
} else if (subtype == F("GY21h")) {
|
||||
return new GY21h(param);
|
||||
}
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
26
src/modules/sensors/GY21/items.json
Normal file
26
src/modules/sensors/GY21/items.json
Normal file
@@ -0,0 +1,26 @@
|
||||
[
|
||||
{
|
||||
"name": "Cенсор температуры GY21",
|
||||
"num": 16,
|
||||
"type": "Reading",
|
||||
"subtype": "GY21t",
|
||||
"id": "tmp4",
|
||||
"widget": "anydataTmp",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Температура",
|
||||
"round": 1,
|
||||
"int": 15
|
||||
},
|
||||
{
|
||||
"name": "Cенсор влажности GY21",
|
||||
"num": 17,
|
||||
"type": "Reading",
|
||||
"subtype": "GY21h",
|
||||
"id": "Hum4",
|
||||
"widget": "anydataHum",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Влажность",
|
||||
"round": 1,
|
||||
"int": 15
|
||||
}
|
||||
]
|
||||
8
src/modules/sensors/GY21/platformio.ini
Normal file
8
src/modules/sensors/GY21/platformio.ini
Normal file
@@ -0,0 +1,8 @@
|
||||
[env:esp8266_4mb]
|
||||
lib_deps =
|
||||
https://github.com/JonasGMorsch/GY-21.git
|
||||
|
||||
[env:esp32_4mb]
|
||||
lib_deps =
|
||||
https://github.com/JonasGMorsch/GY-21.git
|
||||
|
||||
Reference in New Issue
Block a user