diff --git a/include/YourSensor.h b/include/YourSensor.h index 8549f9fb..a793b19c 100644 --- a/include/YourSensor.h +++ b/include/YourSensor.h @@ -1,4 +1,7 @@ #pragma once #include -float yourSensorReading(String type); +float yourSensorReading(String type, String addr); + +void HDC1080_init(String &addr); +void AHTX0_init(); diff --git a/platformio.ini b/platformio.ini index 01c01df3..9d0b04f9 100644 --- a/platformio.ini +++ b/platformio.ini @@ -41,6 +41,8 @@ lib_deps = adafruit/Adafruit CCS811 Library milesburton/DallasTemperature robtillaart/SHT2x@^0.1.1 + ClosedCube HDC1080 + Adafruit AHTX0 monitor_filters = esp8266_exception_decoder upload_speed = 921600 monitor_speed = 115200 @@ -65,6 +67,8 @@ lib_deps = adafruit/Adafruit CCS811 Library milesburton/DallasTemperature robtillaart/SHT2x@^0.1.1 + ClosedCube HDC1080 + Adafruit AHTX0 monitor_filters = esp8266_exception_decoder upload_speed = 921600 monitor_speed = 115200 @@ -82,7 +86,6 @@ lib_deps = ESPAsyncUDP CTBot @2.1.6 MySensors @2.3.2 - robtillaart/SHT2x@^0.1.1 monitor_filters = esp8266_exception_decoder upload_speed = 921600 monitor_speed = 115200 @@ -108,6 +111,8 @@ lib_deps = adafruit/Adafruit CCS811 Library milesburton/DallasTemperature robtillaart/SHT2x@^0.1.1 + ClosedCube HDC1080 + Adafruit AHTX0 monitor_filters = esp32_exception_decoder upload_speed = 921600 monitor_speed = 115200 diff --git a/src/YourSensor.cpp b/src/YourSensor.cpp index a3ba9895..d3099973 100644 --- a/src/YourSensor.cpp +++ b/src/YourSensor.cpp @@ -1,23 +1,63 @@ #include "YourSensor.h" -float yourSensorReading(String type) { +#include "Utils/StringUtils.h" + +//подключаем необходимые файлы библиотеки +#include + +#include "ClosedCube_HDC1080.h" + +//создаем объект HDC1080 +ClosedCube_HDC1080 hdc1080; + +//создаем объект AHTX0 +Adafruit_AHTX0 aht; +Adafruit_Sensor *aht_humidity, *aht_temp; +sensors_event_t tmpEvent_t; + +float yourSensorReading(String type, String addr) { float value; - if (type == "type1") { // type1 - замените на название вашего датчика, потом это же название указывайте в type[], в вебе - //сюда вставляем процедуру чтения одного датчика - static int a; - a++; - value = a; - } else if (type == "type2") { - //сюда вставляем процедуру чтения другого датчика - static int b; - b--; - value = b; - } else if (type == "type3") { - //сюда третьего и так далее, создавайте сколько угодно else if.... - //если у одного датчика несколько параметров то под каждый из них делайте свой else if и свое имя type - static int c; - c++; - value = c * 10; + //========================================================HDC1080================================================================ + if (type == "HDC1080_temp") { + HDC1080_init(addr); + value = hdc1080.readTemperature(); + } else if (type == "HDC1080_hum") { + HDC1080_init(addr); + value = hdc1080.readHumidity(); + } + //==========================================================AHTX0================================================================= + if (type == "AHTX0_temp") { + AHTX0_init(); + aht_temp->getEvent(&tmpEvent_t); + value = tmpEvent_t.temperature; + } else if (type == "typeAHTX0_hum") { + AHTX0_init(); + aht_humidity->getEvent(&tmpEvent_t); + value = tmpEvent_t.relative_humidity; } return value; } + +void HDC1080_init(String &addr) { + static bool HDC1080_flag = true; + if (HDC1080_flag) { + hdc1080.begin(hexStringToUint8(addr)); + HDC1080_flag = false; + } +} + +void AHTX0_init() { + static bool AHTX0_flag = true; + if (AHTX0_flag) { + if (!aht.begin()) { + Serial.println("Failed to find AHT10/AHT20 chip"); + // return -127; + } + aht_temp = aht.getTemperatureSensor(); + aht_temp->printSensorDetails(); + + aht_humidity = aht.getHumiditySensor(); + aht_humidity->printSensorDetails(); + AHTX0_flag = false; + } +} diff --git a/src/items/vSensorAny.cpp b/src/items/vSensorAny.cpp index 12917194..2dfbe267 100644 --- a/src/items/vSensorAny.cpp +++ b/src/items/vSensorAny.cpp @@ -29,7 +29,7 @@ void SensorAny::loop() { } void SensorAny::read() { - float value = yourSensorReading(_type); + float value = yourSensorReading(_type, _addr); value = value * _c;