Merge pull request #310 from Mit4el/ver4dev

Add board 16m, Add wifi multi point
This commit is contained in:
IoT Manager
2023-10-02 14:45:55 +02:00
committed by GitHub
37 changed files with 1117 additions and 611 deletions

View File

@@ -3,8 +3,8 @@
"name": "IoTmanagerVer4", "name": "IoTmanagerVer4",
"apssid": "IoTmanager", "apssid": "IoTmanager",
"appass": "", "appass": "",
"routerssid": "iot", "routerssid": ["iot","wifi"],
"routerpass": "hostel3333", "routerpass": ["hostel3333","pswd"],
"timezone": 2, "timezone": 2,
"ntp": "pool.ntp.org", "ntp": "pool.ntp.org",
"weblogin": "admin", "weblogin": "admin",
@@ -32,6 +32,11 @@
"firmware": "0x00000", "firmware": "0x00000",
"littlefs": "0x300000" "littlefs": "0x300000"
}, },
{
"name": "esp8266_16mb",
"firmware": "0x00000",
"littlefs": "0x200000"
},
{ {
"name": "esp32_4mb", "name": "esp32_4mb",
"boot_app0": "0xe000", "boot_app0": "0xe000",
@@ -40,6 +45,14 @@
"partitions": "0x8000", "partitions": "0x8000",
"littlefs": "0x290000" "littlefs": "0x290000"
}, },
{
"name": "esp32_16mb",
"boot_app0": "0xe000",
"bootloader_qio_80m": "0x1000",
"firmware": "0x10000",
"partitions": "0x8000",
"littlefs": "0x910000"
},
{ {
"name": "esp8266_1mb", "name": "esp8266_1mb",
"firmware": "0x00000000", "firmware": "0x00000000",

View File

@@ -2,8 +2,14 @@
"name": "IoTmanagerVer4", "name": "IoTmanagerVer4",
"apssid": "IoTmanager", "apssid": "IoTmanager",
"appass": "", "appass": "",
"routerssid": "iot", "routerssid": [
"routerpass": "hostel3333", "iot",
"wifi"
],
"routerpass": [
"hostel3333",
"pswd"
],
"timezone": 2, "timezone": 2,
"ntp": "pool.ntp.org", "ntp": "pool.ntp.org",
"weblogin": "admin", "weblogin": "admin",

View File

@@ -24,10 +24,18 @@
#define FIRMWARE_NAME "esp8266_4mb" #define FIRMWARE_NAME "esp8266_4mb"
#endif #endif
#ifdef esp8266_16mb
#define FIRMWARE_NAME "esp8266_16mb"
#endif
#ifdef esp32_4mb #ifdef esp32_4mb
#define FIRMWARE_NAME "esp32_4mb" #define FIRMWARE_NAME "esp32_4mb"
#endif #endif
#ifdef esp32_16mb
#define FIRMWARE_NAME "esp32_16mb"
#endif
#ifdef esp32s2_4mb #ifdef esp32s2_4mb
#define FIRMWARE_NAME "esp32s2_4mb" #define FIRMWARE_NAME "esp32s2_4mb"
#endif #endif

View File

@@ -14,6 +14,7 @@ boolean mqttConnect();
void mqttReconnect(); void mqttReconnect();
void mqttLoop(); void mqttLoop();
void mqttSubscribe(); void mqttSubscribe();
bool mqttIsConnect();
boolean publish(const String& topic, const String& data); boolean publish(const String& topic, const String& data);
boolean publishData(const String& topic, const String& data); boolean publishData(const String& topic, const String& data);
@@ -21,6 +22,7 @@ boolean publishChartMqtt(const String& topic, const String& data);
boolean publishJsonMqtt(const String& topic, const String& json); boolean publishJsonMqtt(const String& topic, const String& json);
boolean publishStatusMqtt(const String& topic, const String& data); boolean publishStatusMqtt(const String& topic, const String& data);
boolean publishEvent(const String& topic, const String& data); boolean publishEvent(const String& topic, const String& data);
void mqttSubscribeExternal(String topic, bool usePrefix);
bool publishChartFileToMqtt(String path, String id, int maxCount); bool publishChartFileToMqtt(String path, String id, int maxCount);

View File

@@ -15,6 +15,7 @@ extern bool jsonRead(const String& json, String key, float& value, bool e = true
extern bool jsonRead(const String& json, String key, String& value, bool e = true); extern bool jsonRead(const String& json, String key, String& value, bool e = true);
extern bool jsonRead(const String& json, String key, bool& value, bool e = true); extern bool jsonRead(const String& json, String key, bool& value, bool e = true);
extern bool jsonRead(const String& json, String key, int& value, bool e = true); extern bool jsonRead(const String& json, String key, int& value, bool e = true);
extern bool jsonReadArray(const String& json, String key, std::vector<String>& jArray, bool e = true);
extern String jsonReadStr(const String& json, String name, bool e = true); extern String jsonReadStr(const String& json, String name, bool e = true);
extern int jsonReadInt(const String& json, String name, bool e = true); extern int jsonReadInt(const String& json, String name, bool e = true);

View File

@@ -2,11 +2,11 @@
#include "Global.h" #include "Global.h"
#include "MqttClient.h" #include "MqttClient.h"
#include <vector>
// boolean isNetworkActive(); // boolean isNetworkActive();
inline boolean isNetworkActive() {return WiFi.status() == WL_CONNECTED;}; inline boolean isNetworkActive() {return WiFi.status() == WL_CONNECTED;};
void routerConnect(); void routerConnect();
bool startAPMode(); bool startAPMode();
boolean RouterFind(String ssid); boolean RouterFind(std::vector<String> jArray);
uint8_t RSSIquality(); uint8_t RSSIquality();
extern void wifiSignalInit(); extern void wifiSignalInit();

View File

@@ -3,8 +3,8 @@
"name": "IoTmanagerVer4", "name": "IoTmanagerVer4",
"apssid": "IoTmanager", "apssid": "IoTmanager",
"appass": "", "appass": "",
"routerssid": "iot", "routerssid": ["iot","wifi"],
"routerpass": "hostel3333", "routerpass": ["hostel3333","pswd"],
"timezone": 2, "timezone": 2,
"ntp": "pool.ntp.org", "ntp": "pool.ntp.org",
"weblogin": "admin", "weblogin": "admin",
@@ -32,6 +32,11 @@
"firmware": "0x00000", "firmware": "0x00000",
"littlefs": "0x300000" "littlefs": "0x300000"
}, },
{
"name": "esp8266_16mb",
"firmware": "0x00000",
"littlefs": "0x200000"
},
{ {
"name": "esp32_4mb", "name": "esp32_4mb",
"boot_app0": "0xe000", "boot_app0": "0xe000",
@@ -40,6 +45,14 @@
"partitions": "0x8000", "partitions": "0x8000",
"littlefs": "0x290000" "littlefs": "0x290000"
}, },
{
"name": "esp32_16mb",
"boot_app0": "0xe000",
"bootloader_qio_80m": "0x1000",
"firmware": "0x10000",
"partitions": "0x8000",
"littlefs": "0x910000"
},
{ {
"name": "esp8266_1mb", "name": "esp8266_1mb",
"firmware": "0x00000000", "firmware": "0x00000000",

View File

@@ -157,6 +157,28 @@ build_src_filter =
+<modules/*.cpp> +<modules/*.cpp>
${env:esp8266_4mb_fromitems.build_src_filter} ${env:esp8266_4mb_fromitems.build_src_filter}
[env:esp8266_16mb]
extra_scripts = pre:tools/patch8266_16m.py
lib_deps =
${common_env_data.lib_deps_external}
${env:esp8266_16mb_fromitems.lib_deps}
ESPAsyncUDP
build_flags = -Desp8266_16mb="esp8266_16mb"
framework = arduino
board = nodemcuv2
platform = espressif8266 @4.0.1
board_build.ldscript = eagle.flash.16m14m.ld
monitor_filters = esp8266_exception_decoder
upload_speed = 921600
monitor_speed = 115200
board_build.filesystem = littlefs
build_src_filter =
+<*.cpp>
+<classes/*.cpp>
+<utils/*.cpp>
+<modules/*.cpp>
${env:esp8266_16mb_fromitems.build_src_filter}
[env:esp32_4mb] [env:esp32_4mb]
lib_deps = lib_deps =
${common_env_data.lib_deps_external} ${common_env_data.lib_deps_external}
@@ -200,6 +222,29 @@ build_src_filter =
+<modules/*.cpp> +<modules/*.cpp>
${env:esp32s2_4mb_fromitems.build_src_filter} ${env:esp32s2_4mb_fromitems.build_src_filter}
[env:esp32_16mb]
lib_deps =
${common_env_data.lib_deps_external}
${env:esp32_16mb_fromitems.lib_deps}
build_flags = -Desp32_16mb="esp32_16mb"
framework = arduino
board = esp32dev
platform = espressif32 @5.1.1
monitor_filters = esp32_exception_decoder
upload_port = COM11
upload_speed = 921600
monitor_speed = 115200
debug_tool = esp-prog
board_build.partitions = tools/large_spiffs_16MB.csv
board_upload.flash_size = 16MB
board_build.filesystem = littlefs
build_src_filter =
+<*.cpp>
+<classes/*.cpp>
+<utils/*.cpp>
+<modules/*.cpp>
${env:esp32_16mb_fromitems.build_src_filter}
[env:esp8266_1mb_ota_fromitems] [env:esp8266_1mb_ota_fromitems]
lib_deps = lib_deps =
adafruit/Adafruit BME280 Library adafruit/Adafruit BME280 Library
@@ -526,3 +571,31 @@ build_src_filter =
+<modules/exec/Ftp> +<modules/exec/Ftp>
+<modules/exec/TelegramLT> +<modules/exec/TelegramLT>
[env:esp8266_16mb_fromitems]
lib_deps =
gyverlibs/EncButton @ ^2.0
build_src_filter =
+<modules/virtual/Cron>
+<modules/virtual/Loging>
+<modules/virtual/LogingDaily>
+<modules/virtual/Timer>
+<modules/virtual/Variable>
+<modules/virtual/VariableColor>
+<modules/virtual/VButton>
+<modules/exec/ButtonIn>
+<modules/exec/ButtonOut>
+<modules/exec/Enconder>
+<modules/exec/TelegramLT>
[env:esp32_16mb_fromitems]
lib_deps =
build_src_filter =
+<modules/virtual/Cron>
+<modules/virtual/Loging>
+<modules/virtual/LogingDaily>
+<modules/virtual/Timer>
+<modules/virtual/Variable>
+<modules/virtual/VButton>
+<modules/exec/ButtonOut>
+<modules/exec/TelegramLT>

View File

@@ -95,6 +95,10 @@ void mqttReconnect() {
mqttConnect(); mqttConnect();
} }
bool mqttIsConnect(){
return mqtt.connected();
}
void getMqttData() { void getMqttData() {
mqttServer = jsonReadStr(settingsFlashJson, F("mqttServer")); mqttServer = jsonReadStr(settingsFlashJson, F("mqttServer"));
mqttPort = jsonReadInt(settingsFlashJson, F("mqttPort")); mqttPort = jsonReadInt(settingsFlashJson, F("mqttPort"));
@@ -116,6 +120,16 @@ void mqttSubscribe() {
} }
} }
void mqttSubscribeExternal(String topic, bool usePrefix) {
SerialPrint("i", F("MQTT"), ("subscribed external" + topic).c_str());
// SerialPrint("i", F("MQTT"), mqttRootDevice);
if (usePrefix)
{
mqtt.subscribe((mqttPrefix + topic).c_str());
}
mqtt.subscribe(topic.c_str());
}
void mqttCallback(char* topic, uint8_t* payload, size_t length) { void mqttCallback(char* topic, uint8_t* payload, size_t length) {
String topicStr = String(topic); String topicStr = String(topic);
// SerialPrint("i", "=>MQTT", topicStr); // SerialPrint("i", "=>MQTT", topicStr);

View File

@@ -101,7 +101,7 @@ String ESP32GetResetReason(uint32_t cpu_no) {
} }
} }
#endif #endif
#ifdef esp32_4mb #if defined(esp32_4mb) || defined(esp32_16mb)
String ESP_getResetReason(void) { String ESP_getResetReason(void) {
return ESP32GetResetReason(0); // CPU 0 return ESP32GetResetReason(0); // CPU 0
} }

View File

@@ -74,7 +74,7 @@ bool upgradeBuild() {
handleUpdateStatus(true, PATH_ERROR); handleUpdateStatus(true, PATH_ERROR);
return ret; return ret;
} }
#if defined(esp8266_4mb) || defined(esp8266_1mb) || defined(esp8266_1mb_ota) || defined(esp8266_2mb) || defined(esp8266_2mb_ota) #if defined(esp8266_4mb) || defined(esp8266_16mb) || defined(esp8266_1mb) || defined(esp8266_1mb_ota) || defined(esp8266_2mb) || defined(esp8266_2mb_ota)
ESPhttpUpdate.rebootOnUpdate(false); ESPhttpUpdate.rebootOnUpdate(false);
t_httpUpdate_return retBuild = ESPhttpUpdate.update(wifiClient, getBinPath("firmware.bin")); t_httpUpdate_return retBuild = ESPhttpUpdate.update(wifiClient, getBinPath("firmware.bin"));
#endif #endif

View File

@@ -9,7 +9,8 @@ void standWebSocketsInit() {
SerialPrint("i", "WS", "WS server initialized"); SerialPrint("i", "WS", "WS server initialized");
} }
void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length) { void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload,
size_t length) {
switch (type) { switch (type) {
case WStype_ERROR: { case WStype_ERROR: {
Serial.printf("[%u] Error!\n", num); Serial.printf("[%u] Error!\n", num);
@@ -28,13 +29,15 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
standWebSocket.close(); standWebSocket.close();
standWebSocketsInit(); standWebSocketsInit();
} }
// Serial.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload); // Serial.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0],
// standWebSocket.sendTXT(num, "Connected"); // ip[1], ip[2], ip[3], payload); standWebSocket.sendTXT(num,
// "Connected");
} break; } break;
case WStype_TEXT: { case WStype_TEXT: {
bool endOfHeaderFound = false; bool endOfHeaderFound = false;
size_t maxAllowedHeaderSize = 15; // максимальное количество символов заголовка size_t maxAllowedHeaderSize =
15; // максимальное количество символов заголовка
size_t headerLenth = 0; size_t headerLenth = 0;
String headerStr; String headerStr;
for (size_t i = 0; i <= maxAllowedHeaderSize; i++) { for (size_t i = 0; i <= maxAllowedHeaderSize; i++) {
@@ -56,23 +59,27 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
// публикация всех виджетов // публикация всех виджетов
if (headerStr == "/|") { if (headerStr == "/|") {
sendFileToWsByFrames("/layout.json", "layout", "", num, WEB_SOCKETS_FRAME_SIZE); sendFileToWsByFrames("/layout.json", "layout", "", num,
WEB_SOCKETS_FRAME_SIZE);
} }
if (headerStr == "/params|") { if (headerStr == "/params|") {
// публикация всех статус сообщений при подключении svelte приложения // публикация всех статус сообщений при подключении svelte приложения
String params = "{}"; String params = "{}";
for (std::list<IoTItem*>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) { for (std::list<IoTItem*>::iterator it = IoTItems.begin();
it != IoTItems.end(); ++it) {
if ((*it)->getSubtype() != "Loging") { if ((*it)->getSubtype() != "Loging") {
if ((*it)->getSubtype() != "LogingDaily") { if ((*it)->getSubtype() != "LogingDaily") {
if ((*it)->iAmLocal) jsonWriteStr(params, (*it)->getID(), (*it)->getValue()); if ((*it)->iAmLocal)
jsonWriteStr(params, (*it)->getID(), (*it)->getValue());
} }
} }
} }
sendStringToWs("params", params, num); sendStringToWs("params", params, num);
// генерация события подключения в модулях // генерация события подключения в модулях
for (std::list<IoTItem*>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) { for (std::list<IoTItem*>::iterator it = IoTItems.begin();
it != IoTItems.end(); ++it) {
if ((*it)->iAmLocal) (*it)->onMqttWsAppConnectEvent(); if ((*it)->iAmLocal) (*it)->onMqttWsAppConnectEvent();
} }
} }
@@ -81,7 +88,8 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
if (headerStr == "/charts|") { if (headerStr == "/charts|") {
// обращение к логированию из ядра // обращение к логированию из ядра
// отправка данных графиков только в выбранный сокет // отправка данных графиков только в выбранный сокет
for (std::list<IoTItem*>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) { for (std::list<IoTItem*>::iterator it = IoTItems.begin();
it != IoTItems.end(); ++it) {
// сбрасываем даты графиков // сбрасываем даты графиков
// if ((*it)->getID().endsWith("-date")) { // if ((*it)->getID().endsWith("-date")) {
// (*it)->setTodayDate(); // (*it)->setTodayDate();
@@ -99,26 +107,34 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
// отвечаем данными на запрос страницы // отвечаем данными на запрос страницы
if (headerStr == "/config|") { if (headerStr == "/config|") {
sendFileToWsByFrames("/items.json", "itemsj", "", num, WEB_SOCKETS_FRAME_SIZE); sendFileToWsByFrames("/items.json", "itemsj", "", num,
sendFileToWsByFrames("/widgets.json", "widget", "", num, WEB_SOCKETS_FRAME_SIZE); WEB_SOCKETS_FRAME_SIZE);
sendFileToWsByFrames("/config.json", "config", "", num, WEB_SOCKETS_FRAME_SIZE); sendFileToWsByFrames("/widgets.json", "widget", "", num,
sendFileToWsByFrames("/scenario.txt", "scenar", "", num, WEB_SOCKETS_FRAME_SIZE); WEB_SOCKETS_FRAME_SIZE);
sendFileToWsByFrames("/config.json", "config", "", num,
WEB_SOCKETS_FRAME_SIZE);
sendFileToWsByFrames("/scenario.txt", "scenar", "", num,
WEB_SOCKETS_FRAME_SIZE);
sendStringToWs("settin", settingsFlashJson, num); sendStringToWs("settin", settingsFlashJson, num);
} }
// обработка кнопки сохранить // обработка кнопки сохранить
if (headerStr == "/gifnoc|") { if (headerStr == "/gifnoc|") {
writeFileUint8tByFrames("config.json", payload, length, headerLenth, 256); writeFileUint8tByFrames("config.json", payload, length, headerLenth,
256);
} }
if (headerStr == "/tuoyal|") { if (headerStr == "/tuoyal|") {
writeFileUint8tByFrames("layout.json", payload, length, headerLenth, 256); writeFileUint8tByFrames("layout.json", payload, length, headerLenth,
256);
} }
if (headerStr == "/oiranecs|") { if (headerStr == "/oiranecs|") {
writeFileUint8tByFrames("scenario.txt", payload, length, headerLenth, 256); writeFileUint8tByFrames("scenario.txt", payload, length, headerLenth,
256);
clearConfigure(); clearConfigure();
configure("/config.json"); configure("/config.json");
iotScen.loadScenario("/scenario.txt"); iotScen.loadScenario("/scenario.txt");
// создаем событие завершения конфигурирования для возможности выполнения блока кода при загрузке // создаем событие завершения конфигурирования для возможности
// выполнения блока кода при загрузке
createItemFromNet("onStart", "1", 1); createItemFromNet("onStart", "1", 1);
} }
@@ -131,14 +147,16 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
sendStringToWs("settin", settingsFlashJson, num); sendStringToWs("settin", settingsFlashJson, num);
sendStringToWs("ssidli", ssidListHeapJson, num); sendStringToWs("ssidli", ssidListHeapJson, num);
sendStringToWs("errors", errorsHeapJson, num); sendStringToWs("errors", errorsHeapJson, num);
// запуск асинхронного сканирования wifi сетей при переходе на страницу соединений // запуск асинхронного сканирования wifi сетей при переходе на страницу
// RouterFind(jsonReadStr(settingsFlashJson, F("routerssid"))); // соединений RouterFind(jsonReadStr(settingsFlashJson,
// F("routerssid")));
} }
// обработка кнопки сохранить settings.json // обработка кнопки сохранить settings.json
if (headerStr == "/sgnittes|") { if (headerStr == "/sgnittes|") {
writeUint8tToString(payload, length, headerLenth, settingsFlashJson); writeUint8tToString(payload, length, headerLenth, settingsFlashJson);
writeFileUint8tByFrames("settings.json", payload, length, headerLenth, 256); writeFileUint8tByFrames("settings.json", payload, length, headerLenth,
256);
sendStringToWs("errors", errorsHeapJson, num); sendStringToWs("errors", errorsHeapJson, num);
// если не было создано приема данных по udp - то создадим его // если не было создано приема данных по udp - то создадим его
addThisDeviceToList(); addThisDeviceToList();
@@ -146,16 +164,21 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
// обработка кнопки сохранить настройки mqtt // обработка кнопки сохранить настройки mqtt
if (headerStr == "/mqtt|") { if (headerStr == "/mqtt|") {
sendStringToWs("settin", settingsFlashJson, num); // отправляем в ответ новые полученные настройки sendStringToWs("settin", settingsFlashJson,
num); // отправляем в ответ новые полученные настройки
handleMqttStatus(false, 8); // меняем статус на неопределенный handleMqttStatus(false, 8); // меняем статус на неопределенный
mqttReconnect(); // начинаем переподключение mqttReconnect(); // начинаем переподключение
sendStringToWs("errors", errorsHeapJson, num); // отправляем что статус неопределен sendStringToWs("errors", errorsHeapJson,
num); // отправляем что статус неопределен
sendStringToWs("ssidli", ssidListHeapJson, num); sendStringToWs("ssidli", ssidListHeapJson, num);
} }
// запуск асинхронного сканирования wifi сетей при нажатии выпадающего списка // запуск асинхронного сканирования wifi сетей при нажатии выпадающего
// списка
if (headerStr == "/scan|") { if (headerStr == "/scan|") {
RouterFind(jsonReadStr(settingsFlashJson, F("routerssid"))); std::vector<String> jArray;
jsonReadArray(settingsFlashJson, "routerssid", jArray);
RouterFind(jArray);
sendStringToWs("ssidli", ssidListHeapJson, num); sendStringToWs("ssidli", ssidListHeapJson, num);
} }
@@ -170,7 +193,8 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
// sendDeviceList(num); // sendDeviceList(num);
} }
// отвечаем на запрос списка устройств (это отдельный запрос который делает приложение при подключении) // отвечаем на запрос списка устройств (это отдельный запрос который
// делает приложение при подключении)
if (headerStr == "/devlist|") { if (headerStr == "/devlist|") {
// отправим список устройств в зависимости от того что выбрал user // отправим список устройств в зависимости от того что выбрал user
sendDeviceList(num); sendDeviceList(num);
@@ -178,7 +202,8 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
// сохраняем данные листа // сохраняем данные листа
if (headerStr == "/tsil|") { if (headerStr == "/tsil|") {
writeFileUint8tByFrames("devlist.json", payload, length, headerLenth, 256); writeFileUint8tByFrames("devlist.json", payload, length, headerLenth,
256);
} }
//----------------------------------------------------------------------// //----------------------------------------------------------------------//
@@ -197,9 +222,12 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
if (headerStr == "/dev|") { if (headerStr == "/dev|") {
sendStringToWs("errors", errorsHeapJson, num); sendStringToWs("errors", errorsHeapJson, num);
sendStringToWs("settin", settingsFlashJson, num); sendStringToWs("settin", settingsFlashJson, num);
sendFileToWsByFrames("/config.json", "config", "", num, WEB_SOCKETS_FRAME_SIZE); sendFileToWsByFrames("/config.json", "config", "", num,
sendFileToWsByFrames("/items.json", "itemsj", "", num, WEB_SOCKETS_FRAME_SIZE); WEB_SOCKETS_FRAME_SIZE);
// sendFileToWsByFrames("/layout.json", "layout", "", num, WEB_SOCKETS_FRAME_SIZE); sendFileToWsByFrames("/items.json", "itemsj", "", num,
WEB_SOCKETS_FRAME_SIZE);
// sendFileToWsByFrames("/layout.json", "layout", "", num,
// WEB_SOCKETS_FRAME_SIZE);
} }
if (headerStr == "/test|") { if (headerStr == "/test|") {
@@ -211,7 +239,8 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
// переписать любое поле в errors json // переписать любое поле в errors json
if (headerStr == "/rorre|") { if (headerStr == "/rorre|") {
writeUint8tValueToJsonString(payload, length, headerLenth, errorsHeapJson); writeUint8tValueToJsonString(payload, length, headerLenth,
errorsHeapJson);
} }
// команда перезагрузки esp // команда перезагрузки esp
@@ -236,7 +265,9 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
String key = selectFromMarkerToMarker(msg, "/", 0); String key = selectFromMarkerToMarker(msg, "/", 0);
String value = selectFromMarkerToMarker(msg, "/", 1); String value = selectFromMarkerToMarker(msg, "/", 1);
generateOrder(key, value); generateOrder(key, value);
SerialPrint("i", F("=>WS"), "Msg from svelte web, WS No: " + String(num) + ", msg: " + msg); SerialPrint(
"i", F("=>WS"),
"Msg from svelte web, WS No: " + String(num) + ", msg: " + msg);
} }
if (headerStr == "/tst|") { if (headerStr == "/tst|") {
@@ -255,7 +286,8 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
SerialPrint("i", F("=>WS"), "Msg from module, id: " + id); SerialPrint("i", F("=>WS"), "Msg from module, id: " + id);
for (std::list<IoTItem*>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) { for (std::list<IoTItem*>::iterator it = IoTItems.begin();
it != IoTItems.end(); ++it) {
if ((*it)->getID() == id) { if ((*it)->getID() == id) {
(*it)->onModuleOrder(key, value); (*it)->onModuleOrder(key, value);
} }
@@ -294,13 +326,12 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
Serial.printf("[%u] pong: %u\n", num, length); Serial.printf("[%u] pong: %u\n", num, length);
} break; } break;
default: { default: { Serial.printf("[%u] not recognized: %u\n", num, length); } break;
Serial.printf("[%u] not recognized: %u\n", num, length);
} break;
} }
} }
// публикация статус сообщений в ws (недостаток в том что делаем бродкаст всем клиентам поднятым в свелте!!!) // публикация статус сообщений в ws (недостаток в том что делаем бродкаст всем
// клиентам поднятым в свелте!!!)
void publishStatusWs(const String& topic, const String& data) { void publishStatusWs(const String& topic, const String& data) {
String path = mqttRootDevice + "/" + topic; String path = mqttRootDevice + "/" + topic;
String json = "{}"; String json = "{}";
@@ -330,7 +361,8 @@ void periodicWsSend() {
#ifdef ESP32 #ifdef ESP32
void hexdump(const void* mem, uint32_t len, uint8_t cols = 16) { void hexdump(const void* mem, uint32_t len, uint8_t cols = 16) {
const uint8_t* src = (const uint8_t*)mem; const uint8_t* src = (const uint8_t*)mem;
Serial.printf("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)", (ptrdiff_t)src, len, len); Serial.printf("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)", (ptrdiff_t)src,
len, len);
for (uint32_t i = 0; i < len; i++) { for (uint32_t i = 0; i < len; i++) {
if (i % cols == 0) { if (i % cols == 0) {
Serial.printf("\n[0x%08X] 0x%08X: ", (ptrdiff_t)src, i); Serial.printf("\n[0x%08X] 0x%08X: ", (ptrdiff_t)src, i);
@@ -343,7 +375,8 @@ void hexdump(const void* mem, uint32_t len, uint8_t cols = 16) {
#endif #endif
#endif #endif
void sendFileToWsByFrames(const String& filename, const String& header, const String& json, int client_id, size_t frameSize) { void sendFileToWsByFrames(const String& filename, const String& header,
const String& json, int client_id, size_t frameSize) {
if (header.length() != 6) { if (header.length() != 6) {
SerialPrint("E", "FS", F("wrong header size")); SerialPrint("E", "FS", F("wrong header size"));
return; return;
@@ -357,7 +390,8 @@ void sendFileToWsByFrames(const String& filename, const String& header, const St
} }
size_t totalSize = file.size(); size_t totalSize = file.size();
// Serial.println("Send file '" + String(filename) + "', file size: " + String(totalSize)); // Serial.println("Send file '" + String(filename) + "', file size: " +
// String(totalSize));
char buf[32]; char buf[32];
sprintf(buf, "%04d", json.length() + 12); sprintf(buf, "%04d", json.length() + 12);
@@ -397,7 +431,9 @@ void sendFileToWsByFrames(const String& filename, const String& header, const St
continuation = true; continuation = true;
} }
// Serial.println(String(i) + ") " + "ws: " + String(client_id) + " fr sz: " + String(size) + " fin: " + String(fin) + " cnt: " + String(continuation)); // Serial.println(String(i) + ") " + "ws: " + String(client_id) + " fr sz:
// " + String(size) + " fin: " + String(fin) + " cnt: " +
// String(continuation));
if (client_id == -1) { if (client_id == -1) {
standWebSocket.broadcastBIN(frameBuf, size, fin, continuation); standWebSocket.broadcastBIN(frameBuf, size, fin, continuation);
@@ -442,7 +478,8 @@ void sendDeviceList(uint8_t num) {
sendStringToWs("devlis", devListHeapJson, num); sendStringToWs("devlis", devListHeapJson, num);
} else { } else {
// если выключен автопоиск то отдаем список из флешь памяти // если выключен автопоиск то отдаем список из флешь памяти
sendFileToWsByFrames("/devlist.json", "devlis", "", num, WEB_SOCKETS_FRAME_SIZE); sendFileToWsByFrames("/devlist.json", "devlis", "", num,
WEB_SOCKETS_FRAME_SIZE);
SerialPrint("i", "FS", "flash list"); SerialPrint("i", "FS", "flash list");
} }
} }

View File

@@ -341,7 +341,8 @@ enum SysOp {
sysop_getRSSI, sysop_getRSSI,
sysop_getIP, sysop_getIP,
sysop_mqttPub, sysop_mqttPub,
sysop_getUptime sysop_getUptime,
sysop_mqttIsConnect
}; };
IoTValue sysExecute(SysOp command, std::vector<IoTValue> &param) { IoTValue sysExecute(SysOp command, std::vector<IoTValue> &param) {
@@ -442,6 +443,9 @@ IoTValue sysExecute(SysOp command, std::vector<IoTValue> &param) {
value.valS = jsonReadStr(errorsHeapJson, F("upt")); value.valS = jsonReadStr(errorsHeapJson, F("upt"));
value.isDecimal = false; value.isDecimal = false;
break; break;
case sysop_mqttIsConnect:
value.valD = mqttIsConnect();
break;
} }
return value; return value;
@@ -496,6 +500,8 @@ class SysCallExprAST : public ExprAST {
operation = sysop_getTime; operation = sysop_getTime;
else if (Callee == F("getUptime")) else if (Callee == F("getUptime"))
operation = sysop_getUptime; operation = sysop_getUptime;
else if (Callee == F("mqttIsConnect"))
operation = sysop_mqttIsConnect;
else else
operation = sysop_notfound; operation = sysop_notfound;
} }

View File

@@ -104,35 +104,43 @@
"usedLibs": { "usedLibs": {
"esp32_4mb": [ "esp32_4mb": [
"https://github.com/maxint-rd/TM16xx", "https://github.com/maxint-rd/TM16xx",
"adafruit/Adafruit GFX Library @ ^1.11.5" "adafruit/Adafruit GFX Library @ ^1.11.5",
"adafruit/Adafruit BusIO @ ^1.13.2"
], ],
"esp8266_4mb": [ "esp8266_4mb": [
"https://github.com/maxint-rd/TM16xx", "https://github.com/maxint-rd/TM16xx",
"adafruit/Adafruit GFX Library @ ^1.11.5" "adafruit/Adafruit GFX Library @ ^1.11.5",
"adafruit/Adafruit BusIO @ ^1.13.2"
], ],
"esp8266_1mb": [ "esp8266_1mb": [
"https://github.com/maxint-rd/TM16xx", "https://github.com/maxint-rd/TM16xx",
"adafruit/Adafruit GFX Library @ ^1.11.5" "adafruit/Adafruit GFX Library @ ^1.11.5",
"adafruit/Adafruit BusIO @ ^1.13.2"
], ],
"esp8266_1mb_ota": [ "esp8266_1mb_ota": [
"https://github.com/maxint-rd/TM16xx", "https://github.com/maxint-rd/TM16xx",
"adafruit/Adafruit GFX Library @ ^1.11.5" "adafruit/Adafruit GFX Library @ ^1.11.5",
"adafruit/Adafruit BusIO @ ^1.13.2"
], ],
"esp8285_1mb": [ "esp8285_1mb": [
"https://github.com/maxint-rd/TM16xx", "https://github.com/maxint-rd/TM16xx",
"adafruit/Adafruit GFX Library @ ^1.11.5" "adafruit/Adafruit GFX Library @ ^1.11.5",
"adafruit/Adafruit BusIO @ ^1.13.2"
], ],
"esp8285_1mb_ota": [ "esp8285_1mb_ota": [
"https://github.com/maxint-rd/TM16xx", "https://github.com/maxint-rd/TM16xx",
"adafruit/Adafruit GFX Library @ ^1.11.5" "adafruit/Adafruit GFX Library @ ^1.11.5",
"adafruit/Adafruit BusIO @ ^1.13.2"
], ],
"esp8266_2mb": [ "esp8266_2mb": [
"https://github.com/maxint-rd/TM16xx", "https://github.com/maxint-rd/TM16xx",
"adafruit/Adafruit GFX Library @ ^1.11.5" "adafruit/Adafruit GFX Library @ ^1.11.5",
"adafruit/Adafruit BusIO @ ^1.13.2"
], ],
"esp8266_2mb_ota": [ "esp8266_2mb_ota": [
"https://github.com/maxint-rd/TM16xx", "https://github.com/maxint-rd/TM16xx",
"adafruit/Adafruit GFX Library @ ^1.11.5" "adafruit/Adafruit GFX Library @ ^1.11.5",
"adafruit/Adafruit BusIO @ ^1.13.2"
] ]
} }
} }

View File

@@ -46,7 +46,10 @@
"defActive": true, "defActive": true,
"usedLibs": { "usedLibs": {
"esp32_4mb": [], "esp32_4mb": [],
"esp32_16mb": [],
"esp32s2_4mb": [],
"esp8266_4mb": [], "esp8266_4mb": [],
"esp8266_16mb": [],
"esp8266_1mb": [], "esp8266_1mb": [],
"esp8266_1mb_ota": [], "esp8266_1mb_ota": [],
"esp8285_1mb": [], "esp8285_1mb": [],

View File

@@ -45,7 +45,10 @@
"defActive": true, "defActive": true,
"usedLibs": { "usedLibs": {
"esp32_4mb": [], "esp32_4mb": [],
"esp32_16mb": [],
"esp32s2_4mb": [],
"esp8266_4mb": [], "esp8266_4mb": [],
"esp8266_16mb": [],
"esp8266_1mb": [], "esp8266_1mb": [],
"esp8266_1mb_ota": [], "esp8266_1mb_ota": [],
"esp8285_1mb": [], "esp8285_1mb": [],

View File

@@ -49,6 +49,9 @@
"esp8266_4mb": [ "esp8266_4mb": [
"gyverlibs/EncButton @ ^2.0" "gyverlibs/EncButton @ ^2.0"
], ],
"esp8266_16mb": [
"gyverlibs/EncButton @ ^2.0"
],
"esp8266_1mb": [ "esp8266_1mb": [
"gyverlibs/EncButton @ ^2.0" "gyverlibs/EncButton @ ^2.0"
], ],

View File

@@ -35,7 +35,9 @@
"defActive": false, "defActive": false,
"usedLibs": { "usedLibs": {
"esp32_4mb": [], "esp32_4mb": [],
"esp32_16mb": [],
"esp32s2_4mb": [], "esp32s2_4mb": [],
"esp8266_4mb": [] "esp8266_4mb": [],
"esp8266_16mb": []
} }
} }

View File

@@ -58,6 +58,9 @@
"esp32_4mb": [ "esp32_4mb": [
"CTBot @2.1.9" "CTBot @2.1.9"
], ],
"esp32_16mb": [
"CTBot @2.1.9"
],
"esp8266_4mb": [ "esp8266_4mb": [
"CTBot @2.1.9" "CTBot @2.1.9"
] ]

View File

@@ -52,8 +52,10 @@
"defActive": true, "defActive": true,
"usedLibs": { "usedLibs": {
"esp32_4mb": [], "esp32_4mb": [],
"esp32_16mb": [],
"esp32s2_4mb": [], "esp32s2_4mb": [],
"esp8266_4mb": [], "esp8266_4mb": [],
"esp8266_16mb": [],
"esp8266_1mb": [], "esp8266_1mb": [],
"esp8266_1mb_ota": [], "esp8266_1mb_ota": [],
"esp8285_1mb": [], "esp8285_1mb": [],

View File

@@ -69,6 +69,11 @@
"descr": "Отправить значение в топик MQTT", "descr": "Отправить значение в топик MQTT",
"params": ["Топик", "Значение"] "params": ["Топик", "Значение"]
}, },
{
"name": "mqttIsConnect",
"descr": "Получить состояние подключения к MQTT",
"params": []
},
{ {
"name": "getHours", "name": "getHours",
"descr": "Получить текущее число часов. Если время не получено из сети Интернет или внешнего RTC, то условие пропускается", "descr": "Получить текущее число часов. Если время не получено из сети Интернет или внешнего RTC, то условие пропускается",

View File

@@ -7,8 +7,8 @@
#include "Global.h" #include "Global.h"
#include "classes/IoTItem.h" #include "classes/IoTItem.h"
//!Здесь подключаем стороннюю библиотеку при необходимости (ExternalLibrary заменить) //! Здесь подключаем стороннюю библиотеку при необходимости (ExternalLibrary заменить)
//#include <ExternalLibrary.h> // #include <ExternalLibrary.h>
#include "ExternalLibrary.h" //удалить, только для примера. Внешние библиотеки правильно в <> #include "ExternalLibrary.h" //удалить, только для примера. Внешние библиотеки правильно в <>
//! Объяевляем класс IoTGpio для работы с GPIO //! Объяевляем класс IoTGpio для работы с GPIO
@@ -25,9 +25,15 @@ ExternalLibrary *libXX = nullptr;
// Функция инициализации библиотечного класса, возвращает Единстрвенный указать на библиотеку // Функция инициализации библиотечного класса, возвращает Единстрвенный указать на библиотеку
// instanceLibXX НАЗВАТЬ по наименованию модуля (instanceДатчикХ) // instanceLibXX НАЗВАТЬ по наименованию модуля (instanceДатчикХ)
// ПРИ НЕОБХДИМОСТИ передаем любые нужные параметры для инициализации библиотеки (в данном случае PIN) // ПРИ НЕОБХДИМОСТИ передаем любые нужные параметры для инициализации библиотеки (в данном случае PIN)
//
// !!! ВЫзвать данную функцию нужно хотябы один раз, // !!! ВЫзвать данную функцию нужно хотябы один раз,
// но в каждом конструкторе класса модуля ExampleModule_A, ExampleModule_B и т.д. // но в каждом конструкторе класса модуля ExampleModule_A, ExampleModule_B и т.д.
// или можно вывывать постоянно при обращении к библиотеке, типа: instanceLibXX().READ_LIB_DATA_OTHER(); // или можно вывывать постоянно при обращении к библиотеке, типа: instanceLibXX().READ_LIB_DATA_OTHER();
//
// !!!!!! В деструкторах ~ExampleModule_B() и ~ExampleModule_A() надо УДАЛЯТЬ объект libXX, ЕСЛИ в функцию instanceLibXX чтото передается.
// Удаляем класс библиотеки, а то при переконфигурации в нем не поменяются PIN и дугие параметры передаваемые в библиотеку.
// P.S. Не для всех, если используется map или vector то лучше не надо.
ExternalLibrary *instanceLibXX(int pin) ExternalLibrary *instanceLibXX(int pin)
{ {
if (!libXX) if (!libXX)
@@ -39,7 +45,6 @@ ExternalLibrary *instanceLibXX(int pin)
return libXX; return libXX;
} }
//========================================================================================================= //=========================================================================================================
//========================================================================================================= //=========================================================================================================
// Первый класс модуля для определения 1-го элемента (параметра) // Первый класс модуля для определения 1-го элемента (параметра)
@@ -69,7 +74,7 @@ public:
// jsonReadStr, jsonReadBool, jsonReadInt // jsonReadStr, jsonReadBool, jsonReadInt
ExampleModule_A(String parameters) : IoTItem(parameters) ExampleModule_A(String parameters) : IoTItem(parameters)
{ {
//Читаем пользовательскую переменную PIN, должна быть объявлена в в modeinfo.json // Читаем пользовательскую переменную PIN, должна быть объявлена в в modeinfo.json
_pin = jsonReadInt(parameters, "pin"); _pin = jsonReadInt(parameters, "pin");
// другой вариант чтения парметров модуля // другой вариант чтения парметров модуля
jsonRead(parameters, F("int"), _interval, false); jsonRead(parameters, F("int"), _interval, false);
@@ -111,7 +116,12 @@ public:
} }
} }
~ExampleModule_A(){}; ~ExampleModule_A()
{
// Удаляем класс библиотеки, а то при переконфигурации в нем не поменяются PIN и дугие параметры передаваемые в библиотеку.
delete libXX;
libXX = nullptr;
};
}; };
//========================================================================================================= //=========================================================================================================
@@ -126,14 +136,15 @@ public:
class ExampleModule_B : public IoTItem class ExampleModule_B : public IoTItem
{ {
private: private:
//Пользовательские переменные // Пользовательские переменные
unsigned int _pin; unsigned int _pin;
public: public:
ExampleModule_B(String parameters) : IoTItem(parameters) ExampleModule_B(String parameters) : IoTItem(parameters)
{ {
//Читаем пользовательскую переменную PIN, должна быть объявлена в в modeinfo.json // Читаем пользовательскую переменную PIN, должна быть объявлена в в modeinfo.json
_pin = jsonReadInt(parameters, "pin"); _pin = jsonReadInt(parameters, "pin");
//Можно инициализировать библиотеку один раз, а потом используем указатель // Можно инициализировать библиотеку один раз, а потом используем указатель
instanceLibXX(_pin); instanceLibXX(_pin);
libXX->READ_LIB_DATA_OTHER(); libXX->READ_LIB_DATA_OTHER();
} }
@@ -146,7 +157,7 @@ public:
regEvent(value.valD, "ExampleModule"); // обязательный вызов хотяб один для регистрации события в ядре IoTM regEvent(value.valD, "ExampleModule"); // обязательный вызов хотяб один для регистрации события в ядре IoTM
} }
//================ обработка кнопок из конфигурации =================== //================ обработка кнопок из конфигурации ===================
// Хук (переопределение виртуальной функции) для обработки кнопки (в value будут данные с собственной панели ввода) // Хук (переопределение виртуальной функции) для обработки кнопки (в value будут данные с собственной панели ввода)
// Что бы кнопка была без поля ввода, нужно в modeinfo.json указать "btn-Example": nil // Что бы кнопка была без поля ввода, нужно в modeinfo.json указать "btn-Example": nil
void onModuleOrder(String &key, String &value) void onModuleOrder(String &key, String &value)
@@ -158,7 +169,7 @@ public:
} }
} }
//================ обработка команд из сценария=================== //================ обработка команд из сценария===================
// Хук (переопределение виртуальной функции) для обработки команды из сценария (в param будут даныые переданные в функции в сценарии) // Хук (переопределение виртуальной функции) для обработки команды из сценария (в param будут даныые переданные в функции в сценарии)
IoTValue execute(String command, std::vector<IoTValue> &param) IoTValue execute(String command, std::vector<IoTValue> &param)
{ {
@@ -204,10 +215,14 @@ public:
// Прсото пример кокой-то функции // Прсото пример кокой-то функции
} }
~ExampleModule_B(){}; ~ExampleModule_B()
{
// Удаляем класс библиотеки, а то при переконфигурации в нем не поменяются PIN и дугие параметры передаваемые в библиотеку.
delete libXX;
libXX = nullptr;
};
}; };
//========================================================================================================= //=========================================================================================================
//========================================================================================================= //=========================================================================================================
// Функция для связи модуля с ядром IoTM // Функция для связи модуля с ядром IoTM

View File

@@ -13,16 +13,24 @@ private:
int red = 0; int red = 0;
int offline = 0; int offline = 0;
bool dataFromNode = false; bool dataFromNode = false;
String _topic = "";
bool _isJson;
bool _addPrefix;
bool _debug;
public: public:
ExternalMQTT(String parameters) : IoTItem(parameters) ExternalMQTT(String parameters) : IoTItem(parameters)
{ {
_MAC = jsonReadStr(parameters, "MAC");
_sensor = jsonReadStr(parameters, "sensor"); _sensor = jsonReadStr(parameters, "sensor");
jsonRead(parameters, F("orange"), orange); jsonRead(parameters, F("orange"), orange);
jsonRead(parameters, F("red"), red); jsonRead(parameters, F("red"), red);
jsonRead(parameters, F("offline"), offline); jsonRead(parameters, F("offline"), offline);
_topic = jsonReadStr(parameters, "topic");
_isJson = jsonReadBool(parameters, "isJson");
_addPrefix = jsonReadBool(parameters, "addPrefix");
_debug = jsonReadBool(parameters, "debug");
dataFromNode = false; dataFromNode = false;
mqttSubscribeExternal(_topic, _addPrefix);
} }
char *TimeToString(unsigned long t) char *TimeToString(unsigned long t)
{ {
@@ -38,16 +46,20 @@ public:
{ {
if (msg.indexOf("HELLO") == -1) if (msg.indexOf("HELLO") == -1)
{ {
if (_debug)
// SerialPrint("i", "onMqttRecive", "Прилетело " + topic); {
SerialPrint("i", "onMqttRecive", "Прилетело " + topic + " msg: " + msg);
// SerialPrint("i", "onMqttRecive", "Прилетело " + msg); // SerialPrint("i", "onMqttRecive", "Прилетело " + msg);
}
String dev = selectToMarkerLast(topic, "/"); String dev = selectToMarkerLast(topic, "/");
dev.toUpperCase(); dev.toUpperCase();
dev.replace(":", ""); dev.replace(":", "");
if (_MAC == "") if (_topic != topic)
{ {
SerialPrint("i", "onMqttRecive", dev + " --> " + msg); return;
} }
if (_isJson)
{
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
DeserializationError error = deserializeJson(doc, msg); DeserializationError error = deserializeJson(doc, msg);
if (error) if (error)
@@ -60,7 +72,11 @@ public:
{ {
String key = kv.key().c_str(); String key = kv.key().c_str();
String val = kv.value(); String val = kv.value();
if (_MAC == dev && _sensor == key) if (_debug)
{
SerialPrint("i", "onMqttRecive", "Прилетело MAC: " + dev + " key=" + key + " val=" + val);
}
if (_sensor == key)
{ {
dataFromNode = true; dataFromNode = true;
_minutesPassed = 0; _minutesPassed = 0;
@@ -72,6 +88,18 @@ public:
// Serial.println("Value: " + val); // Serial.println("Value: " + val);
} }
} }
else
{
if (_debug)
{
SerialPrint("i", "onMqttRecive", "Прилетело MAC: " + dev + " val=" + msg);
}
dataFromNode = true;
_minutesPassed = 0;
setValue(msg);
// setNewWidgetAttributes();
}
}
} }
void doByInterval() void doByInterval()
@@ -116,7 +144,22 @@ public:
} }
sendSubWidgetsValues(_id, json); sendSubWidgetsValues(_id, json);
} }
/*
IoTValue execute(String command, std::vector<IoTValue> &param)
{
if (command == "mqttSubscribe")
{
if (param.size() == 2)
{
if (!param[0].isDecimal && param[1].isDecimal)
{
mqttSubscribeExternal(param[0].valS, (bool)param[0].valD);
}
}
}
return {};
}
*/
~ExternalMQTT(){}; ~ExternalMQTT(){};
}; };

View File

@@ -10,13 +10,16 @@
"widget": "", "widget": "",
"page": "", "page": "",
"descr": "", "descr": "",
"MAC": "",
"sensor": "", "sensor": "",
"topic": "",
"addPrefix": 0,
"isJson": 1,
"round": "", "round": "",
"orange": 60, "orange": 60,
"red": 120, "red": 120,
"offline": 180, "offline": 180,
"int": 60 "int": 60,
"debug": 0
} }
], ],
"about": { "about": {
@@ -25,7 +28,7 @@
"authorGit": "https://github.com/avaksru", "authorGit": "https://github.com/avaksru",
"specialThanks": "", "specialThanks": "",
"moduleName": "ExternalMQTT", "moduleName": "ExternalMQTT",
"moduleVersion": "1", "moduleVersion": "1.2",
"usedRam": { "usedRam": {
"esp32_4mb": 15, "esp32_4mb": 15,
"esp8266_4mb": 15 "esp8266_4mb": 15
@@ -38,13 +41,18 @@
"orange": "количество минут после которого окрасить виджет в оранжевый цвет", "orange": "количество минут после которого окрасить виджет в оранжевый цвет",
"red": "количество минут после которого окрасить виджет в красный цвет", "red": "количество минут после которого окрасить виджет в красный цвет",
"offline": "количество минут после которого отобразить что устройство offline, если все три orange red и offline поставить в ноль - то функция окраски выключится", "offline": "количество минут после которого отобразить что устройство offline, если все три orange red и offline поставить в ноль - то функция окраски выключится",
"MAC": "MAC адрес беспроводного датчика", "sensor": "Тип сенсора: температура / влажность / время / ... Он же ключ в json пакете ",
"sensor": "Тип сенсора: температура / влажность / время / ... " "topic":"Подписаться на произвольный топик (полный путь), в модуле данный топик буде проверяться с отправителем, например homed/fd/zigbee/temp",
"addPrefix":"1 (число), будет добавлен стандартный префикс из настроек, 0 - не добавлять префикс",
"isJson":"1 - ожидаем в топике json, 0 - в топике просто значение (при 0 поле sensor заполнять не требуется)",
"debug":"1 - выводить дополнительный лог в сериал"
} }
}, },
"defActive": false, "defActive": false,
"usedLibs": { "usedLibs": {
"esp32_4mb": [], "esp32_4mb": [],
"esp32s2_4mb": [],
"esp8266_4mb": [], "esp8266_4mb": [],
"esp8266_1mb": [], "esp8266_1mb": [],
"esp8266_1mb_ota": [], "esp8266_1mb_ota": [],

View File

@@ -235,7 +235,11 @@ public:
} }
} }
} }
~ld2410m(){}; ~ld2410m()
{
delete ld2410;
radar = nullptr;
};
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -291,7 +295,11 @@ public:
} }
} }
~ld2410t(){}; ~ld2410t()
{
delete ld2410;
radar = nullptr;
};
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -346,7 +354,11 @@ public:
} }
} }
} }
~ld2410d(){}; ~ld2410d()
{
delete ld2410;
radar = nullptr;
};
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -404,7 +416,11 @@ public:
} }
} }
} }
~ld2410e(){}; ~ld2410e()
{
delete ld2410;
radar = nullptr;
};
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void *getAPI_ld2410(String subtype, String param) void *getAPI_ld2410(String subtype, String param)

