добавил LCD

This commit is contained in:
Dmitry Borisenko
2021-12-19 22:19:35 +01:00
parent 5b87cedd78
commit b0e06707bd
7 changed files with 44 additions and 9 deletions

View File

@@ -34,4 +34,10 @@
0;uptime;uptid;anydataTime;Системные;%name%#uptime;order;int[60]* 0;uptime;uptid;anydataTime;Системные;%name%#uptime;order;int[60]*
0;sht20;tmpid;anydataTemp;Сенсоры;Температура;1;c[1] 0;sht20;tmpid;anydataTemp;Сенсоры;Температура;1;c[1]
0;sht20;humid;anydataHum;Сенсоры;Влажность;2;c[1];int[50]* 0;sht20;humid;anydataHum;Сенсоры;Влажность;2;c[1];int[50]*
0;sensor;anyid;anydata;Сенсоры;Параметр;1;c[1];int[10];type[type1]* 0;sensor;anyid;anydata;Сенсоры;Параметр;1;c[1];int[10];type[HDC1080_temp];addr[0x76]
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;Сенсоры;Параметр;1;c[1];int[10];type[type1];addr[0x76]*

Binary file not shown.

View File

@@ -3,5 +3,6 @@
#include <Arduino.h> #include <Arduino.h>
float yourSensorReading(String type, String addr); float yourSensorReading(String type, String addr);
void HDC1080_init(String &addr); void HDC1080_init(String addr);
void AHTX0_init(); void AHTX0_init();
void LCD_init();

View File

