mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
Single network space for scenario added
This commit is contained in:
@@ -17,7 +17,7 @@
|
|||||||
"telegonof": "0",
|
"telegonof": "0",
|
||||||
"weblogin": "admin",
|
"weblogin": "admin",
|
||||||
"webpass": "admin",
|
"webpass": "admin",
|
||||||
"udponoff": "1",
|
"onescen": "1",
|
||||||
"blink": "1",
|
"blink": "1",
|
||||||
"oneWirePin": "2",
|
"oneWirePin": "2",
|
||||||
"serverip": "http://206.189.49.244"
|
"serverip": "http://206.189.49.244"
|
||||||
|
|||||||
@@ -170,6 +170,25 @@
|
|||||||
{
|
{
|
||||||
"type": "hr"
|
"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",
|
"type": "button",
|
||||||
"title": "Очистить графики и введенные данные",
|
"title": "Очистить графики и введенные данные",
|
||||||
|
|||||||
@@ -70,3 +70,5 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern Scenario* myScenario;
|
extern Scenario* myScenario;
|
||||||
|
|
||||||
|
extern void streamEventUDP(String event);
|
||||||
@@ -31,9 +31,8 @@
|
|||||||
//#define MDNS_ENABLED
|
//#define MDNS_ENABLED
|
||||||
//#define WEBSOCKET_ENABLED
|
//#define WEBSOCKET_ENABLED
|
||||||
//#define LAYOUT_IN_RAM
|
//#define LAYOUT_IN_RAM
|
||||||
//#define UDP_ENABLED
|
#define UDP_ENABLED
|
||||||
//#define SSDP_ENABLED
|
//#define SSDP_ENABLED
|
||||||
#define SAVE_SETTINGS_TO_FLASH
|
|
||||||
|
|
||||||
//=========Sensors enable/disable=================================================================================================================================
|
//=========Sensors enable/disable=================================================================================================================================
|
||||||
#define LEVEL_ENABLED
|
#define LEVEL_ENABLED
|
||||||
@@ -83,12 +82,11 @@ enum NotAsyncActions {
|
|||||||
do_ZERO,
|
do_ZERO,
|
||||||
do_UPGRADE,
|
do_UPGRADE,
|
||||||
do_GETLASTVERSION,
|
do_GETLASTVERSION,
|
||||||
do_UDPDATAPARSE,
|
|
||||||
do_MQTTUDP,
|
|
||||||
do_BUSSCAN,
|
do_BUSSCAN,
|
||||||
do_MQTTPARAMSCHANGED,
|
do_MQTTPARAMSCHANGED,
|
||||||
do_deviceInit,
|
do_deviceInit,
|
||||||
do_delChoosingItems,
|
do_delChoosingItems,
|
||||||
|
do_sendScenUDP,
|
||||||
do_LAST,
|
do_LAST,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,28 @@
|
|||||||
#include "Class/ScenarioClass3.h"
|
#include "Class/ScenarioClass3.h"
|
||||||
#include "MqttClient.h"
|
#include "MqttClient.h"
|
||||||
|
#include "RemoteOrdersUdp.h"
|
||||||
Scenario* myScenario;
|
Scenario* myScenario;
|
||||||
|
|
||||||
void eventGen2(String eventName, String eventValue) {
|
void eventGen2(String eventName, String eventValue) {
|
||||||
if (!jsonReadBool(configSetupJson, "scen")) {
|
if (!jsonReadBool(configSetupJson, "scen")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//Serial.println(eventName + " " + eventValue);
|
String event = eventName + " " + eventValue + ",";
|
||||||
eventBuf += 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 "RemoteOrdersUdp.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
#include "Class/NotAsync.h"
|
||||||
|
#include "Init.h"
|
||||||
|
|
||||||
#ifdef UDP_ENABLED
|
#ifdef UDP_ENABLED
|
||||||
AsyncUDP asyncUdp;
|
AsyncUDP asyncUdp;
|
||||||
|
|
||||||
void asyncUdpInit() {
|
void asyncUdpInit() {
|
||||||
|
|
||||||
|
if (!jsonReadBool(configSetupJson, "onescen")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (asyncUdp.listenMulticast(IPAddress(239, 255, 255, 255), 4210)) {
|
if (asyncUdp.listenMulticast(IPAddress(239, 255, 255, 255), 4210)) {
|
||||||
asyncUdp.onPacket([](AsyncUDPPacket packet) {
|
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(", Length: ");
|
||||||
//Serial.print(packet.length());
|
//Serial.print(packet.length());
|
||||||
//
|
//
|
||||||
@@ -30,35 +37,65 @@ void asyncUdpInit() {
|
|||||||
String data = uint8tToString(packet.data(), packet.length());
|
String data = uint8tToString(packet.data(), packet.length());
|
||||||
Serial.print("[i] [udp] Packet received: '");
|
Serial.print("[i] [udp] Packet received: '");
|
||||||
Serial.print(data);
|
Serial.print(data);
|
||||||
|
|
||||||
if (udpPacketValidation(data)) {
|
if (udpPacketValidation(data)) {
|
||||||
|
Serial.println("', packet valid");
|
||||||
udpPacketParse(data);
|
udpPacketParse(data);
|
||||||
//Serial.println("', Packet valid");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//Serial.println("', Packet invalid");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//else {
|
||||||
|
// //Serial.println("', Packet invalid");
|
||||||
|
//}
|
||||||
//reply to the client
|
//reply to the client
|
||||||
|
//String ip = WiFi.localIP().toString();
|
||||||
String ip = WiFi.localIP().toString();
|
//asyncUdp.broadcastTo(ip.c_str(), packet.remotePort());
|
||||||
asyncUdp.broadcastTo(ip.c_str(), packet.remotePort());
|
|
||||||
|
|
||||||
//packet.printf(ip.c_str(), packet.length());
|
//packet.printf(ip.c_str(), packet.length());
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ts.add(
|
myNotAsyncActions->add(
|
||||||
UDP, 10000, [&](void*) {
|
do_sendScenUDP, [&](void*) {
|
||||||
|
|
||||||
Serial.println("sended");
|
String scen = "iotm;scen:";
|
||||||
asyncUdp.broadcastTo("Anyone here?", 64130);
|
scen += readFile(String(DEVICE_SCENARIO_FILE), 2048);
|
||||||
//asyncUdp.broadcast("test");
|
|
||||||
//asyncUdp.print("Hello Server!");
|
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) {
|
String uint8tToString(uint8_t* data, size_t len) {
|
||||||
@@ -68,20 +105,4 @@ String uint8tToString(uint8_t* data, size_t len) {
|
|||||||
}
|
}
|
||||||
return ret;
|
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
|
#endif
|
||||||
16
src/Web.cpp
16
src/Web.cpp
@@ -5,6 +5,7 @@
|
|||||||
#include "ItemsList.h"
|
#include "ItemsList.h"
|
||||||
#include "items/vLogging.h"
|
#include "items/vLogging.h"
|
||||||
#include "Telegram.h"
|
#include "Telegram.h"
|
||||||
|
#include "RemoteOrdersUdp.h"
|
||||||
|
|
||||||
bool parseRequestForPreset(AsyncWebServerRequest* request, uint8_t& preset) {
|
bool parseRequestForPreset(AsyncWebServerRequest* request, uint8_t& preset) {
|
||||||
if (request->hasArg("preset")) {
|
if (request->hasArg("preset")) {
|
||||||
@@ -60,6 +61,19 @@ void web_init() {
|
|||||||
request->send(200);
|
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
|
#ifdef LOGGING_ENABLED
|
||||||
if (request->hasArg("cleanlog")) {
|
if (request->hasArg("cleanlog")) {
|
||||||
cleanLogAndData();
|
cleanLogAndData();
|
||||||
@@ -182,7 +196,7 @@ void web_init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasArg("mqttsend")) {
|
if (request->hasArg("mqttsend")) {
|
||||||
myNotAsyncActions->make(do_MQTTUDP);
|
//myNotAsyncActions->make(do_MQTTUDP);
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user