Добавляем функцию сохранения состояния элементов на flash

This commit is contained in:
2022-10-20 00:18:41 +03:00
parent c89127c067
commit b8e76e19b8
15 changed files with 540 additions and 79 deletions

View File

@@ -7,7 +7,34 @@
"header": "Виртуальные элементы" "header": "Виртуальные элементы"
}, },
{ {
"name": "1. Таймер", "name": "1. График",
"type": "Writing",
"subtype": "Loging",
"id": "log",
"widget": "chart2",
"page": "Графики",
"descr": "Температура",
"num": 1,
"int": 5,
"logid": "t",
"points": 300
},
{
"name": "2. График дневного расхода",
"type": "Writing",
"subtype": "LogingDaily",
"id": "log",
"widget": "chart3",
"page": "Графики",
"descr": "Температура",
"num": 2,
"int": 1,
"logid": "t",
"points": 365,
"test": 0
},
{
"name": "3. Таймер",
"type": "Writing", "type": "Writing",
"subtype": "Timer", "subtype": "Timer",
"id": "timer", "id": "timer",
@@ -19,73 +46,227 @@
"ticker": 1, "ticker": 1,
"repeat": 1, "repeat": 1,
"needSave": 0, "needSave": 0,
"num": 1 "num": 3
}, },
{ {
"name": "2. Окно ввода числа (переменная)", "name": "4. Окно ввода числа (переменная)",
"type": "Reading", "type": "Reading",
"subtype": "Variable", "subtype": "Variable",
"id": "value", "id": "value",
"needSave": 0,
"widget": "inputDgt", "widget": "inputDgt",
"page": "Ввод", "page": "Ввод",
"descr": "Введите число", "descr": "Введите число",
"int": "0", "int": "0",
"val": "0.0", "val": "0.0",
"num": 2 "num": 4
}, },
{ {
"name": "3. Окно ввода времени", "name": "5. Окно ввода времени",
"type": "Reading", "type": "Reading",
"subtype": "Variable", "subtype": "Variable",
"id": "time", "id": "time",
"needSave": 0,
"widget": "inputTm", "widget": "inputTm",
"page": "Ввод", "page": "Ввод",
"descr": "Введите время", "descr": "Введите время",
"int": "0", "int": "0",
"val": "02:00", "val": "02:00",
"num": 3 "num": 5
}, },
{ {
"name": "4. Окно ввода даты", "name": "6. Окно ввода даты",
"type": "Reading", "type": "Reading",
"subtype": "Variable", "subtype": "Variable",
"id": "time", "id": "time",
"needSave": 0,
"widget": "inputDate", "widget": "inputDate",
"page": "Ввод", "page": "Ввод",
"descr": "Введите дату", "descr": "Введите дату",
"int": "0", "int": "0",
"val": "24.05.2022", "val": "24.05.2022",
"num": 4 "num": 6
}, },
{ {
"name": "5. Окно ввода текста", "name": "7. Окно ввода текста",
"type": "Reading", "type": "Reading",
"subtype": "Variable", "subtype": "Variable",
"id": "txt", "id": "txt",
"needSave": 0,
"widget": "inputTxt", "widget": "inputTxt",
"page": "Ввод", "page": "Ввод",
"descr": "Введите текст", "descr": "Введите текст",
"int": "0", "int": "0",
"val": "текст", "val": "текст",
"num": 5 "num": 7
}, },
{ {
"name": "6. Виртуальная кнопка", "name": "8. Виртуальная кнопка",
"type": "Reading", "type": "Reading",
"subtype": "VButton", "subtype": "VButton",
"id": "vbtn", "id": "vbtn",
"needSave": 0,
"widget": "toggle", "widget": "toggle",
"page": "Кнопки", "page": "Кнопки",
"descr": "Кнопка", "descr": "Кнопка",
"int": "0", "int": "0",
"val": "0", "val": "0",
"num": 6 "num": 8
}, },
{ {
"header": "Сенсоры" "header": "Сенсоры"
}, },
{ {
"name": "7. DS18B20 Температура", "name": "9. Acs712 Ток",
"type": "Reading",
"subtype": "Acs712",
"id": "amp",
"widget": "anydataAmp",
"page": "Сенсоры",
"descr": "Ток",
"round": 3,
"pin": 39,
"int": 5,
"num": 9
},
{
"name": "10. AHTXX Температура",
"type": "Reading",
"subtype": "AhtXXt",
"id": "Temp20",
"widget": "anydataTmp",
"page": "Сенсоры",
"descr": "AHTXX Температура",
"int": 15,
"addr": "0x38",
"shtType": 1,
"round": 1,
"num": 10
},
{
"name": "11. AHTXX Влажность",
"type": "Reading",
"subtype": "AhtXXh",
"id": "Hum20",
"widget": "anydataHum",
"page": "Сенсоры",
"descr": "AHTXX Влажность",
"int": 15,
"addr": "0x38",
"shtType": 1,
"round": 1,
"num": 11
},
{
"name": "12. Аналоговый сенсор",
"type": "Reading",
"subtype": "AnalogAdc",
"id": "t",
"widget": "anydataTmp",
"page": "Сенсоры",
"descr": "Температура",
"map": "1,1024,1,100",
"plus": 0,
"multiply": 1,
"round": 1,
"pin": 0,
"int": 15,
"avgSteps": 1,
"num": 12
},
{
"name": "13. BME280 Температура",
"type": "Reading",
"subtype": "Bme280t",
"id": "tmp3",
"widget": "anydataTmp",
"page": "Сенсоры",
"descr": "Температура",
"int": 15,
"addr": "0x77",
"round": 1,
"num": 13
},
{
"name": "14. BME280 Давление",
"type": "Reading",
"subtype": "Bme280p",
"id": "Press3",
"widget": "anydataMm",
"page": "Сенсоры",
"descr": "Давление",
"int": 15,
"addr": "0x77",
"round": 1,
"num": 14
},
{
"name": "15. BME280 Влажность",
"type": "Reading",
"subtype": "Bme280h",
"id": "Hum3",
"widget": "anydataHum",
"page": "Сенсоры",
"descr": "Влажность",
"int": 15,
"addr": "0x77",
"round": 1,
"num": 15
},
{
"name": "16. BMP280 Температура",
"type": "Reading",
"subtype": "Bmp280t",
"id": "tmp3",
"widget": "anydataTmp",
"page": "Сенсоры",
"descr": "280 Температура",
"int": 15,
"addr": "0x77",
"round": 1,
"num": 16
},
{
"name": "17. BMP280 Давление",
"type": "Reading",
"subtype": "Bmp280p",
"id": "Press3",
"widget": "anydataMm",
"page": "Сенсоры",
"descr": "280 Давление",
"int": 15,
"addr": "0x77",
"round": 1,
"num": 17
},
{
"name": "18. DHT11 Температура",
"type": "Reading",
"subtype": "Dht1122t",
"id": "tmp3",
"widget": "anydataTmp",
"page": "Сенсоры",
"descr": "Температура",
"int": 15,
"pin": 0,
"senstype": "dht11",
"num": 18
},
{
"name": "19. DHT11 Влажность",
"type": "Reading",
"subtype": "Dht1122h",
"id": "Hum3",
"widget": "anydataHum",
"page": "Сенсоры",
"descr": "Влажность",
"int": 15,
"pin": 0,
"senstype": "dht11",
"num": 19
},
{
"name": "20. DS18B20 Температура",
"type": "Reading", "type": "Reading",
"subtype": "Ds18b20", "subtype": "Ds18b20",
"id": "dstmp", "id": "dstmp",
@@ -97,11 +278,153 @@
"index": 0, "index": 0,
"addr": "", "addr": "",
"round": 1, "round": 1,
"num": 7 "num": 20
}, },
{ {
"name": "8. Сканер кнопок 433 MHz", "name": "21. GY21 Температура",
"num": 8, "type": "Reading",
"subtype": "GY21t",
"id": "tmp4",
"widget": "anydataTmp",
"page": "Сенсоры",
"descr": "Температура",
"round": 1,
"int": 15,
"num": 21
},
{
"name": "22. GY21 Влажность",
"type": "Reading",
"subtype": "GY21h",
"id": "Hum4",
"widget": "anydataHum",
"page": "Сенсоры",
"descr": "Влажность",
"round": 1,
"int": 15,
"num": 22
},
{
"name": "23. HDC1080 Температура",
"type": "Reading",
"subtype": "Hdc1080t",
"id": "Temp1080",
"widget": "anydataTmp",
"page": "Сенсоры",
"descr": "1080 Температура",
"int": 15,
"addr": "0x40",
"round": 1,
"num": 23
},
{
"name": "24. HDC1080 Влажность",
"type": "Reading",
"subtype": "Hdc1080h",
"id": "Hum1080",
"widget": "anydataHum",
"page": "Сенсоры",
"descr": "1080 Влажность",
"int": 15,
"addr": "0x40",
"round": 1,
"num": 24
},
{
"name": "25. MAX6675 Температура",
"type": "Reading",
"subtype": "Max6675t",
"id": "maxtmp",
"widget": "anydataTmp",
"page": "Сенсоры",
"descr": "MAX Температура",
"int": 15,
"DO": 12,
"CS": 13,
"CLK": 14,
"num": 25
},
{
"name": "26. PZEM 004t Напряжение",
"type": "Reading",
"subtype": "Pzem004v",
"id": "v",
"widget": "anydataVlt",
"page": "PZEM",
"descr": "Напряжение",
"int": 15,
"addr": "0xF8",
"round": 1,
"num": 26
},
{
"name": "27. PZEM 004t Сила тока",
"type": "Reading",
"subtype": "Pzem004a",
"id": "a",
"widget": "anydataAmp",
"page": "PZEM",
"descr": "Сила тока",
"int": 15,
"addr": "0xF8",
"round": 1,
"num": 27
},
{
"name": "28. PZEM 004t Мощность",
"type": "Reading",
"subtype": "Pzem004w",
"id": "w",
"widget": "anydataWt",
"page": "PZEM",
"descr": "Мощность",
"int": 15,
"addr": "0xF8",
"round": 1,
"num": 28
},
{
"name": "29. PZEM 004t Энергия",
"type": "Reading",
"subtype": "Pzem004wh",
"id": "wh",
"widget": "anydataWth",
"page": "PZEM",
"descr": "Энергия",
"int": 15,
"addr": "0xF8",
"round": 1,
"num": 29
},
{
"name": "30. PZEM 004t Частота",
"type": "Reading",
"subtype": "Pzem004hz",
"id": "hz",
"widget": "anydataHtz",
"page": "PZEM",
"descr": "Частота",
"int": 15,
"addr": "0xF8",
"round": 1,
"num": 30
},
{
"name": "31. PZEM 004t Косинус",
"type": "Reading",
"subtype": "Pzem004pf",
"id": "pf",
"widget": "anydata",
"page": "PZEM",
"descr": "Косинус F",
"int": 15,
"addr": "0xF8",
"round": 1,
"num": 31
},
{
"name": "32. Сканер кнопок 433 MHz",
"num": 32,
"type": "Reading", "type": "Reading",
"subtype": "RCswitch", "subtype": "RCswitch",
"id": "rsw", "id": "rsw",
@@ -110,8 +433,56 @@
"pinTx": 12 "pinTx": 12
}, },
{ {
"name": "9. HC-SR04 Ультразвуковой дальномер", "name": "33. Sht20 Температура",
"num": 9, "type": "Reading",
"subtype": "Sht20t",
"id": "tmp2",
"widget": "anydataTmp",
"page": "Сенсоры",
"descr": "Температура",
"int": 15,
"round": 1,
"num": 33
},
{
"name": "34. Sht20 Влажность",
"type": "Reading",
"subtype": "Sht20h",
"id": "Hum2",
"widget": "anydataHum",
"page": "Сенсоры",
"descr": "Влажность",
"int": 15,
"round": 1,
"num": 34
},
{
"name": "35. Sht30 Температура",
"type": "Reading",
"subtype": "Sht30t",
"id": "tmp30",
"widget": "anydataTmp",
"page": "Сенсоры",
"descr": "SHT30 Температура",
"int": 15,
"round": 1,
"num": 35
},
{
"name": "36. Sht30 Влажность",
"type": "Reading",
"subtype": "Sht30h",
"id": "Hum30",
"widget": "anydataHum",
"page": "Сенсоры",
"descr": "SHT30 Влажность",
"int": 15,
"round": 1,
"num": 36
},
{
"name": "37. HC-SR04 Ультразвуковой дальномер",
"num": 37,
"type": "Reading", "type": "Reading",
"subtype": "Sonar", "subtype": "Sonar",
"id": "sonar", "id": "sonar",
@@ -122,29 +493,44 @@
"pinEcho": 4, "pinEcho": 4,
"int": 5 "int": 5
}, },
{
"name": "38. UART",
"type": "Reading",
"subtype": "UART",
"page": "",
"descr": "",
"widget": "nil",
"id": "u",
"tx": 12,
"rx": 13,
"speed": 9600,
"num": 38
},
{ {
"header": "Исполнительные устройства" "header": "Исполнительные устройства"
}, },
{ {
"name": "10. Кнопка подключенная к пину", "name": "39. Кнопка подключенная к пину",
"type": "Writing", "type": "Writing",
"subtype": "ButtonIn", "subtype": "ButtonIn",
"id": "btn", "id": "btn",
"widget": "toggle", "widget": "toggle",
"page": "Кнопки", "page": "Кнопки",
"descr": "Освещение", "descr": "Освещение",
"needSave": 0,
"int": 0, "int": 0,
"pin": 16, "pin": 16,
"execLevel": "1", "execLevel": "1",
"pinMode": "INPUT", "pinMode": "INPUT",
"debounceDelay": 50, "debounceDelay": 50,
"fixState": 0, "fixState": 0,
"num": 10 "num": 39
}, },
{ {
"name": "11. Управление пином", "name": "40. Управление пином",
"type": "Writing", "type": "Writing",
"subtype": "ButtonOut", "subtype": "ButtonOut",
"needSave": 0,
"id": "btn", "id": "btn",
"widget": "toggle", "widget": "toggle",
"page": "Кнопки", "page": "Кнопки",
@@ -152,10 +538,24 @@
"int": 0, "int": 0,
"inv": 0, "inv": 0,
"pin": 2, "pin": 2,
"num": 11 "num": 40
}, },
{ {
"name": "12. Расширитель портов Mcp23017", "name": "41. Сервопривод",
"type": "Writing",
"subtype": "IoTServo",
"id": "servo",
"widget": "range",
"page": "servo",
"descr": "угол",
"int": 1,
"pin": 12,
"apin": -1,
"amap": "0, 4096, 0, 180",
"num": 41
},
{
"name": "42. Расширитель портов Mcp23017",
"type": "Reading", "type": "Reading",
"subtype": "Mcp23017", "subtype": "Mcp23017",
"id": "Mcp", "id": "Mcp",
@@ -165,10 +565,23 @@
"int": "0", "int": "0",
"addr": "0x20", "addr": "0x20",
"index": 1, "index": 1,
"num": 12 "num": 42
}, },
{ {
"name": "13. Расширитель портов Pcf8574", "name": "43. MP3 плеер",
"type": "Reading",
"subtype": "Mp3",
"id": "mp3",
"widget": "",
"page": "",
"descr": "",
"int": 1,
"pins": "14,12",
"volume": 20,
"num": 43
},
{
"name": "44. Расширитель портов Pcf8574",
"type": "Reading", "type": "Reading",
"subtype": "Pcf8574", "subtype": "Pcf8574",
"id": "Pcf", "id": "Pcf",
@@ -178,10 +591,10 @@
"int": "0", "int": "0",
"addr": "0x20", "addr": "0x20",
"index": 1, "index": 1,
"num": 13 "num": 44
}, },
{ {
"name": "14. PWM ESP8266", "name": "45. PWM ESP8266",
"type": "Writing", "type": "Writing",
"subtype": "Pwm8266", "subtype": "Pwm8266",
"id": "pwm", "id": "pwm",
@@ -193,10 +606,10 @@
"freq": 5000, "freq": 5000,
"val": 0, "val": 0,
"apin": -1, "apin": -1,
"num": 14 "num": 45
}, },
{ {
"name": "15. Телеграм-Лайт", "name": "46. Телеграм-Лайт",
"type": "Writing", "type": "Writing",
"subtype": "TelegramLT", "subtype": "TelegramLT",
"id": "tg", "id": "tg",
@@ -205,13 +618,13 @@
"descr": "", "descr": "",
"token": "", "token": "",
"chatID": "", "chatID": "",
"num": 15 "num": 46
}, },
{ {
"header": "Экраны" "header": "Экраны"
}, },
{ {
"name": "16. LCD экран 2004", "name": "47. LCD экран 2004",
"type": "Reading", "type": "Reading",
"subtype": "Lcd2004", "subtype": "Lcd2004",
"id": "Lcd", "id": "Lcd",
@@ -223,10 +636,10 @@
"size": "20,4", "size": "20,4",
"coord": "0,0", "coord": "0,0",
"id2show": "id датчика", "id2show": "id датчика",
"num": 16 "num": 47
}, },
{ {
"name": "17. LCD экран 1602", "name": "48. LCD экран 1602",
"type": "Reading", "type": "Reading",
"subtype": "Lcd2004", "subtype": "Lcd2004",
"id": "Lcd", "id": "Lcd",
@@ -238,6 +651,6 @@
"size": "16,2", "size": "16,2",
"coord": "0,0", "coord": "0,0",
"id2show": "id датчика", "id2show": "id датчика",
"num": 17 "num": 48
} }
] ]

