diff --git a/data_svelte/config.json b/data_svelte/config.json index 2afecbd8..1cd18a06 100644 --- a/data_svelte/config.json +++ b/data_svelte/config.json @@ -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 } ] \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index c0e5c915..265aef96 100644 --- a/platformio.ini +++ b/platformio.ini @@ -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 diff --git a/src/modules/API.cpp b/src/modules/API.cpp index 37ef8ec3..2c22c4be 100644 --- a/src/modules/API.cpp +++ b/src/modules/API.cpp @@ -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; diff --git a/src/modules/Sht20.cpp b/src/modules/Sht20.cpp new file mode 100644 index 00000000..23f69508 --- /dev/null +++ b/src/modules/Sht20.cpp @@ -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; + } +}