mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
Single network space for scenario added
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
"telegonof": "0",
|
||||
"weblogin": "admin",
|
||||
"webpass": "admin",
|
||||
"udponoff": "1",
|
||||
"onescen": "1",
|
||||
"blink": "1",
|
||||
"oneWirePin": "2",
|
||||
"serverip": "http://206.189.49.244"
|
||||
|
||||
@@ -170,6 +170,25 @@
|
||||
{
|
||||
"type": "hr"
|
||||
},
|
||||
{
|
||||
"type": "checkbox",
|
||||
"name": "onescen",
|
||||
"title": "Включить единые сценарии для всех устройств",
|
||||
"action": "/set?onescen=[[onescen]]",
|
||||
"state": "{{onescen}}"
|
||||
},
|
||||
{
|
||||
"type": "hr"
|
||||
},
|
||||
{
|
||||
"type": "button",
|
||||
"title": "Отправить сценарии всем устройствам в локальной сети",
|
||||
"action": "/set?scenudp",
|
||||
"class": "btn btn-block btn-default"
|
||||
},
|
||||
{
|
||||
"type": "hr"
|
||||
},
|
||||
{
|
||||
"type": "button",
|
||||
"title": "Очистить графики и введенные данные",
|
||||
|
||||
@@ -69,4 +69,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
extern Scenario* myScenario;
|
||||
extern Scenario* myScenario;
|
||||
|
||||
extern void streamEventUDP(String event);
|
||||
@@ -31,9 +31,8 @@
|
||||
//#define MDNS_ENABLED
|
||||
//#define WEBSOCKET_ENABLED
|
||||
//#define LAYOUT_IN_RAM
|
||||
//#define UDP_ENABLED
|
||||
#define UDP_ENABLED
|
||||
//#define SSDP_ENABLED
|
||||
#define SAVE_SETTINGS_TO_FLASH
|
||||
|
||||
//=========Sensors enable/disable=================================================================================================================================
|
||||
#define LEVEL_ENABLED
|
||||
@@ -83,12 +82,11 @@ enum NotAsyncActions {
|
||||
do_ZERO,
|
||||
do_UPGRADE,
|
||||
do_GETLASTVERSION,
|
||||
do_UDPDATAPARSE,
|
||||
do_MQTTUDP,
|
||||
do_BUSSCAN,
|
||||
do_MQTTPARAMSCHANGED,
|
||||
do_deviceInit,
|
||||
do_delChoosingItems,
|
||||
do_sendScenUDP,
|
||||
do_LAST,
|
||||
};
|
||||
|
||||
|
||||
@@ -1,13 +1,28 @@
|
||||
#include "Class/ScenarioClass3.h"
|
||||
#include "MqttClient.h"
|
||||
#include "RemoteOrdersUdp.h"
|
||||
Scenario* myScenario;
|
||||
|
||||
void eventGen2(String eventName, String eventValue) {
|
||||
if (!jsonReadBool(configSetupJson, "scen")) {
|
||||
return;
|
||||
}
|
||||
//Serial.println(eventName + " " + eventValue);
|
||||
eventBuf += eventName + " " + eventValue + ",";
|
||||
String event = eventName + " " + eventValue + ",";
|
||||
eventBuf += event;
|
||||
|
||||
//publish(mqttPrefix, eventName + " " + eventValue + ",");
|
||||
streamEventUDP(event);
|
||||
}
|
||||
|
||||
void streamEventUDP(String event) {
|
||||
#ifdef UDP_ENABLED
|
||||
|
||||
if (!jsonReadBool(configSetupJson, "onescen")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.indexOf("timenow") == -1) {
|
||||
event = "iotm;event:" + event;
|
||||
asyncUdp.broadcastTo(event.c_str(), 4210);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,26 +1,33 @@
|
||||
#include "RemoteOrdersUdp.h"
|
||||
#include <Arduino.h>
|
||||
#include "Global.h"
|
||||
#include "Class/NotAsync.h"
|
||||
#include "Init.h"
|
||||
|
||||
#ifdef UDP_ENABLED
|
||||
AsyncUDP asyncUdp;
|
||||
|
||||
void asyncUdpInit() {
|
||||
|
||||
if (!jsonReadBool(configSetupJson, "onescen")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (asyncUdp.listenMulticast(IPAddress(239, 255, 255, 255), 4210)) {
|
||||
asyncUdp.onPacket([](AsyncUDPPacket packet) {
|
||||
Serial.print("UDP Packet Type: ");
|
||||
Serial.println(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast" : "Unicast");
|
||||
|
||||
Serial.print("From: ");
|
||||
Serial.print(packet.remoteIP());
|
||||
Serial.print(":");
|
||||
Serial.println(packet.remotePort());
|
||||
|
||||
Serial.print("To: ");
|
||||
Serial.print(packet.localIP());
|
||||
Serial.print(":");
|
||||
Serial.println(packet.localPort());
|
||||
|
||||
//Serial.print("UDP Packet Type: ");
|
||||
//Serial.println(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast" : "Unicast");
|
||||
//
|
||||
//Serial.print("From: ");
|
||||
//Serial.print(packet.remoteIP());
|
||||
//Serial.print(":");
|
||||
//Serial.println(packet.remotePort());
|
||||
//
|
||||
//Serial.print("To: ");
|
||||
//Serial.print(packet.localIP());
|
||||
//Serial.print(":");
|
||||
//Serial.println(packet.localPort());
|
||||
//Serial.print(", Length: ");
|
||||
//Serial.print(packet.length());
|
||||
//
|
||||
@@ -30,35 +37,65 @@ void asyncUdpInit() {
|
||||
String data = uint8tToString(packet.data(), packet.length());
|
||||
Serial.print("[i] [udp] Packet received: '");
|
||||
Serial.print(data);
|
||||
|
||||
if (udpPacketValidation(data)) {
|
||||
Serial.println("', packet valid");
|
||||
udpPacketParse(data);
|
||||
//Serial.println("', Packet valid");
|
||||
}
|
||||
else {
|
||||
//Serial.println("', Packet invalid");
|
||||
}
|
||||
|
||||
|
||||
//else {
|
||||
// //Serial.println("', Packet invalid");
|
||||
//}
|
||||
//reply to the client
|
||||
|
||||
String ip = WiFi.localIP().toString();
|
||||
asyncUdp.broadcastTo(ip.c_str(), packet.remotePort());
|
||||
|
||||
//String ip = WiFi.localIP().toString();
|
||||
//asyncUdp.broadcastTo(ip.c_str(), packet.remotePort());
|
||||
//packet.printf(ip.c_str(), packet.length());
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
ts.add(
|
||||
UDP, 10000, [&](void*) {
|
||||
myNotAsyncActions->add(
|
||||
do_sendScenUDP, [&](void*) {
|
||||
|
||||
Serial.println("sended");
|
||||
asyncUdp.broadcastTo("Anyone here?", 64130);
|
||||
//asyncUdp.broadcast("test");
|
||||
//asyncUdp.print("Hello Server!");
|
||||
String scen = "iotm;scen:";
|
||||
scen += readFile(String(DEVICE_SCENARIO_FILE), 2048);
|
||||
|
||||
asyncUdp.broadcastTo(scen.c_str(), 4210);
|
||||
|
||||
},
|
||||
nullptr, true);
|
||||
nullptr);
|
||||
|
||||
//ts.add(
|
||||
//UDP, 10000, [&](void*) {
|
||||
//Serial.println("sended");
|
||||
//asyncUdp.broadcastTo("iotm;Anyone here?", 4210);
|
||||
//asyncUdp.broadcast("test");
|
||||
//asyncUdp.print("Hello Server!");
|
||||
//},
|
||||
//nullptr, true);
|
||||
|
||||
}
|
||||
|
||||
bool udpPacketValidation(String& data) {
|
||||
if (data.indexOf("iotm;") != -1) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void udpPacketParse(String& data) {
|
||||
if (data.indexOf("scen:") != -1) {
|
||||
data = deleteBeforeDelimiter(data, ":");
|
||||
writeFile(String(DEVICE_SCENARIO_FILE), data);
|
||||
loadScenario();
|
||||
}
|
||||
else if (data.indexOf("event:") != -1) {
|
||||
data = deleteBeforeDelimiter(data, ":");
|
||||
eventBuf += data;
|
||||
}
|
||||
}
|
||||
|
||||
String uint8tToString(uint8_t* data, size_t len) {
|
||||
@@ -68,20 +105,4 @@ String uint8tToString(uint8_t* data, size_t len) {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool udpPacketValidation(String& data) {
|
||||
if (data.indexOf("iotm;") != -1 && data.indexOf(getChipId()) != -1) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//iotm;chipid;button-out-1_1
|
||||
void udpPacketParse(String& data) {
|
||||
data = selectFromMarkerToMarker(data, ";", 2);
|
||||
data.replace("_", " ");
|
||||
orderBuf += data + ",";
|
||||
}
|
||||
#endif
|
||||
16
src/Web.cpp
16
src/Web.cpp
@@ -5,6 +5,7 @@
|
||||
#include "ItemsList.h"
|
||||
#include "items/vLogging.h"
|
||||
#include "Telegram.h"
|
||||
#include "RemoteOrdersUdp.h"
|
||||
|
||||
bool parseRequestForPreset(AsyncWebServerRequest* request, uint8_t& preset) {
|
||||
if (request->hasArg("preset")) {
|
||||
@@ -60,6 +61,19 @@ void web_init() {
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
if (request->hasArg("onescen")) {
|
||||
bool value = request->getParam("onescen")->value().toInt();
|
||||
jsonWriteBool(configSetupJson, "onescen", value);
|
||||
saveConfig();
|
||||
asyncUdpInit();
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
if (request->hasArg("scenudp")) {
|
||||
myNotAsyncActions->make(do_sendScenUDP);
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
#ifdef LOGGING_ENABLED
|
||||
if (request->hasArg("cleanlog")) {
|
||||
cleanLogAndData();
|
||||
@@ -182,7 +196,7 @@ void web_init() {
|
||||
}
|
||||
|
||||
if (request->hasArg("mqttsend")) {
|
||||
myNotAsyncActions->make(do_MQTTUDP);
|
||||
//myNotAsyncActions->make(do_MQTTUDP);
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user