mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
запустил dashboard
This commit is contained in:
@@ -12,6 +12,11 @@ bool fileSystemInit() {
|
|||||||
void globalVarsSync() {
|
void globalVarsSync() {
|
||||||
settingsFlashJson = readFile(F("settings.json"), 4096);
|
settingsFlashJson = readFile(F("settings.json"), 4096);
|
||||||
settingsFlashJson.replace("\r\n", "");
|
settingsFlashJson.replace("\r\n", "");
|
||||||
|
|
||||||
|
mqttPrefix = jsonReadStr(settingsFlashJson, F("mqttPrefix"));
|
||||||
|
mqttRootDevice = mqttPrefix + "/" + chipId;
|
||||||
|
jsonWriteStr_(settingsFlashJson, "root", mqttRootDevice);
|
||||||
|
saveSettingsFlashJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveSettingsFlashJson() {
|
void saveSettingsFlashJson() {
|
||||||
|
|||||||
@@ -89,20 +89,18 @@ void getMqttData1() {
|
|||||||
currentBroker = 1;
|
currentBroker = 1;
|
||||||
mqttServer = jsonReadStr(settingsFlashJson, F("mqttServer"));
|
mqttServer = jsonReadStr(settingsFlashJson, F("mqttServer"));
|
||||||
mqttPort = jsonReadInt(settingsFlashJson, F("mqttPort"));
|
mqttPort = jsonReadInt(settingsFlashJson, F("mqttPort"));
|
||||||
mqttPrefix = jsonReadStr(settingsFlashJson, F("mqttPrefix"));
|
|
||||||
mqttUser = jsonReadStr(settingsFlashJson, F("mqttUser"));
|
mqttUser = jsonReadStr(settingsFlashJson, F("mqttUser"));
|
||||||
mqttPass = jsonReadStr(settingsFlashJson, F("mqttPass"));
|
mqttPass = jsonReadStr(settingsFlashJson, F("mqttPass"));
|
||||||
prex = mqttPrefix + "/" + chipId;
|
// prex = mqttPrefix + "/" + chipId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void getMqttData2() {
|
void getMqttData2() {
|
||||||
currentBroker = 2;
|
currentBroker = 2;
|
||||||
mqttServer = jsonReadStr(settingsFlashJson, F("mqttServer2"));
|
mqttServer = jsonReadStr(settingsFlashJson, F("mqttServer2"));
|
||||||
mqttPort = jsonReadInt(settingsFlashJson, F("mqttPort2"));
|
mqttPort = jsonReadInt(settingsFlashJson, F("mqttPort2"));
|
||||||
mqttPrefix = jsonReadStr(settingsFlashJson, F("mqttPrefix2"));
|
|
||||||
mqttUser = jsonReadStr(settingsFlashJson, F("mqttUser2"));
|
mqttUser = jsonReadStr(settingsFlashJson, F("mqttUser2"));
|
||||||
mqttPass = jsonReadStr(settingsFlashJson, F("mqttPass2"));
|
mqttPass = jsonReadStr(settingsFlashJson, F("mqttPass2"));
|
||||||
prex = mqttPrefix + "/" + chipId;
|
// prex = mqttPrefix + "/" + chipId;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isSecondBrokerSet() {
|
bool isSecondBrokerSet() {
|
||||||
@@ -125,8 +123,6 @@ boolean mqttConnect() {
|
|||||||
}
|
}
|
||||||
SerialPrint("I", "MQTT", "connection started to broker No " + String(currentBroker));
|
SerialPrint("I", "MQTT", "connection started to broker No " + String(currentBroker));
|
||||||
|
|
||||||
mqttRootDevice = mqttPrefix + "/" + chipId;
|
|
||||||
|
|
||||||
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);
|
||||||
@@ -147,16 +143,16 @@ boolean mqttConnect() {
|
|||||||
|
|
||||||
if (connected) {
|
if (connected) {
|
||||||
SerialPrint("I", F("MQTT"), F("✔ connected"));
|
SerialPrint("I", F("MQTT"), F("✔ connected"));
|
||||||
if (currentBroker == 1) jsonWriteStr(settingsFlashJson, F("warning4"), F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #8ef584; padding: 10px;'>Подключено к основному брокеру</p></font></div>"));
|
// if (currentBroker == 1) jsonWriteStr(settingsFlashJson, F("warning4"), F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #8ef584; padding: 10px;'>Подключено к основному брокеру</p></font></div>"));
|
||||||
if (currentBroker == 2) jsonWriteStr(settingsFlashJson, F("warning4"), F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #8ef584; padding: 10px;'>Подключено к резервному брокеру</p></font></div>"));
|
// if (currentBroker == 2) jsonWriteStr(settingsFlashJson, F("warning4"), F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #8ef584; padding: 10px;'>Подключено к резервному брокеру</p></font></div>"));
|
||||||
// setLedStatus(LED_OFF);
|
// setLedStatus(LED_OFF);
|
||||||
mqttSubscribe();
|
mqttSubscribe();
|
||||||
res = true;
|
res = true;
|
||||||
} else {
|
} else {
|
||||||
mqttConnectAttempts++;
|
mqttConnectAttempts++;
|
||||||
SerialPrint("E", F("MQTT"), "🡆 Attempt No: " + String(mqttConnectAttempts) + " could't connect, retry in " + String(MQTT_RECONNECT_INTERVAL / 1000) + "s");
|
SerialPrint("E", F("MQTT"), "🡆 Attempt No: " + String(mqttConnectAttempts) + " could't connect, retry in " + String(MQTT_RECONNECT_INTERVAL / 1000) + "s");
|
||||||
// setLedStatus(LED_FAST);
|
// setLedStatus(LED_FAST);
|
||||||
jsonWriteStr(settingsFlashJson, F("warning4"), F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #fa987a; padding: 10px;'>Не подключено брокеру</p></font></div>"));
|
// jsonWriteStr(settingsFlashJson, F("warning4"), F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #fa987a; padding: 10px;'>Не подключено брокеру</p></font></div>"));
|
||||||
if (mqttConnectAttempts >= CHANGE_BROKER_AFTER) {
|
if (mqttConnectAttempts >= CHANGE_BROKER_AFTER) {
|
||||||
mqttConnectAttempts = 0;
|
mqttConnectAttempts = 0;
|
||||||
if (isSecondBrokerSet()) {
|
if (isSecondBrokerSet()) {
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
|||||||
sendFileToWs5("/items.json", num, 1024);
|
sendFileToWs5("/items.json", num, 1024);
|
||||||
sendFileToWs5("/widgets.json", num, 1024);
|
sendFileToWs5("/widgets.json", num, 1024);
|
||||||
sendFileToWs5("/config.json", num, 1024);
|
sendFileToWs5("/config.json", num, 1024);
|
||||||
|
sendFileToWs5("/settings.json", num, 1024);
|
||||||
}
|
}
|
||||||
if (headerStr == "/gifnoc") {
|
if (headerStr == "/gifnoc") {
|
||||||
writeFileUint8tByFrames("config.json", payload, length, headerLenth, 256);
|
writeFileUint8tByFrames("config.json", payload, length, headerLenth, 256);
|
||||||
@@ -129,7 +130,7 @@ void sendFileToWs5(const char* filename, uint8_t num, size_t frameSize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void publishStatusWs(const String& topic, const String& data) {
|
void publishStatusWs(const String& topic, const String& data) {
|
||||||
String path = mqttRootDevice + "/" + topic + "/status";
|
String path = mqttRootDevice + "/" + topic; //+ "/status";
|
||||||
String json = "{}";
|
String json = "{}";
|
||||||
jsonWriteStr(json, "status", data);
|
jsonWriteStr(json, "status", data);
|
||||||
jsonWriteStr(json, "topic", path);
|
jsonWriteStr(json, "topic", path);
|
||||||
|
|||||||
Reference in New Issue
Block a user