mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
Merge branch 'ver4dev' of https://github.com/biveraxe/IoTManager into ver4dev
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
BIN
data_svelte/favicon.ico
Normal file
BIN
data_svelte/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 3.1 KiB |
@@ -4,9 +4,9 @@
|
|||||||
<meta charset='utf-8'>
|
<meta charset='utf-8'>
|
||||||
<meta name='viewport' content='width=device-width,initial-scale=1'>
|
<meta name='viewport' content='width=device-width,initial-scale=1'>
|
||||||
|
|
||||||
<title>Svelte app</title>
|
<title>IoT Manager</title>
|
||||||
|
|
||||||
<link rel='icon' type='image/png' href='/favicon.png'>
|
<link rel='icon' type='image/png' href='/favicon.ico'>
|
||||||
<link rel='stylesheet' href='/build/bundle.css'>
|
<link rel='stylesheet' href='/build/bundle.css'>
|
||||||
|
|
||||||
<script defer src='/build/bundle.js'></script>
|
<script defer src='/build/bundle.js'></script>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"settings": "",
|
||||||
"name": "IoTmanagerVer4",
|
"name": "IoTmanagerVer4",
|
||||||
"apssid": "IoTmanager",
|
"apssid": "IoTmanager",
|
||||||
"appass": "",
|
"appass": "",
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
//Это версия прошивки
|
//Это версия прошивки
|
||||||
#define FIRMWARE_VERSION 403
|
#define FIRMWARE_VERSION 404
|
||||||
|
|
||||||
|
#ifdef esp8266_4mb
|
||||||
|
#define FIRMWARE_NAME "esp8266_4mb"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef esp32_4mb
|
||||||
|
#define FIRMWARE_NAME "esp32_4mb"
|
||||||
|
#endif
|
||||||
|
|
||||||
//Размер буфера json
|
//Размер буфера json
|
||||||
#define JSON_BUFFER_SIZE 1024
|
#define JSON_BUFFER_SIZE 2048
|
||||||
|
|
||||||
//выбор сервера
|
//выбор сервера
|
||||||
//#define ASYNC_WEB_SERVER
|
//#define ASYNC_WEB_SERVER
|
||||||
|
|||||||
@@ -55,7 +55,6 @@
|
|||||||
*****************************************глобальные объекты классов***************************************************
|
*****************************************глобальные объекты классов***************************************************
|
||||||
**********************************************************************************************************************/
|
**********************************************************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
extern TickerScheduler ts;
|
extern TickerScheduler ts;
|
||||||
extern WiFiClient espClient;
|
extern WiFiClient espClient;
|
||||||
extern PubSubClient mqtt;
|
extern PubSubClient mqtt;
|
||||||
@@ -104,6 +103,7 @@ extern String mqttUser;
|
|||||||
extern String mqttPass;
|
extern String mqttPass;
|
||||||
|
|
||||||
extern unsigned long mqttUptime;
|
extern unsigned long mqttUptime;
|
||||||
|
extern unsigned long flashWriteNumber;
|
||||||
|
|
||||||
extern String mqttRootDevice;
|
extern String mqttRootDevice;
|
||||||
extern String chipId;
|
extern String chipId;
|
||||||
|
|||||||
@@ -70,8 +70,8 @@ class Scenario {
|
|||||||
oneBlock = deleteBeforeDelimiter(oneBlock, "\n");
|
oneBlock = deleteBeforeDelimiter(oneBlock, "\n");
|
||||||
oneBlock.replace("end", "");
|
oneBlock.replace("end", "");
|
||||||
|
|
||||||
// SerialPrint("I", "Event done", incommingEvent);
|
// SerialPrint("i", "Event done", incommingEvent);
|
||||||
SerialPrint("I", F("Scenario"), F("All conditions are matched"));
|
SerialPrint("i", F("Scenario"), F("All conditions are matched"));
|
||||||
spaceCmdExecute(oneBlock);
|
spaceCmdExecute(oneBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,8 +124,8 @@ class Scenario {
|
|||||||
oneBlock = deleteBeforeDelimiter(oneBlock, "\n");
|
oneBlock = deleteBeforeDelimiter(oneBlock, "\n");
|
||||||
oneBlock.replace("end", "");
|
oneBlock.replace("end", "");
|
||||||
|
|
||||||
// SerialPrint("I", "Event done", incommingEvent);
|
// SerialPrint("i", "Event done", incommingEvent);
|
||||||
SerialPrint("I", F("Scenario"), F("One of all condition are matched"));
|
SerialPrint("i", F("Scenario"), F("One of all condition are matched"));
|
||||||
spaceCmdExecute(oneBlock);
|
spaceCmdExecute(oneBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,8 +135,8 @@ class Scenario {
|
|||||||
oneBlock = deleteBeforeDelimiter(oneBlock, "\n");
|
oneBlock = deleteBeforeDelimiter(oneBlock, "\n");
|
||||||
oneBlock.replace("end", "");
|
oneBlock.replace("end", "");
|
||||||
|
|
||||||
// SerialPrint("I", "Event done", incommingEvent);
|
// SerialPrint("i", "Event done", incommingEvent);
|
||||||
SerialPrint("I", F("Scenario"), "Condition are matched: " + condition);
|
SerialPrint("i", F("Scenario"), "Condition are matched: " + condition);
|
||||||
spaceCmdExecute(oneBlock);
|
spaceCmdExecute(oneBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,8 +146,8 @@ class Scenario {
|
|||||||
oneBlock = deleteBeforeDelimiter(oneBlock, "\n");
|
oneBlock = deleteBeforeDelimiter(oneBlock, "\n");
|
||||||
oneBlock.replace("end", "");
|
oneBlock.replace("end", "");
|
||||||
|
|
||||||
// SerialPrint("I", "Event done", incommingEvent);
|
// SerialPrint("i", "Event done", incommingEvent);
|
||||||
SerialPrint("I", F("Scenario"), "Condition are matched: " + condition);
|
SerialPrint("i", F("Scenario"), "Condition are matched: " + condition);
|
||||||
spaceCmdExecute(oneBlock);
|
spaceCmdExecute(oneBlock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,4 +9,5 @@ extern const String writeFile(const String& filename, const String& str);
|
|||||||
extern const String readFile(const String& filename, size_t max_size);
|
extern const String readFile(const String& filename, size_t max_size);
|
||||||
extern const String filepath(const String& filename);
|
extern const String filepath(const String& filename);
|
||||||
extern bool cutFile(const String& src, const String& dst);
|
extern bool cutFile(const String& src, const String& dst);
|
||||||
extern const String addFileLn(const String& filename, const String& str);
|
extern const String addFileLn(const String& filename, const String& str);
|
||||||
|
extern void onFlashWrite();
|
||||||
@@ -8,7 +8,7 @@ void eventGen2(String eventName, String eventValue) {
|
|||||||
String event = eventName + " " + eventValue + ",";
|
String event = eventName + " " + eventValue + ",";
|
||||||
eventBuf += event;
|
eventBuf += event;
|
||||||
|
|
||||||
SerialPrint("I", "Event add", eventName + " " + eventValue);
|
SerialPrint("i", "Event add", eventName + " " + eventValue);
|
||||||
|
|
||||||
if (jsonReadBool(settingsFlashJson, "MqttOut")) {
|
if (jsonReadBool(settingsFlashJson, "MqttOut")) {
|
||||||
if (eventName != "timenow") {
|
if (eventName != "timenow") {
|
||||||
@@ -25,7 +25,7 @@ void spaceCmdExecute(String& cmdStr) {
|
|||||||
String buf = selectToMarker(cmdStr, "\n");
|
String buf = selectToMarker(cmdStr, "\n");
|
||||||
if (buf != "") {
|
if (buf != "") {
|
||||||
sCmd.readStr(buf);
|
sCmd.readStr(buf);
|
||||||
SerialPrint("I", F("Order done W"), buf);
|
SerialPrint("i", F("Order done W"), buf);
|
||||||
}
|
}
|
||||||
cmdStr = deleteBeforeDelimiter(cmdStr, "\n");
|
cmdStr = deleteBeforeDelimiter(cmdStr, "\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ const String getThisDevice() {
|
|||||||
|
|
||||||
void addThisDeviceToList() {
|
void addThisDeviceToList() {
|
||||||
devListHeapJson = getThisDevice();
|
devListHeapJson = getThisDevice();
|
||||||
|
SerialPrint("i", "List", "Add this dev to list");
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef UDP_ENABLED
|
#ifdef UDP_ENABLED
|
||||||
@@ -61,7 +62,7 @@ void asyncUdpInit() {
|
|||||||
},
|
},
|
||||||
nullptr, true);
|
nullptr, true);
|
||||||
|
|
||||||
SerialPrint("I", F("UDP"), F("Udp Init"));
|
SerialPrint("i", F("UDP"), F("Udp Init"));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool udpPacketValidation(String& data) {
|
bool udpPacketValidation(String& data) {
|
||||||
|
|||||||
@@ -14,27 +14,32 @@ void configure(String path) {
|
|||||||
if (jsonArrayElement.startsWith(",")) {
|
if (jsonArrayElement.startsWith(",")) {
|
||||||
jsonArrayElement = jsonArrayElement.substring(1, jsonArrayElement.length()); //это нужно оптимизировать в последствии
|
jsonArrayElement = jsonArrayElement.substring(1, jsonArrayElement.length()); //это нужно оптимизировать в последствии
|
||||||
}
|
}
|
||||||
|
if (jsonArrayElement == "]}") {
|
||||||
String subtype;
|
jsonArrayElement = "";
|
||||||
if (!jsonRead(jsonArrayElement, F("subtype"), subtype)) { //если нет такого ключа в представленном json или он не валидный
|
}
|
||||||
SerialPrint(F("E"), F("Config"), "json error " + subtype);
|
if (jsonArrayElement != "") {
|
||||||
continue;
|
String subtype;
|
||||||
} else {
|
if (!jsonRead(jsonArrayElement, F("subtype"), subtype)) { //если нет такого ключа в представленном json или он не валидный
|
||||||
myIoTItem = (IoTItem*)getAPI(subtype, jsonArrayElement);
|
SerialPrint(F("E"), F("Config"), "json error " + subtype);
|
||||||
if (myIoTItem) {
|
continue;
|
||||||
IoTGpio* tmp = myIoTItem->getGpioDriver();
|
} else {
|
||||||
if (tmp) IoTgpio.regDriver(tmp);
|
myIoTItem = (IoTItem*)getAPI(subtype, jsonArrayElement);
|
||||||
IoTItems.push_back(myIoTItem);
|
if (myIoTItem) {
|
||||||
|
IoTGpio* tmp = myIoTItem->getGpioDriver();
|
||||||
|
if (tmp) IoTgpio.regDriver(tmp);
|
||||||
|
IoTItems.push_back(myIoTItem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
|
SerialPrint("i", "Config", "Configured");
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearConfigure() {
|
void clearConfigure() {
|
||||||
Serial.printf("Start clearing config\n");
|
Serial.printf("Start clearing config\n");
|
||||||
for (unsigned int i = 0; i < IoTItems.size(); i++) {
|
for (unsigned int i = 0; i < IoTItems.size(); i++) {
|
||||||
if (IoTItems[i]) delete IoTItems[i];
|
if (IoTItems[i]) delete IoTItems[i];
|
||||||
}
|
}
|
||||||
IoTItems.clear();
|
IoTItems.clear();
|
||||||
}
|
}
|
||||||
@@ -18,8 +18,6 @@ void globalVarsSync() {
|
|||||||
jsonWriteStr_(settingsFlashJson, "root", mqttRootDevice);
|
jsonWriteStr_(settingsFlashJson, "root", mqttRootDevice);
|
||||||
jsonWriteStr_(settingsFlashJson, "id", chipId);
|
jsonWriteStr_(settingsFlashJson, "id", chipId);
|
||||||
|
|
||||||
syncSettingsFlashJson();
|
|
||||||
|
|
||||||
jsonWriteStr_(errorsHeapJson, "errors", ""); //метка для парсинга
|
jsonWriteStr_(errorsHeapJson, "errors", ""); //метка для парсинга
|
||||||
jsonWriteStr_(ssidListHeapJson, "ssid", ""); //метка для парсинга
|
jsonWriteStr_(ssidListHeapJson, "ssid", ""); //метка для парсинга
|
||||||
jsonWriteStr(paramsHeapJson, "params", ""); //метка для парсинга
|
jsonWriteStr(paramsHeapJson, "params", ""); //метка для парсинга
|
||||||
@@ -39,7 +37,7 @@ const String getChipId() {
|
|||||||
|
|
||||||
void setChipId() {
|
void setChipId() {
|
||||||
chipId = getChipId();
|
chipId = getChipId();
|
||||||
SerialPrint("I", "System", "id: " + chipId);
|
SerialPrint("i", "System", "id: " + chipId);
|
||||||
}
|
}
|
||||||
|
|
||||||
const String getUniqueId(const char* name) {
|
const String getUniqueId(const char* name) {
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ String mqttPrefix = "";
|
|||||||
String mqttUser = "";
|
String mqttUser = "";
|
||||||
String mqttPass = "";
|
String mqttPass = "";
|
||||||
|
|
||||||
unsigned long mqttUptime;
|
unsigned long mqttUptime = 0;
|
||||||
|
unsigned long flashWriteNumber = 0;
|
||||||
|
|
||||||
String chipId = "";
|
String chipId = "";
|
||||||
String prex = "";
|
String prex = "";
|
||||||
|
|||||||
@@ -23,9 +23,6 @@ void setup() {
|
|||||||
//подключаемся к роутеру
|
//подключаемся к роутеру
|
||||||
routerConnect();
|
routerConnect();
|
||||||
|
|
||||||
//запустим один раз асинхронное сканирование сетей wifi для веба
|
|
||||||
RouterFind(jsonReadStr(settingsFlashJson, F("routerssid")));
|
|
||||||
|
|
||||||
//инициализация асинхронного веб сервера и веб сокетов
|
//инициализация асинхронного веб сервера и веб сокетов
|
||||||
#ifdef ASYNC_WEB_SERVER
|
#ifdef ASYNC_WEB_SERVER
|
||||||
asyncWebServerInit();
|
asyncWebServerInit();
|
||||||
@@ -51,9 +48,6 @@ void setup() {
|
|||||||
//инициализация задач переодического выполнения
|
//инициализация задач переодического выполнения
|
||||||
periodicTasksInit();
|
periodicTasksInit();
|
||||||
|
|
||||||
//окончательнаясинхронизация настроек
|
|
||||||
syncSettingsFlashJson();
|
|
||||||
|
|
||||||
//синхронизация списка устройств
|
//синхронизация списка устройств
|
||||||
addThisDeviceToList();
|
addThisDeviceToList();
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ void mqttInit() {
|
|||||||
WIFI_MQTT_CONNECTION_CHECK, MQTT_RECONNECT_INTERVAL,
|
WIFI_MQTT_CONNECTION_CHECK, MQTT_RECONNECT_INTERVAL,
|
||||||
[&](void*) {
|
[&](void*) {
|
||||||
if (WiFi.status() == WL_CONNECTED) {
|
if (WiFi.status() == WL_CONNECTED) {
|
||||||
SerialPrint("I", F("WIFI"), F("OK"));
|
SerialPrint("i", F("WIFI"), F("OK"));
|
||||||
if (mqtt.connected()) {
|
if (mqtt.connected()) {
|
||||||
SerialPrint("I", F("MQTT"), "OK");
|
SerialPrint("i", F("MQTT"), "OK");
|
||||||
handleMqttStatus(false);
|
handleMqttStatus(false);
|
||||||
|
|
||||||
static unsigned int prevMillis;
|
static unsigned int prevMillis;
|
||||||
@@ -48,10 +48,10 @@ boolean mqttConnect() {
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
SerialPrint("I", "MQTT", "connection started");
|
SerialPrint("i", "MQTT", "connection started");
|
||||||
|
|
||||||
SerialPrint("I", "MQTT", "broker " + mqttServer + ":" + String(mqttPort, DEC));
|
SerialPrint("i", "MQTT", "broker " + mqttServer + ":" + String(mqttPort, DEC));
|
||||||
SerialPrint("I", "MQTT", "topic " + mqttRootDevice);
|
SerialPrint("i", "MQTT", "topic " + mqttRootDevice);
|
||||||
|
|
||||||
// setLedStatus(LED_FAST);
|
// setLedStatus(LED_FAST);
|
||||||
|
|
||||||
@@ -61,10 +61,10 @@ boolean mqttConnect() {
|
|||||||
bool connected = false;
|
bool connected = false;
|
||||||
if (mqttUser != "" && mqttPass != "") {
|
if (mqttUser != "" && mqttPass != "") {
|
||||||
connected = mqtt.connect(chipId.c_str(), mqttUser.c_str(), mqttPass.c_str());
|
connected = mqtt.connect(chipId.c_str(), mqttUser.c_str(), mqttPass.c_str());
|
||||||
SerialPrint("I", F("MQTT"), F("Go to connection with login and password"));
|
SerialPrint("i", F("MQTT"), F("Go to connection with login and password"));
|
||||||
} else if (mqttUser == "" && mqttPass == "") {
|
} else if (mqttUser == "" && mqttPass == "") {
|
||||||
connected = mqtt.connect(chipId.c_str());
|
connected = mqtt.connect(chipId.c_str());
|
||||||
SerialPrint("I", F("MQTT"), F("Go to connection without login and password"));
|
SerialPrint("i", F("MQTT"), F("Go to connection without login and password"));
|
||||||
} else {
|
} else {
|
||||||
SerialPrint("E", F("MQTT"), F("✖ Login or password missed"));
|
SerialPrint("E", F("MQTT"), F("✖ Login or password missed"));
|
||||||
handleMqttStatus(true, 7);
|
handleMqttStatus(true, 7);
|
||||||
@@ -72,7 +72,7 @@ boolean mqttConnect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mqtt.state() == 0) {
|
if (mqtt.state() == 0) {
|
||||||
SerialPrint("I", F("MQTT"), F("✔ connected"));
|
SerialPrint("i", F("MQTT"), F("✔ connected"));
|
||||||
handleMqttStatus(true);
|
handleMqttStatus(true);
|
||||||
// setLedStatus(LED_OFF);
|
// setLedStatus(LED_OFF);
|
||||||
mqttSubscribe();
|
mqttSubscribe();
|
||||||
@@ -87,7 +87,7 @@ boolean mqttConnect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void mqttDisconnect() {
|
void mqttDisconnect() {
|
||||||
SerialPrint("I", F("MQTT"), F("disconnected"));
|
SerialPrint("i", F("MQTT"), F("disconnected"));
|
||||||
mqtt.disconnect();
|
mqtt.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,8 +104,8 @@ void getMqttData() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void mqttSubscribe() {
|
void mqttSubscribe() {
|
||||||
SerialPrint("I", F("MQTT"), F("subscribed"));
|
SerialPrint("i", F("MQTT"), F("subscribed"));
|
||||||
SerialPrint("I", F("MQTT"), mqttRootDevice);
|
SerialPrint("i", F("MQTT"), mqttRootDevice);
|
||||||
mqtt.subscribe(mqttPrefix.c_str());
|
mqtt.subscribe(mqttPrefix.c_str());
|
||||||
mqtt.subscribe((mqttRootDevice + "/+/control").c_str());
|
mqtt.subscribe((mqttRootDevice + "/+/control").c_str());
|
||||||
mqtt.subscribe((mqttRootDevice + "/update").c_str());
|
mqtt.subscribe((mqttRootDevice + "/update").c_str());
|
||||||
@@ -119,17 +119,17 @@ void mqttSubscribe() {
|
|||||||
|
|
||||||
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);
|
||||||
String payloadStr;
|
String payloadStr;
|
||||||
payloadStr.reserve(length + 1);
|
payloadStr.reserve(length + 1);
|
||||||
for (size_t i = 0; i < length; i++) {
|
for (size_t i = 0; i < length; i++) {
|
||||||
payloadStr += (char)payload[i];
|
payloadStr += (char)payload[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// SerialPrint("I", "=>MQTT", payloadStr);
|
// SerialPrint("i", "=>MQTT", payloadStr);
|
||||||
|
|
||||||
if (payloadStr.startsWith("HELLO")) {
|
if (payloadStr.startsWith("HELLO")) {
|
||||||
SerialPrint("I", F("MQTT"), F("Full update"));
|
SerialPrint("i", F("MQTT"), F("Full update"));
|
||||||
publishWidgets();
|
publishWidgets();
|
||||||
publishState();
|
publishState();
|
||||||
#ifdef GATE_MODE
|
#ifdef GATE_MODE
|
||||||
@@ -151,7 +151,7 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) {
|
|||||||
//
|
//
|
||||||
// loopCmdAdd(order);
|
// loopCmdAdd(order);
|
||||||
//
|
//
|
||||||
// SerialPrint("I", F("=>MQTT"), "Msg from iotmanager app: " + key + " " + payloadStr);
|
// SerialPrint("i", F("=>MQTT"), "Msg from iotmanager app: " + key + " " + payloadStr);
|
||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
// else if (topicStr.indexOf("event") != -1) {
|
// else if (topicStr.indexOf("event") != -1) {
|
||||||
@@ -161,7 +161,7 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) {
|
|||||||
// if (topicStr.indexOf(chipId) == -1) {
|
// if (topicStr.indexOf(chipId) == -1) {
|
||||||
// String devId = selectFromMarkerToMarker(topicStr, "/", 2);
|
// String devId = selectFromMarkerToMarker(topicStr, "/", 2);
|
||||||
// String key = selectFromMarkerToMarker(topicStr, "/", 3);
|
// String key = selectFromMarkerToMarker(topicStr, "/", 3);
|
||||||
// SerialPrint("I", F("=>MQTT"), "Received event from other device: '" + devId + "' " + key + " " + payloadStr);
|
// SerialPrint("i", F("=>MQTT"), "Received event from other device: '" + devId + "' " + key + " " + payloadStr);
|
||||||
// String event = key + " " + payloadStr + ",";
|
// String event = key + " " + payloadStr + ",";
|
||||||
// eventBuf += event;
|
// eventBuf += event;
|
||||||
// }
|
// }
|
||||||
@@ -173,17 +173,17 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) {
|
|||||||
// }
|
// }
|
||||||
// String devId = selectFromMarkerToMarker(topicStr, "/", 2);
|
// String devId = selectFromMarkerToMarker(topicStr, "/", 2);
|
||||||
// String key = selectFromMarkerToMarker(topicStr, "/", 3);
|
// String key = selectFromMarkerToMarker(topicStr, "/", 3);
|
||||||
// SerialPrint("I", F("=>MQTT"), "Received direct order " + key + " " + payloadStr);
|
// SerialPrint("i", F("=>MQTT"), "Received direct order " + key + " " + payloadStr);
|
||||||
// String order = key + " " + payloadStr + ",";
|
// String order = key + " " + payloadStr + ",";
|
||||||
// loopCmdAdd(order);
|
// loopCmdAdd(order);
|
||||||
// SerialPrint("I", "Order add", order);
|
// SerialPrint("i", "Order add", order);
|
||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
// else if (topicStr.indexOf("info") != -1) {
|
// else if (topicStr.indexOf("info") != -1) {
|
||||||
// if (topicStr.indexOf("scen") != -1) {
|
// if (topicStr.indexOf("scen") != -1) {
|
||||||
// writeFile(String(DEVICE_SCENARIO_FILE), payloadStr);
|
// writeFile(String(DEVICE_SCENARIO_FILE), payloadStr);
|
||||||
// loadScenario();
|
// loadScenario();
|
||||||
// SerialPrint("I", F("=>MQTT"), F("Scenario received"));
|
// SerialPrint("i", F("=>MQTT"), F("Scenario received"));
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,11 +14,15 @@ void periodicTasksInit() {
|
|||||||
// uptime
|
// uptime
|
||||||
jsonWriteStr_(errorsHeapJson, F("upt"), prettyMillis(millis()));
|
jsonWriteStr_(errorsHeapJson, F("upt"), prettyMillis(millis()));
|
||||||
jsonWriteStr_(errorsHeapJson, F("uptm"), prettyMillis(mqttUptime));
|
jsonWriteStr_(errorsHeapJson, F("uptm"), prettyMillis(mqttUptime));
|
||||||
|
// flash
|
||||||
|
jsonWriteInt_(errorsHeapJson, F("fl"), flashWriteNumber);
|
||||||
// build ver
|
// build ver
|
||||||
jsonWriteStr_(errorsHeapJson, F("bver"), String(FIRMWARE_VERSION));
|
jsonWriteStr_(errorsHeapJson, F("bver"), String(FIRMWARE_VERSION));
|
||||||
|
jsonWriteStr_(errorsHeapJson, F("bn"), String(FIRMWARE_NAME));
|
||||||
periodicWsSend();
|
periodicWsSend();
|
||||||
},
|
},
|
||||||
nullptr, true);
|
nullptr, true);
|
||||||
|
SerialPrint("i", "Task", "Periodic tasks init");
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleError(String errorId, String errorValue) {
|
void handleError(String errorId, String errorValue) {
|
||||||
@@ -31,17 +35,23 @@ void handleError(String errorId, int errorValue) {
|
|||||||
|
|
||||||
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 errorsHeapJsonSize = errorsHeapJson.length();
|
size_t errorsHeapJsonSize = errorsHeapJson.length();
|
||||||
// SerialPrint(F("i"), F("settingsFlashJson"), String(errorsHeapJsonSize));
|
SerialPrint(F("i"), F("errorsHeapJson"), String(errorsHeapJsonSize));
|
||||||
size_t paramsFlashJsonSize = paramsFlashJson.length();
|
size_t paramsFlashJsonSize = paramsFlashJson.length();
|
||||||
// SerialPrint(F("i"), F("settingsFlashJson"), String(paramsFlashJsonSize));
|
SerialPrint(F("i"), F("paramsFlashJson"), String(paramsFlashJsonSize));
|
||||||
size_t paramsHeapJsonSize = paramsHeapJson.length();
|
size_t paramsHeapJsonSize = paramsHeapJson.length();
|
||||||
// SerialPrint(F("i"), F("settingsFlashJson"), String(paramsHeapJsonSize));
|
SerialPrint(F("i"), F("paramsHeapJson"), String(paramsHeapJsonSize));
|
||||||
|
size_t devListHeapJsonSize = devListHeapJson.length();
|
||||||
|
SerialPrint(F("i"), F("devListHeapJson"), String(devListHeapJsonSize));
|
||||||
|
|
||||||
size_t halfBuffer = JSON_BUFFER_SIZE / 2;
|
size_t halfBuffer = JSON_BUFFER_SIZE / 2;
|
||||||
|
|
||||||
if (settingsFlashJsonSize > halfBuffer || errorsHeapJsonSize > halfBuffer || paramsFlashJsonSize > halfBuffer || paramsHeapJsonSize > halfBuffer) {
|
if (settingsFlashJsonSize > halfBuffer ||
|
||||||
|
errorsHeapJsonSize > halfBuffer ||
|
||||||
|
paramsFlashJsonSize > halfBuffer ||
|
||||||
|
paramsHeapJsonSize > halfBuffer ||
|
||||||
|
devListHeapJsonSize > halfBuffer) {
|
||||||
SerialPrint(F("EE"), F("Json"), F("Insufficient buffer size!!!"));
|
SerialPrint(F("EE"), F("Json"), F("Insufficient buffer size!!!"));
|
||||||
jsonWriteInt(errorsHeapJson, "jse1", 1);
|
jsonWriteInt(errorsHeapJson, "jse1", 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
|||||||
sendFileToWs("/items.json", num, 1024);
|
sendFileToWs("/items.json", num, 1024);
|
||||||
sendFileToWs("/widgets.json", num, 1024);
|
sendFileToWs("/widgets.json", num, 1024);
|
||||||
sendFileToWs("/config.json", num, 1024);
|
sendFileToWs("/config.json", num, 1024);
|
||||||
sendFileToWs("/settings.json", num, 1024);
|
standWebSocket.sendTXT(num, settingsFlashJson);
|
||||||
}
|
}
|
||||||
//**сохранение**//
|
//**сохранение**//
|
||||||
if (headerStr == "/gifnoc|") {
|
if (headerStr == "/gifnoc|") {
|
||||||
@@ -77,7 +77,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
|||||||
// page connection===================================================================
|
// page connection===================================================================
|
||||||
//**отправка**//
|
//**отправка**//
|
||||||
if (headerStr == "/connection|") {
|
if (headerStr == "/connection|") {
|
||||||
sendFileToWs("/settings.json", num, 1024);
|
standWebSocket.sendTXT(num, settingsFlashJson);
|
||||||
standWebSocket.sendTXT(num, ssidListHeapJson);
|
standWebSocket.sendTXT(num, ssidListHeapJson);
|
||||||
standWebSocket.sendTXT(num, errorsHeapJson);
|
standWebSocket.sendTXT(num, errorsHeapJson);
|
||||||
//запуск асинхронного сканирования wifi сетей при переходе на страницу соединений
|
//запуск асинхронного сканирования wifi сетей при переходе на страницу соединений
|
||||||
@@ -85,11 +85,10 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
|||||||
}
|
}
|
||||||
//**сохранение**//
|
//**сохранение**//
|
||||||
if (headerStr == "/sgnittes|") {
|
if (headerStr == "/sgnittes|") {
|
||||||
writeFileUint8tByFrames("settings.json", payload, length, headerLenth, 256);
|
|
||||||
writeUint8tToString(payload, length, headerLenth, settingsFlashJson);
|
writeUint8tToString(payload, length, headerLenth, settingsFlashJson);
|
||||||
|
writeFileUint8tByFrames("settings.json", payload, length, headerLenth, 256);
|
||||||
standWebSocket.sendTXT(num, errorsHeapJson);
|
standWebSocket.sendTXT(num, errorsHeapJson);
|
||||||
addThisDeviceToList();
|
addThisDeviceToList();
|
||||||
// settingsFlashJson = readFile(F("settings.json"), 4096);
|
|
||||||
}
|
}
|
||||||
//**отправка**//
|
//**отправка**//
|
||||||
if (headerStr == "/scan|") {
|
if (headerStr == "/scan|") {
|
||||||
@@ -99,10 +98,10 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
|||||||
}
|
}
|
||||||
//**сохранение**//
|
//**сохранение**//
|
||||||
if (headerStr == "/mqtt|") {
|
if (headerStr == "/mqtt|") {
|
||||||
sendFileToWs("/settings.json", num, 1024); //отправляем в ответ новые полученные настройки
|
standWebSocket.sendTXT(num, settingsFlashJson); //отправляем в ответ новые полученные настройки
|
||||||
handleMqttStatus(false, 8); //меняем статус на неопределенный
|
handleMqttStatus(false, 8); //меняем статус на неопределенный
|
||||||
mqttReconnect(); //начинаем переподключение
|
mqttReconnect(); //начинаем переподключение
|
||||||
standWebSocket.sendTXT(num, errorsHeapJson); //отправляем что статус неопределен
|
standWebSocket.sendTXT(num, errorsHeapJson); //отправляем что статус неопределен
|
||||||
standWebSocket.sendTXT(num, ssidListHeapJson);
|
standWebSocket.sendTXT(num, ssidListHeapJson);
|
||||||
}
|
}
|
||||||
// page list ==========================================================================
|
// page list ==========================================================================
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ void IoTItem::regEvent(String value, String consoleInfo = "") {
|
|||||||
jsonWriteStr(paramsHeapJson, _id, value);
|
jsonWriteStr(paramsHeapJson, _id, value);
|
||||||
publishStatusMqtt(_id, value);
|
publishStatusMqtt(_id, value);
|
||||||
publishStatusWs(_id, value);
|
publishStatusWs(_id, value);
|
||||||
SerialPrint("I", "Sensor " + consoleInfo, "'" + _id + "' data: " + value + "'");
|
SerialPrint("i", "Sensor " + consoleInfo, "'" + _id + "' data: " + value + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
void IoTItem::regEvent(float value, String consoleInfo = "") {
|
void IoTItem::regEvent(float value, String consoleInfo = "") {
|
||||||
@@ -75,13 +75,13 @@ void IoTItem::regEvent(float value, String consoleInfo = "") {
|
|||||||
|
|
||||||
void IoTItem::doByInterval() {}
|
void IoTItem::doByInterval() {}
|
||||||
|
|
||||||
IoTValue IoTItem::execute(String command, std::vector<IoTValue> ¶m) { return {};}
|
IoTValue IoTItem::execute(String command, std::vector<IoTValue>& param) { return {}; }
|
||||||
|
|
||||||
IoTItem* findIoTItem(String name) { // поиск элемента модуля в существующей конфигурации
|
IoTItem* findIoTItem(String name) { // поиск элемента модуля в существующей конфигурации
|
||||||
for (unsigned int i = 0; i < IoTItems.size(); i++) {
|
for (unsigned int i = 0; i < IoTItems.size(); i++) {
|
||||||
if(IoTItems[i]->getID() == name) return IoTItems[i];
|
if (IoTItems[i]->getID() == name) return IoTItems[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ void writeFileUint8tByFrames(const String& filename, uint8_t*& big_buf, size_t l
|
|||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
|
onFlashWrite();
|
||||||
}
|
}
|
||||||
|
|
||||||
// void writeStrValueToJsonFile(const String& filename, String key, String value) {
|
// void writeStrValueToJsonFile(const String& filename, String key, String value) {
|
||||||
@@ -75,6 +76,7 @@ void writeFileUint8tByByte(const String& filename, uint8_t*& payload, size_t len
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
|
onFlashWrite();
|
||||||
}
|
}
|
||||||
|
|
||||||
File seekFile(const String& filename, size_t position) {
|
File seekFile(const String& filename, size_t position) {
|
||||||
@@ -96,6 +98,7 @@ const String writeFile(const String& filename, const String& str) {
|
|||||||
file.print(str);
|
file.print(str);
|
||||||
file.close();
|
file.close();
|
||||||
return "sucсess";
|
return "sucсess";
|
||||||
|
onFlashWrite();
|
||||||
}
|
}
|
||||||
|
|
||||||
const String readFile(const String& filename, size_t max_size) {
|
const String readFile(const String& filename, size_t max_size) {
|
||||||
@@ -139,6 +142,7 @@ bool cutFile(const String& src, const String& dst) {
|
|||||||
srcFile.close();
|
srcFile.close();
|
||||||
dstFile.close();
|
dstFile.close();
|
||||||
FileFS.remove(srcPath);
|
FileFS.remove(srcPath);
|
||||||
|
onFlashWrite();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,5 +154,11 @@ const String addFileLn(const String& filename, const String& str) {
|
|||||||
}
|
}
|
||||||
file.println(str);
|
file.println(str);
|
||||||
file.close();
|
file.close();
|
||||||
|
onFlashWrite();
|
||||||
return "sucсess";
|
return "sucсess";
|
||||||
|
}
|
||||||
|
|
||||||
|
void onFlashWrite() {
|
||||||
|
flashWriteNumber++;
|
||||||
|
SerialPrint(F("->"), F("FS"), F("write data on flash"));
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user