mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
Скопом добавляем несколько сенсоров
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
"widget": "anydataTmp",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Температура",
|
||||
"map": "1,1024,1,1024",
|
||||
"map": "1,1024,1,100",
|
||||
"plus": 0,
|
||||
"multiply": 1,
|
||||
"round": 1,
|
||||
@@ -27,14 +27,15 @@
|
||||
"num": 2,
|
||||
"type": "Reading",
|
||||
"subtype": "Ds18b20",
|
||||
"id": "tmp",
|
||||
"id": "dstmp",
|
||||
"widget": "anydataTmp",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Температура",
|
||||
"descr": "DS Температура",
|
||||
"int": 15,
|
||||
"pin": 0,
|
||||
"pin": 2,
|
||||
"index": 0,
|
||||
"addr": ""
|
||||
"addr": "",
|
||||
"round": 1
|
||||
},
|
||||
{
|
||||
"name": "3. Cенсор температуры Sht20",
|
||||
@@ -45,7 +46,8 @@
|
||||
"widget": "anydataTmp",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Температура",
|
||||
"int": 15
|
||||
"int": 15,
|
||||
"round": 1
|
||||
},
|
||||
{
|
||||
"name": "4. Cенсор влажности Sht20",
|
||||
@@ -56,7 +58,8 @@
|
||||
"widget": "anydataHum",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Влажность",
|
||||
"int": 15
|
||||
"int": 15,
|
||||
"round": 1
|
||||
},
|
||||
{
|
||||
"name": "5. Cенсор температуры dht11",
|
||||
@@ -92,9 +95,10 @@
|
||||
"id": "tmp3",
|
||||
"widget": "anydataTmp",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Температура",
|
||||
"descr": "280 Температура",
|
||||
"int": 15,
|
||||
"addr": "0x76"
|
||||
"addr": "0x77",
|
||||
"round": 1
|
||||
},
|
||||
{
|
||||
"name": "8. Cенсор давления Bmp280",
|
||||
@@ -104,9 +108,10 @@
|
||||
"id": "Press3",
|
||||
"widget": "anydataMm",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Давление",
|
||||
"descr": "280 Давление",
|
||||
"int": 15,
|
||||
"addr": "0x76"
|
||||
"addr": "0x77",
|
||||
"round": 1
|
||||
},
|
||||
{
|
||||
"name": "9. Cенсор температуры Bme280",
|
||||
@@ -118,7 +123,8 @@
|
||||
"page": "Сенсоры",
|
||||
"descr": "Температура",
|
||||
"int": 15,
|
||||
"addr": "0x76"
|
||||
"addr": "0x77",
|
||||
"round": 1
|
||||
},
|
||||
{
|
||||
"name": "10. Cенсор давления Bme280",
|
||||
@@ -130,7 +136,8 @@
|
||||
"page": "Сенсоры",
|
||||
"descr": "Давление",
|
||||
"int": 15,
|
||||
"addr": "0x76"
|
||||
"addr": "0x77",
|
||||
"round": 1
|
||||
},
|
||||
{
|
||||
"name": "11. Cенсор влажности Bme280",
|
||||
@@ -142,6 +149,125 @@
|
||||
"page": "Сенсоры",
|
||||
"descr": "Влажность",
|
||||
"int": 15,
|
||||
"addr": "0x76"
|
||||
"addr": "0x77",
|
||||
"round": 1
|
||||
},
|
||||
{
|
||||
"name": "12. Cенсор температуры AHT20",
|
||||
"num": 12,
|
||||
"type": "Reading",
|
||||
"subtype": "Aht20t",
|
||||
"id": "Temp20",
|
||||
"widget": "anydataTmp",
|
||||
"page": "Сенсоры",
|
||||
"descr": "AHT20 Температура",
|
||||
"int": 15,
|
||||
"addr": "0x38",
|
||||
"plus": 0,
|
||||
"multiply": 1,
|
||||
"round": 1
|
||||
},
|
||||
{
|
||||
"name": "13. Cенсор влажности AHT20",
|
||||
"num": 13,
|
||||
"type": "Reading",
|
||||
"subtype": "Aht20h",
|
||||
"id": "Hum20",
|
||||
"widget": "anydataHum",
|
||||
"page": "Сенсоры",
|
||||
"descr": "AHT20 Влажность",
|
||||
"int": 15,
|
||||
"addr": "0x38",
|
||||
"plus": 0,
|
||||
"multiply": 1,
|
||||
"round": 1
|
||||
},
|
||||
{
|
||||
"name": "14. Cенсор температуры HDC1080",
|
||||
"num": 14,
|
||||
"type": "Reading",
|
||||
"subtype": "Hdc1080t",
|
||||
"id": "Temp1080",
|
||||
"widget": "anydataTmp",
|
||||
"page": "Сенсоры",
|
||||
"descr": "1080 Температура",
|
||||
"int": 15,
|
||||
"addr": "0x40",
|
||||
"plus": 0,
|
||||
"multiply": 1,
|
||||
"round": 1
|
||||
},
|
||||
{
|
||||
"name": "15. Cенсор влажности HDC1080",
|
||||
"num": 15,
|
||||
"type": "Reading",
|
||||
"subtype": "Hdc1080h",
|
||||
"id": "Hum1080",
|
||||
"widget": "anydataHum",
|
||||
"page": "Сенсоры",
|
||||
"descr": "1080 Влажность",
|
||||
"int": 15,
|
||||
"addr": "0x40",
|
||||
"plus": 0,
|
||||
"multiply": 1,
|
||||
"round": 1
|
||||
},
|
||||
{
|
||||
"name": "16. Cенсор температуры GY21",
|
||||
"num": 16,
|
||||
"type": "Reading",
|
||||
"subtype": "GY21t",
|
||||
"id": "tmp4",
|
||||
"widget": "anydataTmp",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Температура",
|
||||
"plus": 0,
|
||||
"multiply": 1,
|
||||
"round": 1,
|
||||
"int": 1
|
||||
},
|
||||
{
|
||||
"name": "17. Cенсор влажности GY21",
|
||||
"num": 17,
|
||||
"type": "Reading",
|
||||
"subtype": "GY21h",
|
||||
"id": "Hum4",
|
||||
"widget": "anydataHum",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Влажность",
|
||||
"plus": 0,
|
||||
"multiply": 1,
|
||||
"round": 1,
|
||||
"int": 1
|
||||
},
|
||||
{
|
||||
"name": "18. LCD экран 2004",
|
||||
"num": 18,
|
||||
"type": "Reading",
|
||||
"subtype": "Lcd2004",
|
||||
"id": "Lcd",
|
||||
"widget": "",
|
||||
"page": "",
|
||||
"descr": "T",
|
||||
"int": 15,
|
||||
"addr": "0x27",
|
||||
"size": "20,4",
|
||||
"coord": "0,0",
|
||||
"id2show": "id датчика"
|
||||
},
|
||||
{
|
||||
"name": "19. LCD экран 1602",
|
||||
"num": 19,
|
||||
"type": "Reading",
|
||||
"subtype": "Lcd2004",
|
||||
"id": "Lcd",
|
||||
"widget": "",
|
||||
"page": "",
|
||||
"descr": "T",
|
||||
"int": 15,
|
||||
"addr": "0x27",
|
||||
"size": "16,2",
|
||||
"coord": "0,0",
|
||||
"id2show": "id датчика"
|
||||
}
|
||||
]
|
||||
@@ -31,7 +31,11 @@ lib_deps =
|
||||
beegee-tokyo/DHT sensor library for ESPx
|
||||
adafruit/Adafruit BMP280 Library
|
||||
adafruit/Adafruit BME280 Library
|
||||
Adafruit AHTX0
|
||||
marcoschwartz/LiquidCrystal_I2C@^1.1.4
|
||||
me-no-dev/ESPAsyncUDP ;для esp32 данная библиотека встроена в ядро
|
||||
ClosedCube HDC1080
|
||||
https://github.com/JonasGMorsch/GY-21.git
|
||||
monitor_filters = esp8266_exception_decoder
|
||||
upload_speed = 921600
|
||||
monitor_speed = 115200
|
||||
@@ -49,6 +53,10 @@ lib_deps =
|
||||
beegee-tokyo/DHT sensor library for ESPx
|
||||
adafruit/Adafruit BMP280 Library
|
||||
adafruit/Adafruit BME280 Library
|
||||
Adafruit AHTX0
|
||||
marcoschwartz/LiquidCrystal_I2C@^1.1.4
|
||||
ClosedCube HDC1080
|
||||
https://github.com/JonasGMorsch/GY-21.git
|
||||
monitor_filters = esp32_exception_decoder
|
||||
upload_speed = 921600
|
||||
monitor_speed = 115200
|
||||
|
||||
@@ -249,7 +249,7 @@ public:
|
||||
IoTValue* exec() {
|
||||
Serial.printf("Call from BracketsExprAST OperCount = %d \n", BracketsList.size());
|
||||
|
||||
IoTValue* lastExecValue;
|
||||
IoTValue* lastExecValue = nullptr;
|
||||
for (unsigned int i = 0; i < BracketsList.size(); i++) {
|
||||
lastExecValue = BracketsList[i]->exec();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,10 @@ void* getAPI_Sht20(String subtype, String params);
|
||||
void* getAPI_Dht1122(String subtype, String params);
|
||||
void* getAPI_Bmp280(String subtype, String params);
|
||||
void* getAPI_Bme280(String subtype, String params);
|
||||
void* getAPI_Aht20(String subtype, String params);
|
||||
void* getAPI_Hdc1080(String subtype, String params);
|
||||
void* getAPI_GY21(String subtype, String params);
|
||||
void* getAPI_Lcd2004(String subtype, String params);
|
||||
//============================================================================================
|
||||
|
||||
void* getAPI(String subtype, String params) {
|
||||
@@ -20,6 +24,10 @@ void* getAPI(String subtype, String params) {
|
||||
if ((tmpAPI = getAPI_Dht1122(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Bmp280(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Bme280(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Aht20(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Hdc1080(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_GY21(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI;
|
||||
//================================================================================================================
|
||||
|
||||
return nullptr;
|
||||
|
||||
60
src/modules/Aht20.cpp
Normal file
60
src/modules/Aht20.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
/******************************************************************
|
||||
Used Adafruit AHT20 Driver (temperature and humidity sensor)
|
||||
Support for AHT20
|
||||
https://github.com/adafruit/Adafruit_AHTX0
|
||||
|
||||
adapted for version 4 @Serghei63
|
||||
******************************************************************/
|
||||
|
||||
|
||||
#include "Global.h"
|
||||
#include "Classes/IoTItem.h"
|
||||
|
||||
#include "Adafruit_AHTX0.h"
|
||||
#include <map>
|
||||
|
||||
Adafruit_AHTX0 aht;
|
||||
sensors_event_t temp, humidity;
|
||||
|
||||
class Aht20t : public IoTItem {
|
||||
public:
|
||||
Aht20t(String parameters): IoTItem(parameters) { }
|
||||
|
||||
void doByInterval() {
|
||||
value.valD = temp.temperature;
|
||||
if (String(value.valD) != "nan") regEvent(value.valD, "Aht20t");
|
||||
else SerialPrint("E", "Sensor AHTt", "Error");
|
||||
}
|
||||
|
||||
~Aht20t();
|
||||
};
|
||||
|
||||
|
||||
class Aht20h : public IoTItem {
|
||||
public:
|
||||
Aht20h(String parameters): IoTItem(parameters) { }
|
||||
|
||||
void doByInterval() {
|
||||
value.valD = humidity.relative_humidity;
|
||||
if (String(value.valD) != "nan") regEvent(value.valD, "Aht20t");
|
||||
else SerialPrint("E", "Sensor AHTt", "Error");
|
||||
}
|
||||
|
||||
~Aht20h();
|
||||
};
|
||||
|
||||
|
||||
void* getAPI_Aht20(String subtype, String param) {
|
||||
if (subtype == F("Aht20t")) {
|
||||
aht.begin();
|
||||
aht.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
|
||||
return new Aht20t(param);
|
||||
} else if (subtype == F("Aht20h")) {
|
||||
aht.begin();
|
||||
aht.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
|
||||
return new Aht20h(param);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
57
src/modules/GY-21.cpp
Normal file
57
src/modules/GY-21.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
/******************************************************************
|
||||
Used GY21 Driver (temperature and humidity sensor)
|
||||
Support for HTY21 , SHT21 , Si7021
|
||||
https://github.com/adafruit/Adafruit_AHTX0
|
||||
|
||||
adapted for version 4 Alecs Alecs
|
||||
******************************************************************/
|
||||
#include "Global.h"
|
||||
#include "Classes/IoTItem.h"
|
||||
|
||||
#include "Wire.h"
|
||||
#include "GY21.h"
|
||||
|
||||
GY21* sensor = nullptr;
|
||||
|
||||
class GY21t : public IoTItem {
|
||||
public:
|
||||
GY21t(String parameters): IoTItem(parameters) { }
|
||||
|
||||
void doByInterval() {
|
||||
//wire->read();
|
||||
value.valD = sensor->GY21_Temperature();
|
||||
if (value.valD > -46.85F) regEvent(value.valD, "GY21");
|
||||
else SerialPrint("E", "Sensor GY21t", "Error");
|
||||
}
|
||||
|
||||
~GY21t();
|
||||
};
|
||||
|
||||
class GY21h : public IoTItem {
|
||||
public:
|
||||
GY21h(String parameters): IoTItem(parameters) { }
|
||||
|
||||
void doByInterval() {
|
||||
//sht->read();
|
||||
value.valD = sensor->GY21_Humidity();
|
||||
if (value.valD != -6) regEvent(value.valD, "GY21h");
|
||||
else SerialPrint("E", "Sensor GY21h", "Error");
|
||||
}
|
||||
|
||||
~GY21h();
|
||||
};
|
||||
|
||||
void* getAPI_GY21(String subtype, String param) {
|
||||
if (!sensor) {
|
||||
sensor = new GY21;
|
||||
if (sensor) Wire.begin(SDA, SCL);
|
||||
}
|
||||
|
||||
if (subtype == F("GY21t")) {
|
||||
return new GY21t(param);
|
||||
} else if (subtype == F("GY21h")) {
|
||||
return new GY21h(param);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
54
src/modules/Hdc1080.cpp
Normal file
54
src/modules/Hdc1080.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/******************************************************************
|
||||
Used ClosedCube HDC1080 Driver (temperature and humidity sensor)
|
||||
Support for HDC1080
|
||||
https://github.com/closedcube/ClosedCube_HDC1080_Arduino
|
||||
|
||||
adapted for version 4 @Serghei63
|
||||
******************************************************************/
|
||||
#include "Global.h"
|
||||
#include "Classes/IoTItem.h"
|
||||
|
||||
#include "Wire.h"
|
||||
#include "ClosedCube_HDC1080.h"
|
||||
#include <map>
|
||||
|
||||
//создаем объект HDC1080
|
||||
ClosedCube_HDC1080 hdc1080;
|
||||
|
||||
class Hdc1080t : public IoTItem {
|
||||
public:
|
||||
Hdc1080t(String parameters): IoTItem(parameters) { }
|
||||
|
||||
void doByInterval() {
|
||||
value.valD = hdc1080.readTemperature();
|
||||
if (value.valD > -46.85F) regEvent(value.valD, "Hdc1080t");
|
||||
else SerialPrint("E", "Sensor Hdc1080t", "Error");
|
||||
}
|
||||
|
||||
~Hdc1080t();
|
||||
};
|
||||
|
||||
class Hdc1080h : public IoTItem {
|
||||
public:
|
||||
Hdc1080h(String parameters): IoTItem(parameters) { }
|
||||
|
||||
void doByInterval() {
|
||||
value.valD = hdc1080.readHumidity();
|
||||
if (value.valD > -46.85F) regEvent(value.valD, "Hdc1080h");
|
||||
else SerialPrint("E", "Sensor Hdc1080h", "Error");
|
||||
}
|
||||
|
||||
~Hdc1080h();
|
||||
};
|
||||
|
||||
void* getAPI_Hdc1080(String subtype, String param) {
|
||||
if (subtype == F("Hdc1080t")) {
|
||||
hdc1080.begin(0x40);
|
||||
return new Hdc1080t(param);
|
||||
} else if (subtype == F("Hdc1080h")) {
|
||||
hdc1080.begin(0x40);
|
||||
return new Hdc1080h(param);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
97
src/modules/Lcd2004.cpp
Normal file
97
src/modules/Lcd2004.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
#include "Global.h"
|
||||
#include "classes/IoTItem.h"
|
||||
|
||||
#include "LiquidCrystal_I2C.h"
|
||||
#include <map>
|
||||
|
||||
LiquidCrystal_I2C *LCDI2C;
|
||||
|
||||
class Lcd2004 : public IoTItem {
|
||||
private:
|
||||
unsigned int _x;
|
||||
unsigned int _y;
|
||||
String _id2show;
|
||||
String _descr;
|
||||
int _prevStrSize;
|
||||
|
||||
public:
|
||||
Lcd2004(String parameters): IoTItem(parameters) {
|
||||
String addr, size, xy;
|
||||
_prevStrSize = 0;
|
||||
|
||||
jsonRead(parameters, "addr", addr);
|
||||
jsonRead(parameters, "size", size);
|
||||
int w = selectFromMarkerToMarker(size, ",", 0).toInt(); //количество столбцов
|
||||
int h = selectFromMarkerToMarker(size, ",", 1).toInt(); //количество строк
|
||||
if (LCDI2C == nullptr) { //инициализации экрана еще не было
|
||||
LCDI2C = new LiquidCrystal_I2C(hexStringToUint8(addr), w, h);
|
||||
if(LCDI2C != nullptr) {
|
||||
LCDI2C->init();
|
||||
LCDI2C->backlight();
|
||||
}
|
||||
}
|
||||
|
||||
jsonRead(parameters, "coord", xy);
|
||||
_x = selectFromMarkerToMarker(xy, ",", 0).toInt();
|
||||
_y = selectFromMarkerToMarker(xy, ",", 1).toInt();
|
||||
|
||||
jsonRead(parameters, "descr", _descr);
|
||||
jsonRead(parameters, "id2show", _id2show);
|
||||
}
|
||||
|
||||
void doByInterval() {
|
||||
if (LCDI2C != nullptr) {
|
||||
printBlankStr(_prevStrSize);
|
||||
|
||||
String tmpStr;
|
||||
jsonRead(paramsHeapJson, _id2show, tmpStr);
|
||||
if (_descr != "none") tmpStr = _descr + " " + tmpStr;
|
||||
LCDI2C->setCursor(_x, _y);
|
||||
LCDI2C->print(tmpStr);
|
||||
|
||||
// LCDI2C->print("Helloy,Manager 404 !");
|
||||
|
||||
_prevStrSize = tmpStr.length();
|
||||
}
|
||||
}
|
||||
|
||||
IoTValue execute(String command, std::vector<IoTValue> ¶m) { // будет возможным использовать, когда сценарии запустятся
|
||||
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") {
|
||||
_x = param[0].valD;
|
||||
}
|
||||
else if (command == "y") {
|
||||
_y = param[0].valD;
|
||||
}
|
||||
else if (command == "descr") {
|
||||
_descr = param[0].valS;
|
||||
}
|
||||
else if (command == "id2show") {
|
||||
_id2show = param[0].valS;
|
||||
}
|
||||
|
||||
doByInterval();
|
||||
return {};
|
||||
}
|
||||
|
||||
//печать пустой строки нужной длинны для затирания предыдущего значения на экране
|
||||
void printBlankStr(int strSize){
|
||||
String tmpStr = "";
|
||||
for(int i=0; i<strSize; i++) tmpStr += " ";
|
||||
LCDI2C->setCursor(_x, _y);
|
||||
LCDI2C->print(tmpStr);
|
||||
}
|
||||
|
||||
~Lcd2004(){};
|
||||
};
|
||||
|
||||
void* getAPI_Lcd2004(String subtype, String param) {
|
||||
if (subtype == F("Lcd2004")) {
|
||||
return new Lcd2004(param);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user