View File

@@ -50,8 +50,10 @@
"defActive": true, "defActive": true,
"usedLibs": { "usedLibs": {
"esp32_4mb": [], "esp32_4mb": [],
"esp32_16mb": [],
"esp32s2_4mb": [], "esp32s2_4mb": [],
"esp8266_4mb": [], "esp8266_4mb": [],
"esp8266_16mb": [],
"esp8266_1mb": [], "esp8266_1mb": [],
"esp8266_1mb_ota": [], "esp8266_1mb_ota": [],
"esp8285_1mb": [], "esp8285_1mb": [],

View File

@@ -51,8 +51,10 @@
"defActive": true, "defActive": true,
"usedLibs": { "usedLibs": {
"esp32_4mb": [], "esp32_4mb": [],
"esp32_16mb": [],
"esp32s2_4mb": [], "esp32s2_4mb": [],
"esp8266_4mb": [], "esp8266_4mb": [],
"esp8266_16mb": [],
"esp8266_1mb": [], "esp8266_1mb": [],
"esp8266_1mb_ota": [], "esp8266_1mb_ota": [],
"esp8285_1mb": [], "esp8285_1mb": [],

View File

@@ -44,8 +44,10 @@
"defActive": true, "defActive": true,
"usedLibs": { "usedLibs": {
"esp32_4mb": [], "esp32_4mb": [],
"esp32_16mb": [],
"esp32s2_4mb": [], "esp32s2_4mb": [],
"esp8266_4mb": [], "esp8266_4mb": [],
"esp8266_16mb": [],
"esp8266_1mb": [], "esp8266_1mb": [],
"esp8266_1mb_ota": [], "esp8266_1mb_ota": [],
"esp8285_1mb": [], "esp8285_1mb": [],

View File

@@ -74,8 +74,10 @@
"defActive": true, "defActive": true,
"usedLibs": { "usedLibs": {
"esp32_4mb": [], "esp32_4mb": [],
"esp32_16mb": [],
"esp32s2_4mb": [], "esp32s2_4mb": [],
"esp8266_4mb": [], "esp8266_4mb": [],
"esp8266_16mb": [],
"esp8266_1mb": [], "esp8266_1mb": [],
"esp8266_1mb_ota": [], "esp8266_1mb_ota": [],
"esp8285_1mb": [], "esp8285_1mb": [],

View File

@@ -36,8 +36,10 @@
"defActive": true, "defActive": true,
"usedLibs": { "usedLibs": {
"esp32_4mb": [], "esp32_4mb": [],
"esp32_16mb": [],
"esp32s2_4mb": [], "esp32s2_4mb": [],
"esp8266_4mb": [], "esp8266_4mb": [],
"esp8266_16mb": [],
"esp8266_1mb": [], "esp8266_1mb": [],
"esp8266_1mb_ota": [], "esp8266_1mb_ota": [],
"esp8285_1mb": [], "esp8285_1mb": [],

View File

@@ -96,8 +96,10 @@
"defActive": true, "defActive": true,
"usedLibs": { "usedLibs": {
"esp32_4mb": [], "esp32_4mb": [],
"esp32_16mb": [],
"esp32s2_4mb": [], "esp32s2_4mb": [],
"esp8266_4mb": [], "esp8266_4mb": [],
"esp8266_16mb": [],
"esp8266_1mb": [], "esp8266_1mb": [],
"esp8266_1mb_ota": [], "esp8266_1mb_ota": [],
"esp8285_1mb": [], "esp8285_1mb": [],

View File

@@ -35,8 +35,10 @@
"defActive": true, "defActive": true,
"usedLibs": { "usedLibs": {
"esp32_4mb": [], "esp32_4mb": [],
"esp32_16mb": [],
"esp32s2_4mb": [], "esp32s2_4mb": [],
"esp8266_4mb": [], "esp8266_4mb": [],
"esp8266_16mb": [],
"esp8266_1mb": [], "esp8266_1mb": [],
"esp8266_1mb_ota": [], "esp8266_1mb_ota": [],
"esp8285_1mb": [], "esp8285_1mb": [],

View File

@@ -40,8 +40,10 @@
"defActive": false, "defActive": false,
"usedLibs": { "usedLibs": {
"esp32_4mb": [], "esp32_4mb": [],
"esp32_16mb": [],
"esp32s2_4mb": [], "esp32s2_4mb": [],
"esp8266_4mb": [], "esp8266_4mb": [],
"esp8266_16mb": [],
"esp8266_1mb": [], "esp8266_1mb": [],
"esp8266_1mb_ota": [], "esp8266_1mb_ota": [],
"esp8285_1mb": [], "esp8285_1mb": [],

View File

@@ -2,26 +2,34 @@
#include "utils/FileUtils.h" #include "utils/FileUtils.h"
// new================================================================================ // new================================================================================
String jsonReadStrDoc(DynamicJsonDocument& doc, String name) { String jsonReadStrDoc(DynamicJsonDocument &doc, String name)
{
return doc[name].as<String>(); return doc[name].as<String>();
} }
void jsonWriteStrDoc(DynamicJsonDocument& doc, String name, String value) { void jsonWriteStrDoc(DynamicJsonDocument &doc, String name, String value)
{
doc[name] = value; doc[name] = value;
} }
// new============================================================================== // new==============================================================================
bool jsonRead(const String& json, String key, long& value, bool e) { bool jsonRead(const String &json, String key, long &value, bool e)
{
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
DeserializationError error = deserializeJson(doc, json); DeserializationError error = deserializeJson(doc, json);
if (error) { if (error)
if (e) { {
if (e)
{
SerialPrint("E", F("jsonRead"), error.f_str()); SerialPrint("E", F("jsonRead"), error.f_str());
jsonErrorDetected(); jsonErrorDetected();
} }
return false; return false;
} else if (!doc.containsKey(key)) { }
if (e) { else if (!doc.containsKey(key))
{
if (e)
{
SerialPrint("E", F("jsonRead"), key + " missing in " + json); SerialPrint("E", F("jsonRead"), key + " missing in " + json);
jsonErrorDetected(); jsonErrorDetected();
} }
@@ -31,17 +39,23 @@ bool jsonRead(const String& json, String key, long& value, bool e) {
return true; return true;
} }
bool jsonRead(const String& json, String key, float& value, bool e) { bool jsonRead(const String &json, String key, float &value, bool e)
{
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
DeserializationError error = deserializeJson(doc, json); DeserializationError error = deserializeJson(doc, json);
if (error) { if (error)
if (e) { {
if (e)
{
SerialPrint("E", F("jsonRead"), error.f_str()); SerialPrint("E", F("jsonRead"), error.f_str());
jsonErrorDetected(); jsonErrorDetected();
} }
return false; return false;
} else if (!doc.containsKey(key)) { }
if (e) { else if (!doc.containsKey(key))
{
if (e)
{
SerialPrint("E", F("jsonRead"), key + " missing in " + json); SerialPrint("E", F("jsonRead"), key + " missing in " + json);
jsonErrorDetected(); jsonErrorDetected();
} }
@@ -51,17 +65,23 @@ bool jsonRead(const String& json, String key, float& value, bool e) {
return true; return true;
} }
bool jsonRead(const String& json, String key, String& value, bool e) { bool jsonRead(const String &json, String key, String &value, bool e)
{
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
DeserializationError error = deserializeJson(doc, json); DeserializationError error = deserializeJson(doc, json);
if (error) { if (error)
if (e) { {
if (e)
{
SerialPrint("E", F("jsonRead"), error.f_str()); SerialPrint("E", F("jsonRead"), error.f_str());
jsonErrorDetected(); jsonErrorDetected();
} }
return false; return false;
} else if (!doc.containsKey(key)) { }
if (e) { else if (!doc.containsKey(key))
{
if (e)
{
SerialPrint("E", F("jsonRead"), key + " missing in " + json); SerialPrint("E", F("jsonRead"), key + " missing in " + json);
jsonErrorDetected(); jsonErrorDetected();
} }
@@ -71,24 +91,31 @@ bool jsonRead(const String& json, String key, String& value, bool e) {
return true; return true;
} }
bool jsonRead(const String& json, String key, bool& value, bool e) { bool jsonRead(const String &json, String key, bool &value, bool e)
{
int lvalue = value; int lvalue = value;
bool ret = jsonRead(json, key, lvalue, e); bool ret = jsonRead(json, key, lvalue, e);
value = lvalue; value = lvalue;
return ret; return ret;
} }
bool jsonRead(const String& json, String key, int& value, bool e) { bool jsonRead(const String &json, String key, int &value, bool e)
{
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
DeserializationError error = deserializeJson(doc, json); DeserializationError error = deserializeJson(doc, json);
if (error) { if (error)
if (e) { {
if (e)
{
SerialPrint("E", F("jsonRead"), error.f_str()); SerialPrint("E", F("jsonRead"), error.f_str());
jsonErrorDetected(); jsonErrorDetected();
} }
return false; return false;
} else if (!doc.containsKey(key)) { }
if (e) { else if (!doc.containsKey(key))
{
if (e)
{
SerialPrint("E", F("jsonRead"), key + " missing in " + json); SerialPrint("E", F("jsonRead"), key + " missing in " + json);
jsonErrorDetected(); jsonErrorDetected();
} }
@@ -98,13 +125,59 @@ bool jsonRead(const String& json, String key, int& value, bool e) {
return true; return true;
} }
bool jsonReadArray(const String &json, String key, std::vector<String> &jArray, bool e)
{
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
DeserializationError error = deserializeJson(doc, json);
if (error)
{
if (e)
{
SerialPrint("E", F("jsonReadArray"), error.f_str());
jsonErrorDetected();
}
return false;
}
else if (!doc.containsKey(key))
{
if (e)
{
SerialPrint("E", F("jsonReadArray"), key + " missing in " + json);
jsonErrorDetected();
}
return false;
}
// SerialPrint("E", F("jsonReadArray"), key + " doc " + doc[key].as<String>());
if (doc[key].is<JsonArray>())
{
for (int8_t i = 0; i < doc[key].size(); i++)
jArray.push_back(doc[key][i].as<String>());
// SerialPrint("E", F("jsonReadArray"), "isArray"+key + " doc " + doc[key].as<String>());
}
else
{
jArray.push_back(doc[key].as<String>());
// DynamicJsonDocument docArr(JSON_BUFFER_SIZE/5);
// jArray = doc[key].as<JsonArray>();
// String tmp = doc[key].as<String>();
// jArray.add("dsdsd");
// SerialPrint("E", F("jsonReadArray"), "notArray"+key + " doc " + doc[key].as<String>());
// SerialPrint("E", F("jsonReadArray"), "count: " + String(jArray.size()) +" key: " + key + " arr " + jArray[0]);
}
// SerialPrint("E", F("jsonReadArray"), "count: " + String(jArray.size()) +" key: " + key + " doc " + jArray[0].as<String>());
return true;
}
// new============================================================================== // new==============================================================================
bool jsonWriteStr_(String& json, const String& key, const String& value, bool e) { bool jsonWriteStr_(String &json, const String &key, const String &value, bool e)
{
bool ret = true; bool ret = true;
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
DeserializationError error = deserializeJson(doc, json); DeserializationError error = deserializeJson(doc, json);
if (error) { if (error)
if (e) { {
if (e)
{
SerialPrint("E", F("jsonWrite"), error.f_str()); SerialPrint("E", F("jsonWrite"), error.f_str());
jsonErrorDetected(); jsonErrorDetected();
} }
@@ -116,12 +189,15 @@ bool jsonWriteStr_(String& json, const String& key, const String& value, bool e)
return ret; return ret;
} }
bool jsonWriteBool_(String& json, const String& key, bool value, bool e) { bool jsonWriteBool_(String &json, const String &key, bool value, bool e)
{
bool ret = true; bool ret = true;
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
DeserializationError error = deserializeJson(doc, json); DeserializationError error = deserializeJson(doc, json);
if (error) { if (error)
if (e) { {
if (e)
{
SerialPrint("E", F("jsonWrite"), error.f_str()); SerialPrint("E", F("jsonWrite"), error.f_str());
jsonErrorDetected(); jsonErrorDetected();
} }
@@ -133,12 +209,15 @@ bool jsonWriteBool_(String& json, const String& key, bool value, bool e) {
return ret; return ret;
} }
bool jsonWriteInt_(String& json, const String& key, int value, bool e) { bool jsonWriteInt_(String &json, const String &key, int value, bool e)
{
bool ret = true; bool ret = true;
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
DeserializationError error = deserializeJson(doc, json); DeserializationError error = deserializeJson(doc, json);
if (error) { if (error)
if (e) { {
if (e)
{
SerialPrint("E", F("jsonWrite"), error.f_str()); SerialPrint("E", F("jsonWrite"), error.f_str());
jsonErrorDetected(); jsonErrorDetected();
} }
@@ -150,12 +229,15 @@ bool jsonWriteInt_(String& json, const String& key, int value, bool e) {
return ret; return ret;
} }
bool jsonWriteFloat_(String& json, const String &key, float value, bool e) { bool jsonWriteFloat_(String &json, const String &key, float value, bool e)
{
bool ret = true; bool ret = true;
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
DeserializationError error = deserializeJson(doc, json); DeserializationError error = deserializeJson(doc, json);
if (error) { if (error)
if (e) { {
if (e)
{
SerialPrint("E", F("jsonWrite"), error.f_str()); SerialPrint("E", F("jsonWrite"), error.f_str());
jsonErrorDetected(); jsonErrorDetected();
} }
@@ -167,24 +249,29 @@ bool jsonWriteFloat_(String& json, const String &key, float value, bool e) {
return ret; return ret;
} }
void writeUint8tValueToJsonString(uint8_t* payload, size_t length, size_t headerLenth, String& json) { void writeUint8tValueToJsonString(uint8_t *payload, size_t length, size_t headerLenth, String &json)
{
String payloadStr; String payloadStr;
payloadStr.reserve(length + 1); payloadStr.reserve(length + 1);
for (size_t i = headerLenth; i < length; i++) { for (size_t i = headerLenth; i < length; i++)
{
payloadStr += (char)payload[i]; payloadStr += (char)payload[i];
} }
jsonMergeObjects(json, payloadStr); jsonMergeObjects(json, payloadStr);
} }
bool jsonMergeObjects(String& json1, String& json2, bool e) { bool jsonMergeObjects(String &json1, String &json2, bool e)
{
bool ret = true; bool ret = true;
DynamicJsonDocument doc1(JSON_BUFFER_SIZE); DynamicJsonDocument doc1(JSON_BUFFER_SIZE);
DeserializationError error1 = deserializeJson(doc1, json1); DeserializationError error1 = deserializeJson(doc1, json1);
DynamicJsonDocument doc2(JSON_BUFFER_SIZE); DynamicJsonDocument doc2(JSON_BUFFER_SIZE);
DeserializationError error2 = deserializeJson(doc2, json2); DeserializationError error2 = deserializeJson(doc2, json2);
jsonMergeDocs(doc1.as<JsonObject>(), doc2.as<JsonObject>()); jsonMergeDocs(doc1.as<JsonObject>(), doc2.as<JsonObject>());
if (error1 || error2) { if (error1 || error2)
if (e) { {
if (e)
{
SerialPrint("E", F("json"), "jsonMergeObjects error"); SerialPrint("E", F("json"), "jsonMergeObjects error");
jsonErrorDetected(); jsonErrorDetected();
} }
@@ -195,18 +282,23 @@ bool jsonMergeObjects(String& json1, String& json2, bool e) {
return ret; return ret;
} }
void jsonMergeDocs(JsonObject dest, JsonObjectConst src) { void jsonMergeDocs(JsonObject dest, JsonObjectConst src)
for (auto kvp : src) { {
for (auto kvp : src)
{
dest[kvp.key()] = kvp.value(); dest[kvp.key()] = kvp.value();
} }
} }
// depricated====================================================================== // depricated======================================================================
String jsonReadStr(const String& json, String name, bool e) { String jsonReadStr(const String &json, String name, bool e)
{
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
DeserializationError error = deserializeJson(doc, json); DeserializationError error = deserializeJson(doc, json);
if (error) { if (error)
if (e) { {
if (e)
{
SerialPrint("E", F("jsonRead"), error.f_str()); SerialPrint("E", F("jsonRead"), error.f_str());
jsonErrorDetected(); jsonErrorDetected();
} }
@@ -214,11 +306,14 @@ String jsonReadStr(const String& json, String name, bool e) {
return doc[name].as<String>(); return doc[name].as<String>();
} }
boolean jsonReadBool(const String& json, String name, bool e) { boolean jsonReadBool(const String &json, String name, bool e)
{
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
DeserializationError error = deserializeJson(doc, json); DeserializationError error = deserializeJson(doc, json);
if (error) { if (error)
if (e) { {
if (e)
{
SerialPrint("E", F("jsonRead"), error.f_str()); SerialPrint("E", F("jsonRead"), error.f_str());
jsonErrorDetected(); jsonErrorDetected();
} }
@@ -226,11 +321,14 @@ boolean jsonReadBool(const String& json, String name, bool e) {
return doc[name].as<bool>(); return doc[name].as<bool>();
} }
int jsonReadInt(const String& json, String name, bool e) { int jsonReadInt(const String &json, String name, bool e)
{
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
DeserializationError error = deserializeJson(doc, json); DeserializationError error = deserializeJson(doc, json);
if (error) { if (error)
if (e) { {
if (e)
{
SerialPrint("E", F("jsonRead"), error.f_str()); SerialPrint("E", F("jsonRead"), error.f_str());
jsonErrorDetected(); jsonErrorDetected();
} }
@@ -238,11 +336,14 @@ int jsonReadInt(const String& json, String name, bool e) {
return doc[name].as<int>(); return doc[name].as<int>();
} }
long int jsonReadLInt(const String& json, String name, bool e) { long int jsonReadLInt(const String &json, String name, bool e)
{
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
DeserializationError error = deserializeJson(doc, json); DeserializationError error = deserializeJson(doc, json);
if (error) { if (error)
if (e) { {
if (e)
{
SerialPrint("E", F("jsonRead"), error.f_str()); SerialPrint("E", F("jsonRead"), error.f_str());
jsonErrorDetected(); jsonErrorDetected();
} }
@@ -251,11 +352,14 @@ long int jsonReadLInt(const String& json, String name, bool e) {
} }
// depricated======================================================================== // depricated========================================================================
String jsonWriteStr(String& json, String name, String value, bool e) { String jsonWriteStr(String &json, String name, String value, bool e)
{
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
DeserializationError error = deserializeJson(doc, json); DeserializationError error = deserializeJson(doc, json);
if (error) { if (error)
if (e) { {
if (e)
{
SerialPrint("E", F("jsonWrite"), error.f_str()); SerialPrint("E", F("jsonWrite"), error.f_str());
jsonErrorDetected(); jsonErrorDetected();
} }
@@ -266,11 +370,14 @@ String jsonWriteStr(String& json, String name, String value, bool e) {
return json; return json;
} }
String jsonWriteBool(String& json, String name, boolean value, bool e) { String jsonWriteBool(String &json, String name, boolean value, bool e)
{
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
DeserializationError error = deserializeJson(doc, json); DeserializationError error = deserializeJson(doc, json);
if (error) { if (error)
if (e) { {
if (e)
{
SerialPrint("E", F("jsonWrite"), error.f_str()); SerialPrint("E", F("jsonWrite"), error.f_str());
jsonErrorDetected(); jsonErrorDetected();
} }
@@ -281,11 +388,14 @@ String jsonWriteBool(String& json, String name, boolean value, bool e) {
return json; return json;
} }
String jsonWriteInt(String& json, String name, int value, bool e) { String jsonWriteInt(String &json, String name, int value, bool e)
{
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
DeserializationError error = deserializeJson(doc, json); DeserializationError error = deserializeJson(doc, json);
if (error) { if (error)
if (e) { {
if (e)
{
SerialPrint("E", F("jsonWrite"), error.f_str()); SerialPrint("E", F("jsonWrite"), error.f_str());
jsonErrorDetected(); jsonErrorDetected();
} }
@@ -296,11 +406,14 @@ String jsonWriteInt(String& json, String name, int value, bool e) {
return json; return json;
} }
String jsonWriteFloat(String& json, String name, float value, bool e) { String jsonWriteFloat(String &json, String name, float value, bool e)
{
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
DeserializationError error = deserializeJson(doc, json); DeserializationError error = deserializeJson(doc, json);
if (error) { if (error)
if (e) { {
if (e)
{
SerialPrint("E", F("jsonWrite"), error.f_str()); SerialPrint("E", F("jsonWrite"), error.f_str());
jsonErrorDetected(); jsonErrorDetected();
} }
@@ -311,7 +424,8 @@ String jsonWriteFloat(String& json, String name, float value, bool e) {
return json; return json;
} }
void jsonErrorDetected() { void jsonErrorDetected()
{
// пример как отправить ошибку с количеством // пример как отправить ошибку с количеством
// jsonWriteInt(errorsHeapJson, F("jse2"), 1); // jsonWriteInt(errorsHeapJson, F("jse2"), 1);
// int number = jsonReadInt(errorsHeapJson, F("jse2n")); // int number = jsonReadInt(errorsHeapJson, F("jse2n"));

View File

@@ -1,43 +1,83 @@
#include "utils/WiFiUtils.h" #include "utils/WiFiUtils.h"
#include <vector>
#define TRIESONE 25 // количество попыток подключения к одной сети из несколких
#define TRIES 40 // количество попыток подключения сети если она одна
void routerConnect() { void routerConnect()
{
WiFi.setAutoConnect(false); WiFi.setAutoConnect(false);
WiFi.persistent(false); WiFi.persistent(false);
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
byte tries = 40; byte triesOne = TRIESONE;
String _ssid = jsonReadStr(settingsFlashJson, "routerssid"); std::vector<String> _ssidList;
String _password = jsonReadStr(settingsFlashJson, "routerpass"); std::vector<String> _passwordList;
jsonReadArray(settingsFlashJson, "routerssid", _ssidList);
jsonReadArray(settingsFlashJson, "routerpass", _passwordList);
if (_ssidList.size() > 1)
triesOne = TRIES;
if (_ssid == "" && _password == "") { if (_passwordList.size() == 0 && _ssidList[0] == "" && _passwordList[0] == "")
{
WiFi.begin(); WiFi.begin();
} else { }
WiFi.begin(_ssid.c_str(), _password.c_str()); else
{
WiFi.begin(_ssidList[0].c_str(), _passwordList[0].c_str());
#ifdef ESP32 #ifdef ESP32
WiFi.setTxPower(WIFI_POWER_19_5dBm); WiFi.setTxPower(WIFI_POWER_19_5dBm);
#else #else
WiFi.setOutputPower(20.5); WiFi.setOutputPower(20.5);
#endif #endif
SerialPrint("i", "WIFI", "ssid: " + _ssid); String _ssid;
SerialPrint("i", "WIFI", "pass: " + _password); String _password;
for (int8_t i = 0; i < _ssidList.size(); i++)
{
_ssid = _ssid + _ssidList[i] + "; ";
} }
for (int8_t i = 0; i < _passwordList.size(); i++)
while (--tries && WiFi.status() != WL_CONNECTED) { {
if (WiFi.status() == WL_CONNECT_FAILED) { _password = _password + _passwordList[i] + "; ";
}
SerialPrint("i", "WIFI", "ssid list: " + _ssid);
SerialPrint("i", "WIFI", "pass list: " + _password);
}
for (size_t i = 0; i < _ssidList.size(); i++)
{
triesOne = TRIESONE;
if (WiFi.status() == WL_CONNECTED)
break;
WiFi.begin(_ssidList[i].c_str(), _passwordList[i].c_str());
SerialPrint("i", "WIFI", "ssid connect: " + _ssidList[i]);
SerialPrint("i", "WIFI", "pass connect: " + _passwordList[i]);
while (--triesOne && WiFi.status() != WL_CONNECTED)
{
// SerialPrint("i", "WIFI", ": " + String((int)WiFi.status()));
#ifdef ESP8266
if (WiFi.status() == WL_CONNECT_FAILED || WiFi.status() == WL_WRONG_PASSWORD)
#else
if (WiFi.status() == WL_CONNECT_FAILED)
#endif
{
SerialPrint("E", "WIFI", "password is not correct"); SerialPrint("E", "WIFI", "password is not correct");
tries = 1; triesOne = 1;
jsonWriteInt(errorsHeapJson, "passer", 1); jsonWriteInt(errorsHeapJson, "passer", 1);
break; break;
} }
Serial.print("."); Serial.print(".");
delay(1000); delay(1000);
} }
Serial.println("");
}
if (WiFi.status() != WL_CONNECTED) { if (WiFi.status() != WL_CONNECTED)
{
Serial.println(""); Serial.println("");
startAPMode(); startAPMode();
} else { }
else
{
Serial.println(""); Serial.println("");
SerialPrint("i", "WIFI", "http://" + WiFi.localIP().toString()); SerialPrint("i", "WIFI", "http://" + WiFi.localIP().toString());
jsonWriteStr(settingsFlashJson, "ip", WiFi.localIP().toString()); jsonWriteStr(settingsFlashJson, "ip", WiFi.localIP().toString());
@@ -47,7 +87,8 @@ void routerConnect() {
SerialPrint("i", F("WIFI"), F("Network Init")); SerialPrint("i", F("WIFI"), F("Network Init"));
} }
bool startAPMode() { bool startAPMode()
{
SerialPrint("i", "WIFI", "AP Mode"); SerialPrint("i", "WIFI", "AP Mode");
WiFi.disconnect(); WiFi.disconnect();
@@ -62,14 +103,20 @@ bool startAPMode() {
SerialPrint("i", "WIFI", "AP IP: " + myIP.toString()); SerialPrint("i", "WIFI", "AP IP: " + myIP.toString());
jsonWriteStr(settingsFlashJson, "ip", myIP.toString()); jsonWriteStr(settingsFlashJson, "ip", myIP.toString());
if (jsonReadInt(errorsHeapJson, "passer") != 1) { if (jsonReadInt(errorsHeapJson, "passer") != 1)
{
ts.add( ts.add(
WIFI_SCAN, 30 * 1000, [&](void*) { WIFI_SCAN, 30 * 1000,
String sta_ssid = jsonReadStr(settingsFlashJson, "routerssid"); [&](void *)
{
SerialPrint("i", "WIFI", "scanning for " + sta_ssid); std::vector<String> jArray;
jsonReadArray(settingsFlashJson, "routerssid", jArray);
if (RouterFind(sta_ssid)) { for (int8_t i = 0; i < jArray.size(); i++)
{
SerialPrint("i", "WIFI", "scanning for " + jArray[i]);
}
if (RouterFind(jArray))
{
ts.remove(WIFI_SCAN); ts.remove(WIFI_SCAN);
WiFi.scanDelete(); WiFi.scanDelete();
routerConnect(); routerConnect();
@@ -80,30 +127,39 @@ bool startAPMode() {
return true; return true;
} }
boolean RouterFind(String ssid) { boolean RouterFind(std::vector<String> jArray)
{
bool res = false; bool res = false;
int n = WiFi.scanComplete(); int n = WiFi.scanComplete();
SerialPrint("i", "WIFI", "scan result: " + String(n, DEC)); SerialPrint("i", "WIFI", "scan result: " + String(n, DEC));
if (n == -2) { //Сканирование не было запущено, запускаем if (n == -2)
{ // Сканирование не было запущено, запускаем
SerialPrint("i", "WIFI", "start scanning"); SerialPrint("i", "WIFI", "start scanning");
WiFi.scanNetworks(true, false); // async, show_hidden WiFi.scanNetworks(true, false); // async, show_hidden
} }
else if (n == -1) { //Сканирование все еще выполняется else if (n == -1)
{ // Сканирование все еще выполняется
SerialPrint("i", "WIFI", "scanning in progress"); SerialPrint("i", "WIFI", "scanning in progress");
} }
else if (n == 0) { //ни одна сеть не найдена else if (n == 0)
{ // ни одна сеть не найдена
SerialPrint("i", "WIFI", "no networks found"); SerialPrint("i", "WIFI", "no networks found");
WiFi.scanNetworks(true, false); WiFi.scanNetworks(true, false);
} }
else if (n > 0)
else if (n > 0) { {
for (int8_t i = 0; i < n; i++) { for (int8_t i = 0; i < n; i++)
if (WiFi.SSID(i) == ssid) { {
for (int8_t k = 0; k < jArray.size(); k++)
{
if (WiFi.SSID(i) == jArray[k])
{
res = true; res = true;
} }
}
// SerialPrint("i", "WIFI", (res ? "*" : "") + String(i, DEC) + ") " + WiFi.SSID(i)); // SerialPrint("i", "WIFI", (res ? "*" : "") + String(i, DEC) + ") " + WiFi.SSID(i));
jsonWriteStr_(ssidListHeapJson, String(i), WiFi.SSID(i)); jsonWriteStr_(ssidListHeapJson, String(i), WiFi.SSID(i));
@@ -119,21 +175,34 @@ boolean RouterFind(String ssid) {
// return WiFi.status() == WL_CONNECTED; // return WiFi.status() == WL_CONNECTED;
// } // }
uint8_t RSSIquality() { uint8_t RSSIquality()
{
uint8_t res = 0; uint8_t res = 0;
if (WiFi.status() == WL_CONNECTED) { if (WiFi.status() == WL_CONNECTED)
{
int rssi = WiFi.RSSI(); int rssi = WiFi.RSSI();
if (rssi >= -50) { if (rssi >= -50)
{
res = 6; //"Excellent"; res = 6; //"Excellent";
} else if (rssi < -50 && rssi >= -60) { }
else if (rssi < -50 && rssi >= -60)
{
res = 5; //"Very good"; res = 5; //"Very good";
} else if (rssi < -60 && rssi >= -70) { }
else if (rssi < -60 && rssi >= -70)
{
res = 4; //"Good"; res = 4; //"Good";
} else if (rssi < -70 && rssi >= -80) { }
else if (rssi < -70 && rssi >= -80)
{
res = 3; //"Low"; res = 3; //"Low";
} else if (rssi < -80 && rssi > -100) { }
else if (rssi < -80 && rssi > -100)
{
res = 2; //"Very low"; res = 2; //"Very low";
} else if (rssi <= -100) { }
else if (rssi <= -100)
{
res = 1; //"No signal"; res = 1; //"No signal";
} }
} }

View File

@@ -0,0 +1,7 @@
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x480000,
app1, app, ota_1, 0x490000,0x480000,
spiffs, data, spiffs, 0x910000,0x6E0000,
coredump, data, coredump,0xFF0000,0x10000,
1 # Name Type SubType Offset Size Flags
2 nvs data nvs 0x9000 0x5000
3 otadata data ota 0xe000 0x2000
4 app0 app ota_0 0x10000 0x480000
5 app1 app ota_1 0x490000 0x480000
6 spiffs data spiffs 0x910000 0x6E0000
7 coredump data coredump 0xFF0000 0x10000

16
tools/patch8266_16m.py Normal file
View File

@@ -0,0 +1,16 @@
# правим %USERPROFILE%\.platformio\platforms\espressif8266\builder\main.py 103-115
# для добавления возможности прошивки 16мб модуля esp8266
import os
import shutil
mainPyPath = os.environ['USERPROFILE'] + '\\.platformio\\platforms\\espressif8266@4.0.1\\builder\\main.py'
with open(mainPyPath) as fr:
oldData = fr.read()
if not 'if _value == -0x6000:' in oldData:
shutil.copyfile(mainPyPath, mainPyPath+'.bak')
newData = oldData.replace('_value += 0xE00000 # correction', '_value += 0xE00000 # correction\n\n if _value == -0x6000:\n _value = env[k]-0x40200000')
with open(mainPyPath, 'w') as fw:
fw.write(newData)