Портируем датчик SHT20

This commit is contained in:
2022-02-01 14:48:52 +03:00
parent 3bcdf8d8b5
commit 66d1fffefa
4 changed files with 71 additions and 0 deletions

View File

@@ -23,5 +23,23 @@
"pin": 0,
"index": 0,
"addr": ""
},
{
"type": "Reading",
"subtype": "Sht20t",
"id": "tmp2",
"widget": "anydataTmp",
"page": "Сенсоры",
"descr": "Температура",
"int": 15
},
{
"type": "Reading",
"subtype": "Sht20h",
"id": "Hum2",
"widget": "anydataTmp",
"page": "Сенсоры",
"descr": "Влажность",
"int": 15
}
]

View File

@@ -28,6 +28,7 @@ platform = espressif8266 @2.6.3
lib_deps =
${common_env_data.lib_deps_external}
milesburton/DallasTemperature@^3.9.1
robtillaart/SHT2x@^0.1.1
monitor_filters = esp8266_exception_decoder
upload_speed = 921600
monitor_speed = 115200
@@ -41,6 +42,7 @@ platform = espressif32 @3.3.0
lib_deps =
${common_env_data.lib_deps_external}
milesburton/DallasTemperature@^3.9.1
robtillaart/SHT2x@^0.1.1
monitor_filters = esp32_exception_decoder
upload_speed = 921600
monitor_speed = 115200

View File

@@ -4,6 +4,7 @@
//здесь скопируйте строку и вставьте ниже, заменив имя AnalogAdc на название вашего сенсора
void* getAPI_AnalogAdc(String subtype, String params);
void* getAPI_Ds18b20(String subtype, String params);
void* getAPI_Sht20(String subtype, String params);
//============================================================================================
void* getAPI(String subtype, String params) {
@@ -12,6 +13,7 @@ void* getAPI(String subtype, String params) {
//здесь нужно скопировать строку еще раз и вставить ее ниже, переименовав AnalogAdc на название вашего сенсора
if ((tmpAPI = getAPI_AnalogAdc(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Ds18b20(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Sht20(subtype, params)) != nullptr) return tmpAPI;
//================================================================================================================
return nullptr;

49
src/modules/Sht20.cpp Normal file
View File

@@ -0,0 +1,49 @@
#include "Global.h"
#include "Classes/IoTSensor.h"
#include "Wire.h"
#include "SHT2x.h"
SHT2x* sht = nullptr;
class Sht20t : public IoTSensor {
public:
Sht20t(String parameters): IoTSensor(parameters) { }
void doByInterval() {
sht->read();
float value = sht->getTemperature();
regEvent((String)value, "Sht20t");
}
~Sht20t();
};
class Sht20h : public IoTSensor {
public:
Sht20h(String parameters): IoTSensor(parameters) { }
void doByInterval() {
float value = sht->getHumidity();
regEvent((String)value, "Sht20h");
}
~Sht20h();
};
void* getAPI_Sht20(String subtype, String param) {
if (!sht) {
sht = new SHT2x;
if (sht) sht->begin();
}
if (subtype == F("Sht20t")) {
return new Sht20t(param);
} else if (subtype == F("Sht20h")) {
return new Sht20h(param);
} else {
return nullptr;
}
}