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

@@ -10,20 +10,21 @@ void eventGen2(String eventName, String eventValue) {
String event = eventName + " " + eventValue + ",";
eventBuf += event;
if (jsonReadBool(configSetupJson, "snaMqtt")) publishEvent(eventName, eventValue);
//streamEventUDP(event);
if (jsonReadBool(configSetupJson, "MqttOut")) {
publishEvent(eventName, eventValue);
}
}
void streamEventUDP(String event) {
#ifdef UDP_ENABLED
#ifdef UDP_ENABLED
if (!jsonReadBool(configSetupJson, "snaUdp")) {
return;
}
if (event.indexOf("timenow") == -1) {
event = "iotm;event:" + event;
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 + "/update").c_str());
if (jsonReadBool(configSetupJson, "snaMqtt")) {
if (jsonReadBool(configSetupJson, "MqttIn")) {
mqtt.subscribe((mqttPrefix + "/+/+/event").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) {
if (!jsonReadBool(configSetupJson, "snaMqtt")) {
if (!jsonReadBool(configSetupJson, "MqttIn")) {
return;
}
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) {
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) {

View File

@@ -88,15 +88,22 @@ void web_init() {
// request->send(200);
//}
if (request->hasArg("snaMqtt")) {
bool value = request->getParam("snaMqtt")->value().toInt();
jsonWriteBool(configSetupJson, "snaMqtt", value);
if (request->hasArg("MqttIn")) {
bool value = request->getParam("MqttIn")->value().toInt();
jsonWriteBool(configSetupJson, "MqttIn", value);
saveConfig();
mqtt.subscribe((mqttPrefix + "/+/+/status").c_str());
mqtt.subscribe((mqttPrefix + "/+/+/event").c_str());
mqtt.subscribe((mqttPrefix + "/+/+/info").c_str());
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")) {
myNotAsyncActions->make(do_sendScenMQTT);
request->send(200);
@@ -175,10 +182,15 @@ void web_init() {
request->send(200);
}
if (request->hasArg("device")) {
if (request->getParam("device")->value() == "ok") {
ESP.restart();
}
if (request->hasArg("reqReset")) {
String tmp = "{}";
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);
}