This commit is contained in:
Dmitry Borisenko
2020-12-11 17:37:29 +03:00
parent 71468599fe
commit 3e5d9770a1
10 changed files with 105 additions and 43 deletions

View File

@@ -18,8 +18,8 @@
"teleginput":"0", "teleginput":"0",
"weblogin": "admin", "weblogin": "admin",
"webpass": "admin", "webpass": "admin",
"snaUdp": "0", "MqttIn": "0",
"snaMqtt": "0", "MqttOut": "0",
"blink": "1", "blink": "1",
"oneWirePin": "2", "oneWirePin": "2",
"serverip": "http://206.189.49.244", "serverip": "http://206.189.49.244",

View File

@@ -37,9 +37,19 @@
"class": "btn btn-block btn-default" "class": "btn btn-block btn-default"
}, },
{ {
"type": "link", "type": "hr"
},
{
"type": "h3",
"name": "reset-block",
"style": "position:fixed;top:50%;left:50%;width:400px;margin-left:-200px;text-align:center;",
"class": "hidden"
},
{
"type": "button",
"title": "Перезагрузить устройство", "title": "Перезагрузить устройство",
"action": "javascript:if(confirm(renameBlock(jsonResponse,'Перезагрузить?'))){send_request(this,'/set?device=ok');}", "action": "/set?reqReset",
"response": "[[reset-block]]",
"class": "btn btn-block btn-danger" "class": "btn btn-block btn-danger"
} }
] ]

View File

@@ -43,7 +43,7 @@
}, },
{ {
"type": "h4", "type": "h4",
"title": "Версия файловой системы: 271" "title": "Версия файловой системы: 272"
}, },
{ {
"type": "h4", "type": "h4",
@@ -179,10 +179,20 @@
}, },
{ {
"type": "checkbox", "type": "checkbox",
"name": "snaMqtt", "name": "MqttOut",
"title": "Включить единые сценарии для всех устройств", "title": "Передавать события другим устройствам",
"action": "/set?snaMqtt=[[snaMqtt]]", "action": "/set?MqttOut=[[MqttOut]]",
"state": "{{snaMqtt}}" "state": "{{MqttOut}}"
},
{
"type": "hr"
},
{
"type": "checkbox",
"name": "MqttIn",
"title": "Принимать события с других устройств",
"action": "/set?MqttIn=[[MqttIn]]",
"state": "{{MqttIn}}"
}, },
{ {
"type": "hr" "type": "hr"
@@ -234,9 +244,16 @@
"type": "hr" "type": "hr"
}, },
{ {
"type": "link", "type": "h3",
"name": "reset-block",
"style": "position:fixed;top:50%;left:50%;width:400px;margin-left:-200px;text-align:center;",
"class": "hidden"
},
{
"type": "button",
"title": "Перезагрузить устройство", "title": "Перезагрузить устройство",
"action": "javascript:if(confirm(renameBlock(jsonResponse,'Перезагрузить?'))){send_request(this,'/set?device=ok');}", "action": "/set?reqReset",
"response": "[[reset-block]]",
"class": "btn btn-block btn-danger" "class": "btn btn-block btn-danger"
} }
] ]

View File

@@ -9,7 +9,6 @@
"type": "h5", "type": "h5",
"title": "{{name}}", "title": "{{name}}",
"class": "alert-default" "class": "alert-default"
}, },
{ {
"type": "link", "type": "link",
@@ -20,7 +19,6 @@
{ {
"type": "hr" "type": "hr"
}, },
{ {
"type": "h4", "type": "h4",
"title": "{{SetMQTTServerName}}", "title": "{{SetMQTTServerName}}",
@@ -87,7 +85,6 @@
"style": "position:fixed;top:30%;left:50%;width:400px;margin-left:-200px;text-align:center;", "style": "position:fixed;top:30%;left:50%;width:400px;margin-left:-200px;text-align:center;",
"class": "hidden" "class": "hidden"
}, },
{ {
"type": "button", "type": "button",
"title": "{{ButSave}}", "title": "{{ButSave}}",
@@ -102,7 +99,6 @@
"action": "set?mqttsend", "action": "set?mqttsend",
"class": "btn btn-block btn-default" "class": "btn btn-block btn-default"
}, },
{ {
"type": "button", "type": "button",
"style": "width:100%;float:left;", "style": "width:100%;float:left;",
@@ -115,7 +111,6 @@
"type": "text", "type": "text",
"style": "width:100%;float:left;", "style": "width:100%;float:left;",
"title": "<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #F5F5F5; padding: 10px;'>{{SetMQTTWarn1}}</p></font></div>" "title": "<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #F5F5F5; padding: 10px;'>{{SetMQTTWarn1}}</p></font></div>"
}, },
{ {
"type": "text", "type": "text",
@@ -123,10 +118,19 @@
"title": "<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #F5F5F5; padding: 10px;'>{{SetMQTTWarn2}}</p></font></div>" "title": "<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #F5F5F5; padding: 10px;'>{{SetMQTTWarn2}}</p></font></div>"
}, },
{ {
"type": "link", "type": "hr"
"style": "width:100%;float:left;", },
{
"type": "h3",
"name": "reset-block",
"style": "position:fixed;top:50%;left:50%;width:400px;margin-left:-200px;text-align:center;",
"class": "hidden"
},
{
"type": "button",
"title": "Перезагрузить устройство", "title": "Перезагрузить устройство",
"action": "javascript:if(confirm(renameBlock(jsonResponse,'Перезагрузить?'))){send_request(this,'/restart?device=ok');}", "action": "/set?reqReset",
"response": "[[reset-block]]",
"class": "btn btn-block btn-danger" "class": "btn btn-block btn-danger"
} }
] ]