3
data_svelte/values.json Normal file
View File

@@ -0,0 +1,3 @@
{
}

View File

@@ -19,5 +19,6 @@
"pinSCL": 0, "pinSCL": 0,
"pinSDA": 0, "pinSDA": 0,
"i2cFreq": 100000, "i2cFreq": 100000,
"settings_": "" "settings_": "",
"wg": "group1"
} }

View File

@@ -0,0 +1,3 @@
{
}

View File

@@ -38,6 +38,7 @@ extern void globalVarsSync();
extern String getParamsJson(); extern String getParamsJson();
extern void syncSettingsFlashJson(); extern void syncSettingsFlashJson();
extern void syncValuesFlashJson();
extern const String getChipId(); extern const String getChipId();
extern void setChipId(); extern void setChipId();

View File

@@ -83,7 +83,9 @@ extern WebSocketsServer standWebSocket;
***********************************************глобальные переменные************************************************** ***********************************************глобальные переменные**************************************************
**********************************************************************************************************************/ **********************************************************************************************************************/
extern String settingsFlashJson; extern String settingsFlashJson;
extern String valuesFlashJson;
extern String errorsHeapJson; extern String errorsHeapJson;
extern bool needSaveValues;
// buf // buf
extern String orderBuf; extern String orderBuf;

