Merge pull request #22 from IoTManagerProject/ver4dev

Ver4dev
This commit is contained in:
Mit4el
2023-10-11 23:34:59 +03:00
committed by GitHub
24 changed files with 748 additions and 569 deletions

View File

@@ -3,7 +3,6 @@
void* getAPI_Cron(String subtype, String params);
void* getAPI_Loging(String subtype, String params);
void* getAPI_LogingDaily(String subtype, String params);
void* getAPI_owmWeather(String subtype, String params);
void* getAPI_Timer(String subtype, String params);
void* getAPI_Variable(String subtype, String params);
void* getAPI_VariableColor(String subtype, String params);
@@ -36,6 +35,7 @@ void* getAPI_Pcf8574(String subtype, String params);
void* getAPI_Pwm8266(String subtype, String params);
void* getAPI_TelegramLT(String subtype, String params);
void* getAPI_Lcd2004(String subtype, String params);
void* getAPI_Oled64(String subtype, String params);
void* getAPI_TM16XX(String subtype, String params);
void* getAPI(String subtype, String params) {
@@ -43,7 +43,6 @@ void* tmpAPI;
if ((tmpAPI = getAPI_Cron(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Loging(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_LogingDaily(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_owmWeather(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Timer(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Variable(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_VariableColor(subtype, params)) != nullptr) return tmpAPI;
@@ -76,6 +75,7 @@ if ((tmpAPI = getAPI_Pcf8574(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Pwm8266(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_TelegramLT(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Oled64(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_TM16XX(subtype, params)) != nullptr) return tmpAPI;
return nullptr;
}

View File

@@ -2,7 +2,7 @@
#include "classes/IoTItem.h"
#include <RobotClass_LiquidCrystal_I2C.h>
RobotClass_LiquidCrystal_I2C *LCDI2C;
RobotClass_LiquidCrystal_I2C* LCDI2C;
class Lcd2004 : public IoTItem {
private:
@@ -12,7 +12,7 @@ class Lcd2004 : public IoTItem {
int _prevStrSize;
String _addr;
bool _isShow = true; // экран показывает
bool _isShow = true; // экран показывает
public:
Lcd2004(String parameters) : IoTItem(parameters) {
@@ -26,9 +26,9 @@ class Lcd2004 : public IoTItem {
}
jsonRead(parameters, "size", size);
int w = selectFromMarkerToMarker(size, ",", 0).toInt(); //количество столбцов
int h = selectFromMarkerToMarker(size, ",", 1).toInt(); //количество строк
if (LCDI2C == nullptr) { //инициализации экрана еще не было
int w = selectFromMarkerToMarker(size, ",", 0).toInt(); // количество столбцов
int h = selectFromMarkerToMarker(size, ",", 1).toInt(); // количество строк
if (LCDI2C == nullptr) { // инициализации экрана еще не было
LCDI2C = new RobotClass_LiquidCrystal_I2C(hexStringToUint8(_addr), w, h, CP_UTF8);
if (LCDI2C != nullptr) {
LCDI2C->init();
@@ -46,7 +46,7 @@ class Lcd2004 : public IoTItem {
jsonRead(parameters, "postfix", _postfix);
}
void drawItem(IoTItem* item) {
void drawItem(IoTItem* item) {
String tmpStr = _prefix;
tmpStr += item->getValue();
tmpStr += _postfix;
@@ -66,15 +66,18 @@ class Lcd2004 : public IoTItem {
}
void onRegEvent(IoTItem* eventItem) {
if (LCDI2C == nullptr) { scanI2C(); return;}
if (!eventItem || _id2show == "") return;
if (LCDI2C == nullptr) {
scanI2C();
return;
}
if (!eventItem || _id2show == "") return;
if (_id2show == eventItem->getID()) {
setValue(eventItem->value, false);
}
}
IoTValue execute(String command, std::vector<IoTValue> &param) {
IoTValue execute(String command, std::vector<IoTValue>& param) {
if (command == "noBacklight")
LCDI2C->noBacklight();
else if (command == "backlight")
@@ -89,7 +92,7 @@ class Lcd2004 : public IoTItem {
if (_isShow) {
LCDI2C->noDisplay();
_isShow = false;
} else {
} else {
LCDI2C->display();
_isShow = true;
}
@@ -119,7 +122,7 @@ class Lcd2004 : public IoTItem {
return {};
}
//печать пустой строки нужной длинны для затирания предыдущего значения на экране
// печать пустой строки нужной длинны для затирания предыдущего значения на экране
void printBlankStr(int strSize) {
String tmpStr = "";
for (int i = 0; i < strSize; i++) tmpStr += " ";
@@ -127,13 +130,13 @@ class Lcd2004 : public IoTItem {
LCDI2C->print(tmpStr);
}
~Lcd2004(){
~Lcd2004() {
if (LCDI2C) delete LCDI2C;
LCDI2C = nullptr;
};
};
void *getAPI_Lcd2004(String subtype, String param) {
void* getAPI_Lcd2004(String subtype, String param) {
if (subtype == F("Lcd2004")) {
return new Lcd2004(param);
} else {

View File

@@ -0,0 +1,134 @@
#include "Global.h"
#include "classes/IoTItem.h"
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 0
Adafruit_SSD1306 display(OLED_RESET);
class Oled64 : public IoTItem {
private:
unsigned int _x;
unsigned int _y;
String _id2show, _prefix = "", _postfix = "";
String _size = "1";
String _addr;
int _prevStrSize;
bool _isShow = true;
public:
Oled64(String parameters) : IoTItem(parameters) {
String size, xy;
_prevStrSize = 0;
jsonRead(parameters, "addr", _addr);
if (_addr == "") {
scanI2C();
return;
}
display.begin(SSD1306_SWITCHCAPVCC, hexStringToUint8(_addr));
display.display();
display.clearDisplay();
jsonRead(parameters, "coord", xy);
_x = selectFromMarkerToMarker(xy, ",", 0).toInt();
_y = selectFromMarkerToMarker(xy, ",", 1).toInt();
jsonRead(parameters, "id2show", _id2show);
jsonRead(parameters, "prefix", _prefix);
jsonRead(parameters, "postfix", _postfix);
jsonRead(parameters, "size", _size);
}
void drawItem(IoTItem *item) {
String tmpStr = _prefix;
tmpStr += item->getValue();
tmpStr += _postfix;
display.setRotation(0);
display.setCursor(_x, _y);
display.setTextColor(WHITE, BLACK);
display.setTextSize(_size.toInt());
printBlankStr(_prevStrSize);
display.setCursor(_x, _y);
display.print(tmpStr);
_prevStrSize = tmpStr.length();
display.display();
_prevStrSize = tmpStr.length();
}
void setValue(const IoTValue &Value, bool genEvent = true) {
value = Value;
drawItem(this);
IoTItem::setValue(Value, genEvent);
}
void onRegEvent(IoTItem *eventItem) {
if (!eventItem || _id2show == "") return;
if (_id2show == eventItem->getID()) {
setValue(eventItem->value, false);
}
}
IoTValue execute(String command, std::vector<IoTValue> &param) {
if (command == "display") {
_isShow = true;
} else if (command == "noDisplay") {
_isShow = false;
} else if (command == "x") {
if (param.size()) {
_x = param[0].valD;
}
} else if (command == "y") {
if (param.size()) {
_y = param[0].valD;
}
} else if (command == "prefix") {
if (param.size()) {
_prefix = param[0].valS;
}
} else if (command == "postfix") {
if (param.size()) {
_postfix = param[0].valS;
}
} else if (command == "id2show") {
if (param.size()) {
_id2show = param[0].valS;
}
}
doByInterval();
return {};
}
// печать пустой строки нужной длинны для затирания предыдущего значения на экране
void printBlankStr(int strSize) {
String tmpStr = "";
for (int i = 0; i < strSize; i++) tmpStr += " ";
display.setCursor(_x, _y);
display.print(tmpStr);
}
~Oled64(){};
};
void *getAPI_Oled64(String subtype, String param) {
if (subtype == F("Oled64")) {
return new Oled64(param);
} else {
return nullptr;
}
}

View File

@@ -0,0 +1,97 @@
{
"menuSection": "screens",
"configItem": [
{
"global": 0,
"name": "OLED экран 64 8266",
"type": "Reading",
"subtype": "Oled64",
"id": "Oled",
"widget": "inputTxt",
"page": "screens",
"descr": "OLED Экран",
"addr": "0x3C",
"coord": "0,0",
"size": "1",
"id2show": "",
"prefix": "",
"postfix": ""
}
],
"about": {
"authorName": "Serghei Crasnicov",
"authorContact": "https://t.me/Serghei63",
"authorGit": "https://github.com/Serghei63",
"specialThanks": "Valentin Khandriga @Valiuhaaa",
"moduleName": "Oled64",
"moduleVersion": "1.0",
"usedRam": {
"esp32_4mb": 15,
"esp8266_4mb": 15
},
"title": "Модуль отображения на экранах OLED 64*48",
"moduleDesc": "Позволяет выводить на OLED экраны по указанным позициям значения других элементов конфигурации.",
"propInfo": {
"addr": "Адрес устройства на шине, обычно 0x3C.",
"coord": "Координата позиции для вывода данных элемента конфигурации.",
"id2show": "id элемента конфигурации.",
"size": "Размер шрифта. Допускается 1, 2, 3, 4"
},
"funcInfo": [
{
"name": "x",
"descr": "Устанавливает первую координату",
"params": [
"Номер строки первого символа"
]
},
{
"name": "y",
"descr": "Устанавливает вторую координату",
"params": [
"Номер столбца первого символа"
]
},
{
"name": "descr",
"descr": "Задает приставку слева от значения",
"params": [
"Строка"
]
},
{
"name": "descr1",
"descr1": "Задает приставку справа от значения",
"params": [
"Строка"
]
},
{
"name": "id2show",
"descr": "Задает ИД элемента, значение которого хотим отображать на экране",
"params": [
"Имя элемента конфигурации"
]
}
]
},
"defActive": true,
"usedLibs": {
"esp32_4mb": [
"https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED",
"https://github.com/adafruit/Adafruit-GFX-Library"
],
"esp8266_4mb": [
"https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED",
"https://github.com/adafruit/Adafruit-GFX-Library"
],
"esp8266_1mb": [
"https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED",
"https://github.com/adafruit/Adafruit-GFX-Library"
],
"esp8266_1mb_ota": [
"https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED",
"https://github.com/adafruit/Adafruit-GFX-Library"
]
}
}

View File

@@ -1,18 +1,12 @@
#include "Global.h"
#include "classes/IoTItem.h"
class HttpGet : public IoTItem
{
public:
HttpGet(String parameters) : IoTItem(parameters)
{
}
void sendHttpPOST(String url, String msg)
{
if (isNetworkActive())
{
class HttpGet : public IoTItem {
public:
HttpGet(String parameters) : IoTItem(parameters) {}
void sendHttpPOST(String url, String msg) {
if (isNetworkActive()) {
WiFiClient client;
HTTPClient http;
http.begin(client, url);
@@ -23,26 +17,23 @@ public:
SerialPrint("<-", F("HttpPOST"), "URL: " + url + ", msg: " + msg);
SerialPrint("->", F("HttpPOST"), "URL: " + url + ", server: " + httpResponseCode);
if (httpResponseCode > 0)
{
if (httpResponseCode > 0) {
value.valS = payload;
value.isDecimal = false;
SerialPrint("->", F("HttpPOST"), "msg from server: " + (String)payload.c_str());
value.valS = payload;
regEvent(value.valS, "HttpGet");
}
http.end();
}
}
void sendHttpGET(String url)
{
void sendHttpGET(String url) {
WiFiClient client;
HTTPClient http;
#if defined ESP8266
if (!http.begin(client, url))
{
if (!http.begin(client, url)) {
#elif defined ESP32
if (!http.begin(url))
{
if (!http.begin(url)) {
#endif
SerialPrint("I", F("HttpGet"), "connection failed ");
@@ -52,31 +43,23 @@ public:
String payload = http.getString();
SerialPrint("<-", F("HttpGET"), "URL: " + url);
SerialPrint("->", F("HttpGET"), "URL: " + url + ", server: " + httpResponseCode);
if (httpResponseCode > 0)
{
if (httpResponseCode > 0) {
value.valS = payload;
value.isDecimal = false;
SerialPrint("->", F("HttpGET"), "msg from server: " + (String)payload.c_str());
value.valS = payload;
regEvent(value.valS, "HttpGet");
}
http.end();
}
IoTValue execute(String command, std::vector<IoTValue> &param)
{
if (param.size() > 0)
{
if (command == "get")
{
if (param.size())
{
IoTValue execute(String command, std::vector<IoTValue> &param) {
if (param.size() > 0) {
if (command == "get") {
if (param.size()) {
sendHttpGET(param[0].valS);
}
}
else if (command == "post")
{
if (param.size())
{
} else if (command == "post") {
if (param.size()) {
sendHttpPOST(param[0].valS, param[1].valS);
}
}
@@ -87,14 +70,10 @@ public:
~HttpGet(){};
};
void *getAPI_HttpGet(String subtype, String param)
{
if (subtype == F("HttpGet"))
{
void *getAPI_HttpGet(String subtype, String param) {
if (subtype == F("HttpGet")) {
return new HttpGet(param);
}
else
{
} else {
return nullptr;
}
}

View File

@@ -1,6 +1,5 @@
{
"menuSection": "virtual_elments",
"configItem": [
{
"global": 0,
@@ -24,7 +23,6 @@
"debug": 0
}
],
"about": {
"authorName": "Serghei Crasnicov, v2.0 Mikhail Bubnov",
"authorContact": "https://t.me/Serghei63",
@@ -60,24 +58,14 @@
"lon": "Долгота, при использовании координат, будет автоматически выбран ближайший город",
"lat": "Широта, при использовании координат, будет автоматически выбран ближайший город",
"lang": "Язык используемый в ответах OpenWetaherMap",
"debug":"1 - выводить дополнительный лог в сериал"
"debug": "1 - выводить дополнительный лог в сериал"
}
},
"defActive": true,
"defActive": false,
"usedLibs": {
"esp32_4mb": [],
"esp32_4mb3f": [],
"esp32s2_4mb": [],
"esp32_16mb": [],
"esp8266_4mb": [],
"esp8266_16mb": [],
"esp8266_1mb": [],
"esp8266_1mb_ota": [],
"esp8285_1mb": [],
"esp8285_1mb_ota": [],
"esp8266_2mb": [],
"esp8266_2mb_ota": []
"esp32_16mb": []
}
}
}