mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
@@ -38,6 +38,5 @@
|
||||
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;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;LCD2004;lcdid;anydata;Вывод;IP;1;addr[0x27];k[16,2];int[10];c[0,0];val[ip]*
|
||||
0;sensor;anyid;anydata;Сенсоры;Параметр;1;c[1];int[10];type[type1];addr[0x76]*
|
||||
Binary file not shown.
@@ -127,6 +127,7 @@ class LineParsing {
|
||||
}
|
||||
|
||||
if (_pin != "") {
|
||||
/*
|
||||
if (_pin.indexOf(",") == -1) {
|
||||
if (!isPinExist(_pin.toInt()) || !isDigitStr(_pin)) {
|
||||
pinErrors++;
|
||||
@@ -139,6 +140,17 @@ class LineParsing {
|
||||
pinErrors++;
|
||||
_pin = "";
|
||||
}
|
||||
}*/
|
||||
|
||||
String tmpstr;
|
||||
for (int i=0; i<15; i++) {
|
||||
tmpstr = selectFromMarkerToMarker(_pin, ",", i);
|
||||
if(tmpstr == "not found") break;
|
||||
if(!isDigitStr(tmpstr) || !isPinExist(tmpstr.toInt())){
|
||||
pinErrors++;
|
||||
_pin = "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
#define NUM_BUTTONS 8
|
||||
#endif
|
||||
|
||||
#define MQTT_RECONNECT_INTERVAL 20000
|
||||
#define MQTT_RECONNECT_INTERVAL 60000
|
||||
#define CHANGE_BROKER_AFTER 5
|
||||
#define TELEMETRY_UPDATE_INTERVAL_MIN 60
|
||||
#define DEVICE_CONFIG_FILE "s.conf.csv"
|
||||
@@ -87,6 +87,7 @@
|
||||
#define EnableSensorAny
|
||||
#define EnableTelegram
|
||||
#define EnableUart
|
||||
#define EnableSensorLCD2004
|
||||
#endif
|
||||
|
||||
#ifdef GATE_MODE
|
||||
|
||||
40
include/items/vSensorLCD2004.h
Normal file
40
include/items/vSensorLCD2004.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifdef EnableSensorLCD2004
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <OneWire.h>
|
||||
#include "Global.h"
|
||||
#include "LiquidCrystal_I2C.h"
|
||||
|
||||
|
||||
class SensorLCD2004;
|
||||
|
||||
typedef std::vector<SensorLCD2004> MySensorLCD2004Vector;
|
||||
|
||||
class SensorLCD2004 {
|
||||
public:
|
||||
SensorLCD2004(String key, unsigned long interval, unsigned int x, unsigned int y, String val, String descr);
|
||||
~SensorLCD2004();
|
||||
|
||||
void loop();
|
||||
void writeLCD2004();
|
||||
void execute(String command);
|
||||
String _key;
|
||||
void printBlankStr(int strSize);
|
||||
|
||||
private:
|
||||
unsigned long currentMillis;
|
||||
unsigned long prevMillis;
|
||||
unsigned long difference;
|
||||
|
||||
unsigned long _interval;
|
||||
unsigned int _x;
|
||||
unsigned int _y;
|
||||
String _val;
|
||||
String _descr;
|
||||
int _prevStrSize;
|
||||
};
|
||||
|
||||
extern MySensorLCD2004Vector* mySensorLCD20042;
|
||||
|
||||
extern void lcd2004();
|
||||
#endif
|
||||
@@ -43,8 +43,8 @@ lib_deps =
|
||||
robtillaart/SHT2x@^0.1.1
|
||||
ClosedCube HDC1080
|
||||
Adafruit AHTX0
|
||||
LiquidCrystal_I2C
|
||||
BH1750
|
||||
marcoschwartz/LiquidCrystal_I2C@^1.1.4
|
||||
monitor_filters = esp8266_exception_decoder
|
||||
upload_speed = 921600
|
||||
monitor_speed = 115200
|
||||
@@ -71,8 +71,8 @@ lib_deps =
|
||||
robtillaart/SHT2x@^0.1.1
|
||||
ClosedCube HDC1080
|
||||
Adafruit AHTX0
|
||||
LiquidCrystal_I2C
|
||||
BH1750
|
||||
marcoschwartz/LiquidCrystal_I2C@^1.1.4
|
||||
monitor_filters = esp8266_exception_decoder
|
||||
upload_speed = 921600
|
||||
monitor_speed = 115200
|
||||
@@ -90,6 +90,7 @@ lib_deps =
|
||||
ESPAsyncUDP
|
||||
CTBot @2.1.6
|
||||
MySensors @2.3.2
|
||||
marcoschwartz/LiquidCrystal_I2C@^1.1.4
|
||||
monitor_filters = esp8266_exception_decoder
|
||||
upload_speed = 921600
|
||||
monitor_speed = 115200
|
||||
@@ -117,8 +118,8 @@ lib_deps =
|
||||
robtillaart/SHT2x@^0.1.1
|
||||
ClosedCube HDC1080
|
||||
Adafruit AHTX0
|
||||
LiquidCrystal_I2C
|
||||
BH1750
|
||||
marcoschwartz/LiquidCrystal_I2C@^1.1.4
|
||||
monitor_filters = esp32_exception_decoder
|
||||
upload_speed = 921600
|
||||
monitor_speed = 115200
|
||||
@@ -138,6 +139,8 @@ lib_deps =
|
||||
ESP32 AnalogWrite
|
||||
ESP32Servo
|
||||
MySensors @2.3.2
|
||||
fmalpartida/LiquidCrystal@^1.5.0
|
||||
marcoschwartz/LiquidCrystal_I2C@^1.1.4
|
||||
monitor_filters = esp32_exception_decoder
|
||||
upload_speed = 921600
|
||||
monitor_speed = 115200
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "items/vSensorBmp280.h"
|
||||
#include "items/vSensorCcs811.h"
|
||||
#include "items/vSensorDallas.h"
|
||||
#include "items/vSensorLCD2004.h"
|
||||
#include "items/vSensorDht.h"
|
||||
#include "items/vSensorNode.h"
|
||||
#include "items/vSensorPzem.h"
|
||||
@@ -105,6 +106,10 @@ void csvCmdExecute(String& cmdStr) {
|
||||
} else if (order == F("dallas-temp")) {
|
||||
#ifdef EnableSensorDallas
|
||||
sCmd.addCommand(order.c_str(), dallas);
|
||||
#endif
|
||||
} else if (order == F("LCD2004")) {
|
||||
#ifdef EnableSensorLCD2004
|
||||
sCmd.addCommand(order.c_str(), lcd2004);
|
||||
#endif
|
||||
} else if (order == F("dht")) {
|
||||
#ifdef EnableSensorDht
|
||||
|
||||
12
src/Init.cpp
12
src/Init.cpp
@@ -16,6 +16,7 @@
|
||||
#include "items/vSensorBmp280.h"
|
||||
#include "items/vSensorCcs811.h"
|
||||
#include "items/vSensorDallas.h"
|
||||
#include "items/vSensorLCD2004.h"
|
||||
#include "items/vSensorDht.h"
|
||||
#include "items/vSensorNode.h"
|
||||
#include "items/vSensorPzem.h"
|
||||
@@ -23,6 +24,10 @@
|
||||
#include "items/vSensorUltrasonic.h"
|
||||
#include "items/vSensorUptime.h"
|
||||
|
||||
#ifdef EnableSensorLCD2004
|
||||
extern LiquidCrystal_I2C *LCDI2C;
|
||||
#endif
|
||||
|
||||
void loadConfig() {
|
||||
configSetupJson = readFile("config.json", 4096);
|
||||
configSetupJson.replace("\r\n", "");
|
||||
@@ -169,6 +174,13 @@ void clearVectors() {
|
||||
mySensorDallas2->clear();
|
||||
}
|
||||
#endif
|
||||
#ifdef EnableSensorLCD2004
|
||||
if (mySensorLCD20042 != nullptr) {
|
||||
if(LCDI2C != nullptr) LCDI2C->clear();
|
||||
mySensorLCD20042->clear();
|
||||
|
||||
}
|
||||
#endif
|
||||
#ifdef EnableSensorUltrasonic
|
||||
if (mySensorUltrasonic != nullptr) {
|
||||
mySensorUltrasonic->clear();
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "Adafruit_AHTX0.h"
|
||||
#include "BH1750.h"
|
||||
#include "ClosedCube_HDC1080.h"
|
||||
#include "LiquidCrystal_I2C.h"
|
||||
//#include "LiquidCrystal_I2C.h"
|
||||
|
||||
//создаем объект HDC1080
|
||||
ClosedCube_HDC1080 hdc1080;
|
||||
@@ -20,7 +20,7 @@ Adafruit_Sensor *aht_humidity, *aht_temp;
|
||||
sensors_event_t tmpEvent_t;
|
||||
|
||||
//создаем объект LCD
|
||||
LiquidCrystal_I2C LCD(0x27, 16, 2);
|
||||
//LiquidCrystal_I2C LCD(0x27, 16, 2);
|
||||
|
||||
//создаем объект BH1750
|
||||
BH1750 lightMeter;
|
||||
@@ -29,7 +29,7 @@ BH1750 lightMeter;
|
||||
// Adafruit_ADS1015 ads;
|
||||
|
||||
// co2 sensor
|
||||
SoftwareSerial K_30_Serial(13, 15); //Программный порт
|
||||
//SoftwareSerial K_30_Serial(13, 15); //Программный порт
|
||||
byte readCO2[] = {0xFE, 0X44, 0X00, 0X08, 0X02, 0X9F, 0X25}; //Команды для запроса показаний с датчика
|
||||
byte response[] = {0, 0, 0, 0, 0, 0, 0}; //массив для ответа от датчика
|
||||
unsigned long getValue(byte packet[]) {
|
||||
@@ -39,10 +39,10 @@ unsigned long getValue(byte packet[]) {
|
||||
return val_1;
|
||||
}
|
||||
void sendRequest(byte packet[]) {
|
||||
while (!K_30_Serial.available()) {
|
||||
K_30_Serial.write(readCO2, 7);
|
||||
delay(50);
|
||||
}
|
||||
//while (!K_30_Serial.available()) {
|
||||
// K_30_Serial.write(readCO2, 7);
|
||||
// delay(50);
|
||||
//}
|
||||
}
|
||||
|
||||
float yourSensorReading(String type, String paramsAny) {
|
||||
@@ -68,12 +68,12 @@ float yourSensorReading(String type, String paramsAny) {
|
||||
value = tmpEvent_t.relative_humidity;
|
||||
}
|
||||
//==========================================================LCD=================================================================
|
||||
if (type == "LCD") {
|
||||
LCD_init();
|
||||
LCD.setCursor(jsonReadInt(paramsAny, "c"), jsonReadInt(paramsAny, "k"));
|
||||
String toPrint = jsonReadStr(paramsAny, "descr") + " " + jsonReadStr(configLiveJson, jsonReadStr(paramsAny, "val"));
|
||||
LCD.print(toPrint);
|
||||
}
|
||||
//if (type == "LCD") {
|
||||
//LCD_init();
|
||||
// LCD.setCursor(jsonReadInt(paramsAny, "c"), jsonReadInt(paramsAny, "k"));
|
||||
// String toPrint = jsonReadStr(paramsAny, "descr") + " " + jsonReadStr(configLiveJson, jsonReadStr(paramsAny, "val"));
|
||||
// LCD.print(toPrint);
|
||||
//}
|
||||
//==========================================================BH1750=================================================================
|
||||
if (type == "BH1750_lux") {
|
||||
BH1750_init();
|
||||
@@ -81,10 +81,10 @@ float yourSensorReading(String type, String paramsAny) {
|
||||
}
|
||||
//==========================================================co2=================================================================
|
||||
if (type == "valCO2") {
|
||||
K_30_Serial.begin(9600);
|
||||
sendRequest(readCO2);
|
||||
int valCO2 = getValue(response);
|
||||
value = valCO2;
|
||||
//K_30_Serial.begin(9600);
|
||||
//sendRequest(readCO2);
|
||||
//int valCO2 = getValue(response);
|
||||
//value = valCO2;
|
||||
// Serial.println(valCO2);
|
||||
}
|
||||
//==========================================================timer=================================================================
|
||||
@@ -119,14 +119,14 @@ void AHTX0_init() {
|
||||
}
|
||||
}
|
||||
|
||||
void LCD_init() {
|
||||
static bool LCD_flag = true;
|
||||
if (LCD_flag) {
|
||||
LCD.init(); //инициализация дисплея
|
||||
LCD.backlight(); //включаем подсветку
|
||||
}
|
||||
LCD_flag = false;
|
||||
}
|
||||
//void LCD_init() {
|
||||
//static bool LCD_flag = true;
|
||||
//if (LCD_flag) {
|
||||
//LCD.init(); //инициализация дисплея
|
||||
//LCD.backlight(); //включаем подсветку
|
||||
//}
|
||||
//LCD_flag = false;
|
||||
//}
|
||||
|
||||
void BH1750_init() {
|
||||
static bool BH1750_flag = true;
|
||||
|
||||
128
src/items/vSensorLCD2004.cpp
Normal file
128
src/items/vSensorLCD2004.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
#include "Consts.h"
|
||||
#ifdef EnableSensorLCD2004
|
||||
#include "items/vSensorLCD2004.h"
|
||||
#include "BufferExecute.h"
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "Utils/StringUtils.h"
|
||||
#include <map>
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
LiquidCrystal_I2C *LCDI2C;
|
||||
|
||||
SensorLCD2004::SensorLCD2004(String key, unsigned long interval, unsigned int x, unsigned int y, String val, String descr) {
|
||||
_key = key;
|
||||
_interval = interval * 1000;
|
||||
_x = x;
|
||||
_y = y;
|
||||
_val = val;
|
||||
_descr = descr;
|
||||
_prevStrSize = 0;
|
||||
}
|
||||
|
||||
SensorLCD2004::~SensorLCD2004() {}
|
||||
|
||||
//печать пустой строки нужной длинны для затирания предыдущего значения на экране
|
||||
void SensorLCD2004::printBlankStr(int strSize){
|
||||
String tmpStr = "";
|
||||
for(int i=0; i<strSize; i++) tmpStr += " ";
|
||||
LCDI2C->setCursor(_x, _y);
|
||||
LCDI2C->print(tmpStr);
|
||||
}
|
||||
|
||||
void SensorLCD2004::execute(String command) {
|
||||
if (command == "noBacklight") LCDI2C->noBacklight();
|
||||
else if (command == "backlight") LCDI2C->backlight();
|
||||
else if (command == "noDisplay") LCDI2C->noDisplay();
|
||||
else if (command == "display") LCDI2C->display();
|
||||
else if (command == "x") {
|
||||
printBlankStr(_prevStrSize);
|
||||
String par = sCmd.next();
|
||||
_x = par.toInt();
|
||||
}
|
||||
else if (command == "y") {
|
||||
printBlankStr(_prevStrSize);
|
||||
String par = sCmd.next();
|
||||
_y = par.toInt();
|
||||
}
|
||||
else if (command == "descr") {
|
||||
printBlankStr(_prevStrSize);
|
||||
String par = sCmd.next();
|
||||
_descr = par;
|
||||
}
|
||||
else { //не команда, значит данные
|
||||
_val = command;
|
||||
}
|
||||
|
||||
writeLCD2004();
|
||||
}
|
||||
|
||||
void SensorLCD2004::loop() {
|
||||
currentMillis = millis();
|
||||
difference = currentMillis - prevMillis;
|
||||
if (difference >= _interval) {
|
||||
prevMillis = millis();
|
||||
writeLCD2004();
|
||||
}
|
||||
}
|
||||
|
||||
void SensorLCD2004::writeLCD2004() {
|
||||
if (LCDI2C != nullptr) {
|
||||
printBlankStr(_prevStrSize);
|
||||
|
||||
String tmpStr = getValue(_val);
|
||||
if (tmpStr == "no value") tmpStr = _val;
|
||||
if (_descr != "none") tmpStr = _descr + " " + tmpStr;
|
||||
LCDI2C->setCursor(_x, _y);
|
||||
LCDI2C->print(tmpStr);
|
||||
|
||||
_prevStrSize = tmpStr.length();
|
||||
}
|
||||
}
|
||||
|
||||
MySensorLCD2004Vector* mySensorLCD20042 = nullptr;
|
||||
|
||||
void lcd2004Execute() {
|
||||
String key = sCmd.order();
|
||||
String command = sCmd.next();
|
||||
|
||||
for (unsigned int i = 0; i < mySensorLCD20042->size(); i++) {
|
||||
if (mySensorLCD20042->at(i)._key == key) mySensorLCD20042->at(i).execute(command);
|
||||
}
|
||||
}
|
||||
|
||||
void lcd2004() {
|
||||
myLineParsing.update();
|
||||
String key = myLineParsing.gkey();
|
||||
String addr = myLineParsing.gaddr();
|
||||
String interval = myLineParsing.gint();
|
||||
String c = myLineParsing.gc();
|
||||
String k = myLineParsing.gk();
|
||||
String val = myLineParsing.gval();
|
||||
String descr = myLineParsing.gdescr();
|
||||
myLineParsing.clear();
|
||||
|
||||
int x = selectFromMarkerToMarker(c, ",", 0).toInt();
|
||||
int y = selectFromMarkerToMarker(c, ",", 1).toInt();
|
||||
int w = selectFromMarkerToMarker(k, ",", 0).toInt(); //количество столбцов
|
||||
int h = selectFromMarkerToMarker(k, ",", 1).toInt(); //количество строк
|
||||
|
||||
if (LCDI2C == nullptr) { //инициализации экрана еще не было
|
||||
LCDI2C = new LiquidCrystal_I2C(hexStringToUint8(addr), w, h);//hexStringToUint8(addr), w, h);
|
||||
if(LCDI2C != nullptr) {
|
||||
LCDI2C->init();
|
||||
LCDI2C->backlight();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) mySensorLCD20042 = new MySensorLCD2004Vector();
|
||||
firstTime = false;
|
||||
mySensorLCD20042->push_back(SensorLCD2004(key, interval.toInt(), x, y, val, descr));
|
||||
|
||||
sCmd.addCommand(key.c_str(), lcd2004Execute);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "items/vSensorBmp280.h"
|
||||
#include "items/vSensorCcs811.h"
|
||||
#include "items/vSensorDallas.h"
|
||||
#include "items/vSensorLCD2004.h"
|
||||
#include "items/vSensorDht.h"
|
||||
#include "items/vSensorNode.h"
|
||||
#include "items/vSensorPzem.h"
|
||||
@@ -153,6 +154,13 @@ void loop() {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef EnableSensorLCD2004
|
||||
if (mySensorLCD20042 != nullptr) {
|
||||
for (unsigned int i = 0; i < mySensorLCD20042->size(); i++) {
|
||||
mySensorLCD20042->at(i).loop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef EnableSensorUltrasonic
|
||||
if (mySensorUltrasonic != nullptr) {
|
||||
for (unsigned int i = 0; i < mySensorUltrasonic->size(); i++) {
|
||||
|
||||
Reference in New Issue
Block a user