View File

@@ -6,9 +6,6 @@ struct IoTValue {
String valS = ""; String valS = "";
bool isDecimal = true; bool isDecimal = true;
uint8_t* extBinInfo = NULL; // дополнительные бинарные данные из модуля
size_t extBinInfoSize = 0; // размер дополнительных данных в байтах
}; };
class IoTItem { class IoTItem {
@@ -38,12 +35,11 @@ class IoTItem {
bool iAmDead = false; // признак необходимости удалить объект из базы bool iAmDead = false; // признак необходимости удалить объект из базы
bool iAmLocal = true; // признак того, что айтем был создан локально bool iAmLocal = true; // признак того, что айтем был создан локально
bool needSave = false;
bool enableDoByInt = true; bool enableDoByInt = true;
virtual IoTGpio* getGpioDriver(); virtual IoTGpio* getGpioDriver();
virtual void setValue(IoTValue Value); virtual void setValue(IoTValue Value, bool generateEvent = true);
virtual void setValue(String valStr); virtual void setValue(String valStr, bool generateEvent = true);
String getRoundValue(); String getRoundValue();
//методы для графиков //методы для графиков
@@ -54,6 +50,7 @@ class IoTItem {
virtual void setTodayDate(); virtual void setTodayDate();
protected: protected:
bool _needSave = false; // признак необходимости сохранять и загружать значение элемента на flash
String _subtype; String _subtype;
String _id; String _id;
unsigned long _interval; unsigned long _interval;

View File

@@ -24,7 +24,7 @@
}, },
"projectProp": { "projectProp": {
"platformio": { "platformio": {
"default_envs": "esp8266_1mb_ota" "default_envs": "esp8266_4mb"
} }
}, },
"modules": { "modules": {

View File

@@ -83,11 +83,10 @@ build_src_filter =
${env:esp32_4mb_fromitems.build_src_filter} ${env:esp32_4mb_fromitems.build_src_filter}
[platformio] [platformio]
default_envs = esp8266_1mb_ota default_envs = esp8266_4mb
data_dir = data_svelte_lite data_dir = data_svelte
[common_env_data] [common_env_data]
upload_port = COM4
lib_deps_external = lib_deps_external =
bblanchon/ArduinoJson @6.18.0 bblanchon/ArduinoJson @6.18.0
knolleary/PubSubClient knolleary/PubSubClient

View File

@@ -14,6 +14,10 @@ void globalVarsSync() {
settingsFlashJson = readFile(F("settings.json"), 4096); settingsFlashJson = readFile(F("settings.json"), 4096);
settingsFlashJson.replace("\r\n", ""); settingsFlashJson.replace("\r\n", "");
valuesFlashJson = readFile(F("values.json"), 4096);
valuesFlashJson.replace("\r\n", "");
mqttPrefix = jsonReadStr(settingsFlashJson, F("mqttPrefix")); mqttPrefix = jsonReadStr(settingsFlashJson, F("mqttPrefix"));
mqttRootDevice = mqttPrefix + "/" + chipId; mqttRootDevice = mqttPrefix + "/" + chipId;
jsonWriteStr_(settingsFlashJson, "root", mqttRootDevice); jsonWriteStr_(settingsFlashJson, "root", mqttRootDevice);
@@ -34,6 +38,10 @@ void syncSettingsFlashJson() {
writeFile(F("settings.json"), settingsFlashJson); writeFile(F("settings.json"), settingsFlashJson);
} }
void syncValuesFlashJson() {
writeFile(F("values.json"), valuesFlashJson);
}
const String getChipId() { const String getChipId() {
return String(ESP_getChipId()) + "-" + String(ESP_getFlashChipId()); return String(ESP_getChipId()) + "-" + String(ESP_getFlashChipId());
} }

View File

@@ -31,8 +31,10 @@ WebSocketsServer standWebSocket = WebSocketsServer(81);
**********************************************************************************************************************/ **********************************************************************************************************************/
IoTGpio IoTgpio(0); IoTGpio IoTgpio(0);
String settingsFlashJson = "{}"; //переменная в которой хранятся все настройки, находится в оперативной памяти и синхронизированна с flash памятью String settingsFlashJson = "{}"; // переменная в которой хранятся все настройки, находится в оперативной памяти и синхронизированна с flash памятью
String errorsHeapJson = "{}"; //переменная в которой хранятся все ошибки, находится в оперативной памяти только String valuesFlashJson = "{}"; // переменная в которой хранятся все значения элементов, которые необходимо сохранить на flash. Находится в оперативной памяти и синхронизированна с flash памятью
String errorsHeapJson = "{}"; // переменная в которой хранятся все ошибки, находится в оперативной памяти только
bool needSaveValues = false; // признак необходимости сбросить значения элементов на flash
// buf // buf
String orderBuf = ""; String orderBuf = "";

View File

@@ -149,6 +149,14 @@ void loop() {
loopPeriod = millis() - st; loopPeriod = millis() - st;
if (loopPeriod > 2) Serial.println(loopPeriod); if (loopPeriod > 2) Serial.println(loopPeriod);
#endif #endif
// сохраняем значения IoTItems в файл каждую секунду, если были изменения (установлены маркеры на сохранение)
if (needSaveValues && millis()%1000 == 0) {
syncValuesFlashJson();
needSaveValues = false;
delay(1);
Serial.println("syncValuesFlashJson()");
}
} }
//отправка json //отправка json
@@ -162,24 +170,6 @@ void loop() {
// delay(1); // delay(1);
// } // }
// сохраняем значения IoTItems в файл каждую секунду, если были изменения (установлены маркеры на сохранение)
// currentMillis = millis();
// if (currentMillis - prevMillis >= 1000) {
// prevMillis = millis();
// volStrForSave = "";
// for (std::list<IoTItem *>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
// if ((*it)->needSave) {
// (*it)->needSave = false;
// volStrForSave = volStrForSave + (*it)->getID() + "=" + (*it)->getValue() + ";";
// }
// }
//
// if (volStrForSave != "") {
// Serial.print("volStrForSave: ");
// Serial.println(volStrForSave.c_str());
// }
//}
// File dir = FileFS.open("/", "r"); // File dir = FileFS.open("/", "r");
// String out; // String out;
// printDirectory(dir, out); // printDirectory(dir, out);

View File

@@ -34,16 +34,18 @@ void periodicTasksInit() {
void printGlobalVarSize() { void printGlobalVarSize() {
size_t settingsFlashJsonSize = settingsFlashJson.length(); size_t settingsFlashJsonSize = settingsFlashJson.length();
// SerialPrint(F("i"), F("settingsFlashJson"), String(settingsFlashJsonSize)); // SerialPrint(F("i"), F("settingsFlashJson"), String(settingsFlashJsonSize));
size_t valuesFlashJsonSize = valuesFlashJson.length();
size_t errorsHeapJsonSize = errorsHeapJson.length(); size_t errorsHeapJsonSize = errorsHeapJson.length();
// SerialPrint(F("i"), F("errorsHeapJson"), String(errorsHeapJsonSize)); // SerialPrint(F("i"), F("errorsHeapJson"), String(errorsHeapJsonSize));
size_t devListHeapJsonSize = devListHeapJson.length(); size_t devListHeapJsonSize = devListHeapJson.length();
// SerialPrint(F("i"), F("devListHeapJson"), String(devListHeapJsonSize)); // SerialPrint(F("i"), F("devListHeapJson"), String(devListHeapJsonSize));
SerialPrint(F("i"), F("Var summ sz"), String(settingsFlashJsonSize + errorsHeapJsonSize + devListHeapJsonSize)); SerialPrint(F("i"), F("Var summ sz"), String(settingsFlashJsonSize + valuesFlashJsonSize + errorsHeapJsonSize + devListHeapJsonSize));
size_t halfBuffer = JSON_BUFFER_SIZE / 2; size_t halfBuffer = JSON_BUFFER_SIZE / 2;
if (settingsFlashJsonSize > halfBuffer || if (settingsFlashJsonSize > halfBuffer ||
valuesFlashJsonSize > halfBuffer ||
errorsHeapJsonSize > halfBuffer || errorsHeapJsonSize > halfBuffer ||
devListHeapJsonSize > halfBuffer) { devListHeapJsonSize > halfBuffer) {
SerialPrint(F("EE"), F("Json"), F("Insufficient buffer size!!!")); SerialPrint(F("EE"), F("Json"), F("Insufficient buffer size!!!"));

View File

@@ -20,11 +20,11 @@ IoTItem::IoTItem(String parameters) {
String valAsStr; String valAsStr;
if (jsonRead(parameters, F("val"), valAsStr, false)) // значение переменной или датчика при инициализации если есть в конфигурации if (jsonRead(parameters, F("val"), valAsStr, false)) // значение переменной или датчика при инициализации если есть в конфигурации
if (value.isDecimal = isDigitDotCommaStr(valAsStr)) { setValue(valAsStr, false);
value.valD = valAsStr.toFloat();
} else { jsonRead(parameters, F("needSave"), _needSave, false);
value.valS = valAsStr; if (_needSave && jsonRead(valuesFlashJson, _id, valAsStr, false)) // пробуем достать из сохранения значение элемента, если указано, что нужно сохранять
} setValue(valAsStr, false);
String map; String map;
jsonRead(parameters, F("map"), map, false); jsonRead(parameters, F("map"), map, false);
@@ -58,27 +58,33 @@ String IoTItem::getValue() {
} }
//определяем тип прилетевшей величины //определяем тип прилетевшей величины
void IoTItem::setValue(String valStr) { void IoTItem::setValue(String valStr, bool generateEvent) {
if (value.isDecimal = isDigitDotCommaStr(valStr)) { if (value.isDecimal = isDigitDotCommaStr(valStr)) {
value.valD = valStr.toFloat(); value.valD = valStr.toFloat();
} else { } else {
value.valS = valStr; value.valS = valStr;
} }
setValue(value); if (generateEvent) setValue(value, generateEvent);
} }
// //
void IoTItem::setValue(IoTValue Value) { void IoTItem::setValue(IoTValue Value, bool generateEvent) {
value = Value; value = Value;
if (value.isDecimal) { if (generateEvent)
regEvent(value.valD, ""); if (value.isDecimal) {
} else { regEvent(value.valD, "");
regEvent(value.valS, ""); } else {
} regEvent(value.valS, "");
}
} }
//когда событие случилось //когда событие случилось
void IoTItem::regEvent(String value, String consoleInfo = "") { void IoTItem::regEvent(String value, String consoleInfo = "") {
if (_needSave) {
jsonWriteStr_(valuesFlashJson, _id, value);
needSaveValues = true;
}
generateEvent(_id, value); generateEvent(_id, value);
publishStatusMqtt(_id, value); publishStatusMqtt(_id, value);

View File

@@ -1,14 +1,31 @@
#include "ESPConfiguration.h" #include "ESPConfiguration.h"
void* getAPI_Loging(String subtype, String params);
void* getAPI_LogingDaily(String subtype, String params);
void* getAPI_Timer(String subtype, String params); void* getAPI_Timer(String subtype, String params);
void* getAPI_Variable(String subtype, String params); void* getAPI_Variable(String subtype, String params);
void* getAPI_VButton(String subtype, String params); void* getAPI_VButton(String subtype, String params);
void* getAPI_Acs712(String subtype, String params);
void* getAPI_AhtXX(String subtype, String params);
void* getAPI_AnalogAdc(String subtype, String params);
void* getAPI_Bme280(String subtype, String params);
void* getAPI_Bmp280(String subtype, String params);
void* getAPI_Dht1122(String subtype, String params);
void* getAPI_Ds18b20(String subtype, String params); void* getAPI_Ds18b20(String subtype, String params);
void* getAPI_GY21(String subtype, String params);
void* getAPI_Hdc1080(String subtype, String params);
void* getAPI_Max6675(String subtype, String params);
void* getAPI_Pzem004(String subtype, String params);
void* getAPI_RCswitch(String subtype, String params); void* getAPI_RCswitch(String subtype, String params);
void* getAPI_Sht20(String subtype, String params);
void* getAPI_Sht30(String subtype, String params);
void* getAPI_Sonar(String subtype, String params); void* getAPI_Sonar(String subtype, String params);
void* getAPI_UART(String subtype, String params);
void* getAPI_ButtonIn(String subtype, String params); void* getAPI_ButtonIn(String subtype, String params);
void* getAPI_ButtonOut(String subtype, String params); void* getAPI_ButtonOut(String subtype, String params);
void* getAPI_IoTServo(String subtype, String params);
void* getAPI_Mcp23017(String subtype, String params); void* getAPI_Mcp23017(String subtype, String params);
void* getAPI_Mp3(String subtype, String params);
void* getAPI_Pcf8574(String subtype, String params); void* getAPI_Pcf8574(String subtype, String params);
void* getAPI_Pwm8266(String subtype, String params); void* getAPI_Pwm8266(String subtype, String params);
void* getAPI_TelegramLT(String subtype, String params); void* getAPI_TelegramLT(String subtype, String params);
@@ -16,15 +33,32 @@ void* getAPI_Lcd2004(String subtype, String params);
void* getAPI(String subtype, String params) { void* getAPI(String subtype, String params) {
void* tmpAPI; void* tmpAPI;
if ((tmpAPI = getAPI_Loging(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_LogingDaily(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Timer(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_Variable(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_VButton(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_VButton(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Acs712(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_AhtXX(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_AnalogAdc(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Bme280(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Bmp280(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Dht1122(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Ds18b20(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Ds18b20(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_GY21(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Hdc1080(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Max6675(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Pzem004(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_RCswitch(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_RCswitch(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Sht20(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Sht30(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Sonar(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Sonar(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_UART(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_ButtonIn(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_ButtonIn(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_IoTServo(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Mp3(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Pcf8574(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Pcf8574(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Pwm8266(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_TelegramLT(subtype, params)) != nullptr) return tmpAPI;