View File

@@ -49,7 +49,6 @@
"name": "chatId-arg", "name": "chatId-arg",
"state": "{{chatId}}" "state": "{{chatId}}"
}, },
{ {
"type": "h4", "type": "h4",
"title": "Telegram API token" "title": "Telegram API token"
@@ -78,9 +77,16 @@
"type": "hr" "type": "hr"
}, },
{ {
"type": "link", "type": "h3",
"name": "reset-block",
"style": "position:fixed;top:50%;left:50%;width:400px;margin-left:-200px;text-align:center;",
"class": "hidden"
},
{
"type": "button",
"title": "Перезагрузить устройство", "title": "Перезагрузить устройство",
"action": "javascript:if(confirm(renameBlock(jsonResponse,'Перезагрузить?'))){send_request(this,'/set?device=ok');}", "action": "/set?reqReset",
"response": "[[reset-block]]",
"class": "btn btn-block btn-danger" "class": "btn btn-block btn-danger"
} }
] ]

View File

@@ -175,9 +175,16 @@
"type": "hr" "type": "hr"
}, },
{ {
"type": "link", "type": "h3",
"name": "reset-block",
"style": "position:fixed;top:50%;left:50%;width:400px;margin-left:-200px;text-align:center;",
"class": "hidden"
},
{
"type": "button",
"title": "Перезагрузить устройство", "title": "Перезагрузить устройство",
"action": "javascript:if(confirm(renameBlock(jsonResponse,'Перезагрузить?'))){send_request(this,'/set?device=ok');}", "action": "/set?reqReset",
"response": "[[reset-block]]",
"class": "btn btn-block btn-danger" "class": "btn btn-block btn-danger"
} }
] ]

View File

@@ -1,13 +1,18 @@
#pragma once #pragma once
//===========Firmware============================================================================================================================================= //===========Firmware=============================================================================================================================================
#define FIRMWARE_VERSION 271 #define FIRMWARE_VERSION 272
//#define FLASH_SIZE_1MB true //#define FLASH_SIZE_1MB true
#ifdef ESP8266 #ifdef ESP8266
#define FIRMWARE_NAME "esp8266-iotm" #ifdef FLASH_SIZE_1MB
#define FIRMWARE_NAME "esp8266-1mb"
#else
#define FIRMWARE_NAME "esp8266"
#endif
#endif #endif
#ifdef ESP32 #ifdef ESP32
#define FIRMWARE_NAME "esp32-iotm" #define FIRMWARE_NAME "esp32"
#endif #endif
//===========FSystem============================================================================================================================================== //===========FSystem==============================================================================================================================================

View File

@@ -10,20 +10,21 @@ void eventGen2(String eventName, String eventValue) {
String event = eventName + " " + eventValue + ","; String event = eventName + " " + eventValue + ",";
eventBuf += event; eventBuf += event;
if (jsonReadBool(configSetupJson, "snaMqtt")) publishEvent(eventName, eventValue); if (jsonReadBool(configSetupJson, "MqttOut")) {
//streamEventUDP(event); publishEvent(eventName, eventValue);
}
} }
void streamEventUDP(String event) { void streamEventUDP(String event) {
#ifdef UDP_ENABLED #ifdef UDP_ENABLED
if (!jsonReadBool(configSetupJson, "snaUdp")) { if (!jsonReadBool(configSetupJson, "snaUdp")) {
return; return;
} }
if (event.indexOf("timenow") == -1) { if (event.indexOf("timenow") == -1) {
event = "iotm;event:" + event; event = "iotm;event:" + event;
asyncUdp.broadcastTo(event.c_str(), 4210); asyncUdp.broadcastTo(event.c_str(), 4210);
} }
#endif #endif
} }

