From fd09ec9d6be564ee52d8a50dfaaa9d242f4e12ec Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Sun, 19 Dec 2021 22:36:52 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BF?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_esp/items/items.txt | 4 ++-- include/items/vSensorAny.h | 1 + src/YourSensor.cpp | 3 ++- src/items/vSensorAny.cpp | 2 ++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/data_esp/items/items.txt b/data_esp/items/items.txt index e5b8e2ac..5e43e747 100644 --- a/data_esp/items/items.txt +++ b/data_esp/items/items.txt @@ -38,6 +38,6 @@ 0;sensor;anyid;anydata;Сенсоры;Параметр;1;c[1];int[10];type[HDC1080_hum];addr[0x76]* 0;sensor;anyid;anydata;Сенсоры;Параметр;1;c[1];int[10];type[AHTX0_temp];addr[0x76] 0;sensor;anyid;anydata;Сенсоры;Параметр;1;c[1];int[10];type[AHTX0_hum];addr[0x76]* -0;sensor;anyid;anydata;Сенсоры;Параметр;1;c[0];k[0];int[10];type[LCD];val[any] -0;sensor;anyid;anydata;Сенсоры;Параметр;1;c[8];k[1];int[10];type[LCD];val[any]* +0;sensor;anyid;anydata;Page;Tmp;1;c[0];k[0];int[10];type[LCD];val[any] +0;sensor;anyid;anydata;Page;Hum;1;c[8];k[1];int[10];type[LCD];val[any]* 0;sensor;anyid;anydata;Сенсоры;Параметр;1;c[1];int[10];type[type1];addr[0x76]* \ No newline at end of file diff --git a/include/items/vSensorAny.h b/include/items/vSensorAny.h index 6155c4a2..4083a875 100644 --- a/include/items/vSensorAny.h +++ b/include/items/vSensorAny.h @@ -25,6 +25,7 @@ class SensorAny { String _addr; String _type; String _val; + String _descr; unsigned long prevMillis; unsigned long difference; diff --git a/src/YourSensor.cpp b/src/YourSensor.cpp index 4295b33e..86ab858e 100644 --- a/src/YourSensor.cpp +++ b/src/YourSensor.cpp @@ -45,7 +45,8 @@ float yourSensorReading(String type, String paramsAny) { if (type == "LCD") { LCD_init(); LCD.setCursor(jsonReadInt(paramsAny, "с"), jsonReadInt(paramsAny, "k")); - LCD.print(jsonReadFloat(configLiveJson, jsonReadStr(paramsAny, "val"))); + String toPrint = jsonReadStr(paramsAny, "descr") + " " + jsonReadStr(configLiveJson, jsonReadStr(paramsAny, "val")); + LCD.print(toPrint); } return value; } diff --git a/src/items/vSensorAny.cpp b/src/items/vSensorAny.cpp index 621535bd..0f4bbc5f 100644 --- a/src/items/vSensorAny.cpp +++ b/src/items/vSensorAny.cpp @@ -18,6 +18,7 @@ SensorAny::SensorAny(const String& paramsAny) { _addr = jsonReadStr(_paramsAny, "addr"); _type = jsonReadStr(_paramsAny, "type"); _val = jsonReadStr(_paramsAny, "val"); + _descr = jsonReadStr(_paramsAny, "descr"); } SensorAny::~SensorAny() {} @@ -59,6 +60,7 @@ void AnySensor() { jsonWriteStr(params, "k", myLineParsing.gk()); jsonWriteStr(params, "val", myLineParsing.gval()); jsonWriteStr(params, "type", myLineParsing.gtype()); + jsonWriteStr(params, "descr", myLineParsing.gdescr()); myLineParsing.clear(); static bool firstTime = true; From e9032365b474b20e954734283d1a353dcab77227 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Sun, 19 Dec 2021 22:52:26 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=20BH1750?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/YourSensor.h | 1 + platformio.ini | 3 +++ src/YourSensor.cpp | 34 +++++++++++++++++++++++++++++----- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/include/YourSensor.h b/include/YourSensor.h index c70b0bba..9c3b72c8 100644 --- a/include/YourSensor.h +++ b/include/YourSensor.h @@ -6,3 +6,4 @@ float yourSensorReading(String type, String addr); void HDC1080_init(String addr); void AHTX0_init(); void LCD_init(); +void BH1750_init(); diff --git a/platformio.ini b/platformio.ini index a11f6404..c7c184f2 100644 --- a/platformio.ini +++ b/platformio.ini @@ -44,6 +44,7 @@ lib_deps = ClosedCube HDC1080 Adafruit AHTX0 LiquidCrystal_I2C + BH1750 monitor_filters = esp8266_exception_decoder upload_speed = 921600 monitor_speed = 115200 @@ -71,6 +72,7 @@ lib_deps = ClosedCube HDC1080 Adafruit AHTX0 LiquidCrystal_I2C + BH1750 monitor_filters = esp8266_exception_decoder upload_speed = 921600 monitor_speed = 115200 @@ -116,6 +118,7 @@ lib_deps = ClosedCube HDC1080 Adafruit AHTX0 LiquidCrystal_I2C + BH1750 monitor_filters = esp32_exception_decoder upload_speed = 921600 monitor_speed = 115200 diff --git a/src/YourSensor.cpp b/src/YourSensor.cpp index 86ab858e..ef4ce987 100644 --- a/src/YourSensor.cpp +++ b/src/YourSensor.cpp @@ -5,10 +5,11 @@ #include "Utils/StringUtils.h" //подключаем необходимые файлы библиотеки -#include -#include - +//#include "Adafruit_ADS1X15.h" +#include "Adafruit_AHTX0.h" +#include "BH1750.h" #include "ClosedCube_HDC1080.h" +#include "LiquidCrystal_I2C.h" //создаем объект HDC1080 ClosedCube_HDC1080 hdc1080; @@ -21,13 +22,20 @@ sensors_event_t tmpEvent_t; //создаем объект LCD LiquidCrystal_I2C LCD(0x27, 16, 2); +//создаем объект BH1750 +BH1750 lightMeter; + +//создаем объект ADS1015 +//Adafruit_ADS1015 ads; + float yourSensorReading(String type, String paramsAny) { float value; //========================================================HDC1080================================================================ if (type == "HDC1080_temp") { HDC1080_init(jsonReadStr(paramsAny, "addr")); value = hdc1080.readTemperature(); - } else if (type == "HDC1080_hum") { + } + if (type == "HDC1080_hum") { HDC1080_init(jsonReadStr(paramsAny, "addr")); value = hdc1080.readHumidity(); } @@ -36,7 +44,8 @@ float yourSensorReading(String type, String paramsAny) { AHTX0_init(); aht_temp->getEvent(&tmpEvent_t); value = tmpEvent_t.temperature; - } else if (type == "AHTX0_hum") { + } + if (type == "AHTX0_hum") { AHTX0_init(); aht_humidity->getEvent(&tmpEvent_t); value = tmpEvent_t.relative_humidity; @@ -48,6 +57,12 @@ float yourSensorReading(String type, String paramsAny) { String toPrint = jsonReadStr(paramsAny, "descr") + " " + jsonReadStr(configLiveJson, jsonReadStr(paramsAny, "val")); LCD.print(toPrint); } + //==========================================================BH1750================================================================= + if (type == "BH1750_lux") { + BH1750_init(); + value = lightMeter.readLightLevel(); + } + return value; } @@ -82,3 +97,12 @@ void LCD_init() { LCD.backlight(); //включаем подсветку } } + +void BH1750_init() { + static bool BH1750_flag = true; + if (BH1750_flag) { + lightMeter.begin(); + + BH1750_flag = false; + } +} \ No newline at end of file