@@ -20,9 +20,11 @@ class SensorAny {
String _paramsAny; String _paramsAny;
int _interval; int _interval;
float _c; float _c;
float _k;
String _key; String _key;
String _addr; String _addr;
String _type; String _type;
String _val;
unsigned long prevMillis; unsigned long prevMillis;
unsigned long difference; unsigned long difference;

View File

@@ -43,6 +43,7 @@ lib_deps =
robtillaart/SHT2x@^0.1.1 robtillaart/SHT2x@^0.1.1
ClosedCube HDC1080 ClosedCube HDC1080
Adafruit AHTX0 Adafruit AHTX0
LiquidCrystal_I2C
monitor_filters = esp8266_exception_decoder monitor_filters = esp8266_exception_decoder
upload_speed = 921600 upload_speed = 921600
monitor_speed = 115200 monitor_speed = 115200
@@ -69,6 +70,7 @@ lib_deps =
robtillaart/SHT2x@^0.1.1 robtillaart/SHT2x@^0.1.1
ClosedCube HDC1080 ClosedCube HDC1080
Adafruit AHTX0 Adafruit AHTX0
LiquidCrystal_I2C
monitor_filters = esp8266_exception_decoder monitor_filters = esp8266_exception_decoder
upload_speed = 921600 upload_speed = 921600
monitor_speed = 115200 monitor_speed = 115200
@@ -113,6 +115,7 @@ lib_deps =
robtillaart/SHT2x@^0.1.1 robtillaart/SHT2x@^0.1.1
ClosedCube HDC1080 ClosedCube HDC1080
Adafruit AHTX0 Adafruit AHTX0
LiquidCrystal_I2C
monitor_filters = esp32_exception_decoder monitor_filters = esp32_exception_decoder
upload_speed = 921600 upload_speed = 921600
monitor_speed = 115200 monitor_speed = 115200
@@ -132,7 +135,6 @@ lib_deps =
ESP32 AnalogWrite ESP32 AnalogWrite
ESP32Servo ESP32Servo
MySensors @2.3.2 MySensors @2.3.2
robtillaart/SHT2x@^0.1.1
monitor_filters = esp32_exception_decoder monitor_filters = esp32_exception_decoder
upload_speed = 921600 upload_speed = 921600
monitor_speed = 115200 monitor_speed = 115200

View File

@@ -1,9 +1,12 @@
#include "YourSensor.h" #include "YourSensor.h"
#include "Global.h"
#include "Utils/JsonUtils.h"
#include "Utils/StringUtils.h" #include "Utils/StringUtils.h"
//подключаем необходимые файлы библиотеки //подключаем необходимые файлы библиотеки
#include <Adafruit_AHTX0.h> #include <Adafruit_AHTX0.h>
#include <LiquidCrystal_I2C.h>
#include "ClosedCube_HDC1080.h" #include "ClosedCube_HDC1080.h"
@@ -15,14 +18,17 @@ Adafruit_AHTX0 aht;
Adafruit_Sensor *aht_humidity, *aht_temp; Adafruit_Sensor *aht_humidity, *aht_temp;
sensors_event_t tmpEvent_t; sensors_event_t tmpEvent_t;
float yourSensorReading(String type, String addr) { //создаем объект LCD
LiquidCrystal_I2C LCD(0x27, 16, 2);
float yourSensorReading(String type, String paramsAny) {
float value; float value;
//========================================================HDC1080================================================================ //========================================================HDC1080================================================================
if (type == "HDC1080_temp") { if (type == "HDC1080_temp") {
HDC1080_init(addr); HDC1080_init(jsonReadStr(paramsAny, "addr"));
value = hdc1080.readTemperature(); value = hdc1080.readTemperature();
} else if (type == "HDC1080_hum") { } else if (type == "HDC1080_hum") {
HDC1080_init(addr); HDC1080_init(jsonReadStr(paramsAny, "addr"));
value = hdc1080.readHumidity(); value = hdc1080.readHumidity();
} }
//==========================================================AHTX0================================================================= //==========================================================AHTX0=================================================================
@@ -30,15 +36,21 @@ float yourSensorReading(String type, String addr) {
AHTX0_init(); AHTX0_init();
aht_temp->getEvent(&tmpEvent_t); aht_temp->getEvent(&tmpEvent_t);
value = tmpEvent_t.temperature; value = tmpEvent_t.temperature;
} else if (type == "typeAHTX0_hum") { } else if (type == "AHTX0_hum") {
AHTX0_init(); AHTX0_init();
aht_humidity->getEvent(&tmpEvent_t); aht_humidity->getEvent(&tmpEvent_t);
value = tmpEvent_t.relative_humidity; value = tmpEvent_t.relative_humidity;
} }
//==========================================================LCD=================================================================
if (type == "LCD") {
LCD_init();
LCD.setCursor(jsonReadInt(paramsAny, "с"), jsonReadInt(paramsAny, "k"));
LCD.print(jsonReadFloat(configLiveJson, jsonReadStr(paramsAny, "val")));
}
return value; return value;
} }
void HDC1080_init(String &addr) { void HDC1080_init(String addr) {
static bool HDC1080_flag = true; static bool HDC1080_flag = true;
if (HDC1080_flag) { if (HDC1080_flag) {
hdc1080.begin(hexStringToUint8(addr)); hdc1080.begin(hexStringToUint8(addr));
@@ -61,3 +73,11 @@ void AHTX0_init() {
AHTX0_flag = false; AHTX0_flag = false;
} }
} }
void LCD_init() {
static bool LCD_flag = true;
if (LCD_flag) {
LCD.init(); //инициализация дисплея
LCD.backlight(); //включаем подсветку
}
}

View File

@@ -13,9 +13,11 @@ SensorAny::SensorAny(const String& paramsAny) {
_interval = jsonReadInt(_paramsAny, "int"); _interval = jsonReadInt(_paramsAny, "int");
_c = jsonReadFloat(_paramsAny, "c"); _c = jsonReadFloat(_paramsAny, "c");
_k = jsonReadFloat(_paramsAny, "k");
_key = jsonReadStr(_paramsAny, "key"); _key = jsonReadStr(_paramsAny, "key");
_addr = jsonReadStr(_paramsAny, "addr"); _addr = jsonReadStr(_paramsAny, "addr");
_type = jsonReadStr(_paramsAny, "type"); _type = jsonReadStr(_paramsAny, "type");
_val = jsonReadStr(_paramsAny, "val");
} }
SensorAny::~SensorAny() {} SensorAny::~SensorAny() {}
@@ -29,7 +31,7 @@ void SensorAny::loop() {
} }
void SensorAny::read() { void SensorAny::read() {
float value = yourSensorReading(_type, _addr); float value = yourSensorReading(_type, _paramsAny);
value = value * _c; value = value * _c;
@@ -54,6 +56,8 @@ void AnySensor() {
jsonWriteStr(params, "addr", myLineParsing.gaddr()); jsonWriteStr(params, "addr", myLineParsing.gaddr());
jsonWriteStr(params, "int", myLineParsing.gint()); jsonWriteStr(params, "int", myLineParsing.gint());
jsonWriteStr(params, "c", myLineParsing.gc()); jsonWriteStr(params, "c", myLineParsing.gc());
jsonWriteStr(params, "k", myLineParsing.gk());
jsonWriteStr(params, "val", myLineParsing.gval());
jsonWriteStr(params, "type", myLineParsing.gtype()); jsonWriteStr(params, "type", myLineParsing.gtype());
myLineParsing.clear(); myLineParsing.clear();