View File

@@ -71,7 +71,7 @@ void mqttSubscribe() {
mqtt.subscribe((mqttRootDevice + "/+/control").c_str()); mqtt.subscribe((mqttRootDevice + "/+/control").c_str());
mqtt.subscribe((mqttRootDevice + "/update").c_str()); mqtt.subscribe((mqttRootDevice + "/update").c_str());
if (jsonReadBool(configSetupJson, "snaMqtt")) { if (jsonReadBool(configSetupJson, "MqttIn")) {
mqtt.subscribe((mqttPrefix + "/+/+/event").c_str()); mqtt.subscribe((mqttPrefix + "/+/+/event").c_str());
mqtt.subscribe((mqttPrefix + "/+/+/info").c_str()); mqtt.subscribe((mqttPrefix + "/+/+/info").c_str());
} }
@@ -143,7 +143,7 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) {
} }
else if (topicStr.indexOf("event") != -1) { else if (topicStr.indexOf("event") != -1) {
if (!jsonReadBool(configSetupJson, "snaMqtt")) { if (!jsonReadBool(configSetupJson, "MqttIn")) {
return; return;
} }
if (topicStr.indexOf(chipId) == -1) { if (topicStr.indexOf(chipId) == -1) {
@@ -215,7 +215,7 @@ boolean publishStatus(const String& topic, const String& data) {
boolean publishEvent(const String& topic, const String& data) { boolean publishEvent(const String& topic, const String& data) {
String path = mqttRootDevice + "/" + topic + "/event"; String path = mqttRootDevice + "/" + topic + "/event";
return mqtt.publish(path.c_str(), data.c_str(), false); return mqtt.publish(path.c_str(), data.c_str(), true);
} }
boolean publishInfo(const String& topic, const String& data) { boolean publishInfo(const String& topic, const String& data) {

View File

@@ -88,15 +88,22 @@ void web_init() {
// request->send(200); // request->send(200);
//} //}
if (request->hasArg("snaMqtt")) { if (request->hasArg("MqttIn")) {
bool value = request->getParam("snaMqtt")->value().toInt(); bool value = request->getParam("MqttIn")->value().toInt();
jsonWriteBool(configSetupJson, "snaMqtt", value); jsonWriteBool(configSetupJson, "MqttIn", value);
saveConfig(); saveConfig();
mqtt.subscribe((mqttPrefix + "/+/+/status").c_str()); mqtt.subscribe((mqttPrefix + "/+/+/event").c_str());
mqtt.subscribe((mqttPrefix + "/+/+/info").c_str()); mqtt.subscribe((mqttPrefix + "/+/+/info").c_str());
request->send(200); request->send(200);
} }
if (request->hasArg("MqttOut")) {
bool value = request->getParam("MqttOut")->value().toInt();
jsonWriteBool(configSetupJson, "MqttOut", value);
saveConfig();
request->send(200);
}
if (request->hasArg("scenMqtt")) { if (request->hasArg("scenMqtt")) {
myNotAsyncActions->make(do_sendScenMQTT); myNotAsyncActions->make(do_sendScenMQTT);
request->send(200); request->send(200);
@@ -175,10 +182,15 @@ void web_init() {
request->send(200); request->send(200);
} }
if (request->hasArg("device")) { if (request->hasArg("reqReset")) {
if (request->getParam("device")->value() == "ok") { String tmp = "{}";
ESP.restart(); jsonWriteStr(tmp, "title", F("<button class=\"close\" onclick=\"toggle('reset-block')\">×</button>Вы действительно хотите перезагрузить устройство?<a href=\"#\" class=\"btn btn-block btn-danger\" onclick=\"send_request(this, '/set?reset');setTimeout(function(){ location.href='/?set.device'; }, 15000);html('reset-block','<span class=loader></span>Идет перезагрузка устройства')\">Перезагрузить</a>"));
} jsonWriteStr(tmp, "class", "pop-up");
request->send(200, "text/html", tmp);
}
if (request->hasArg("reset")) {
ESP.restart();
request->send(200); request->send(200);
} }