mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
udp changed for Vadim
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
"chipID": "",
|
||||
"apssid": "IoTmanager",
|
||||
"appass": "",
|
||||
"routerssid": "VOLODYA",
|
||||
"routerpass": "BELCHENKO",
|
||||
"routerssid": "rise",
|
||||
"routerpass": "hostel3333",
|
||||
"timezone": 1,
|
||||
"ntp": "pool.ntp.org",
|
||||
"mqttServer": "m12.cloudmqtt.com",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"widget": "chart",
|
||||
"dateFormat": "HH:mm"
|
||||
"dateFormat": "HH:mm",
|
||||
"pointRadius": 0
|
||||
}
|
||||
@@ -31,7 +31,7 @@
|
||||
//#define MDNS_ENABLED
|
||||
//#define WEBSOCKET_ENABLED
|
||||
//#define LAYOUT_IN_RAM
|
||||
//#define UDP_ENABLED
|
||||
#define UDP_ENABLED
|
||||
//#define SSDP_ENABLED
|
||||
|
||||
//=========Sensors enable/disable=================================================================================================================================
|
||||
|
||||
@@ -6,22 +6,21 @@
|
||||
AsyncUDP asyncUdp;
|
||||
|
||||
void asyncUdpInit() {
|
||||
//if (asyncUdp.listen(1234)) {
|
||||
if (asyncUdp.listenMulticast(IPAddress(239, 255, 255, 255), 1234)) {
|
||||
if (asyncUdp.listenMulticast(IPAddress(239, 255, 255, 255), 4210)) {
|
||||
asyncUdp.onPacket([](AsyncUDPPacket packet) {
|
||||
//Serial.print("UDP Packet Type: ");
|
||||
//Serial.print(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast" : "Unicast");
|
||||
//
|
||||
//Serial.print(", From: ");
|
||||
//Serial.print(packet.remoteIP());
|
||||
//Serial.print(":");
|
||||
//Serial.print(packet.remotePort());
|
||||
//
|
||||
//Serial.print(", To: ");
|
||||
//Serial.print(packet.localIP());
|
||||
//Serial.print(":");
|
||||
//Serial.print(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());
|
||||
//
|
||||
@@ -34,15 +33,33 @@ void asyncUdpInit() {
|
||||
if (udpPacketValidation(data)) {
|
||||
udpPacketParse(data);
|
||||
//Serial.println("', Packet valid");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
//Serial.println("', Packet invalid");
|
||||
}
|
||||
|
||||
//reply to the client
|
||||
|
||||
packet.printf("Got %u bytes of data", packet.length());
|
||||
String ip = WiFi.localIP().toString();
|
||||
asyncUdp.broadcastTo(ip.c_str(), packet.remotePort());
|
||||
|
||||
//packet.printf(ip.c_str(), packet.length());
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
//ts.add(
|
||||
// UDP, 10000, [&](void*) {
|
||||
//
|
||||
// //Serial.println("sended");
|
||||
//
|
||||
// //asyncUdp.broadcastTo("Anyone here?", 5351);
|
||||
// //asyncUdp.broadcast("test");
|
||||
// //asyncUdp.print("Hello Server!");
|
||||
//
|
||||
// },
|
||||
// nullptr, true);
|
||||
|
||||
}
|
||||
|
||||
String uint8tToString(uint8_t* data, size_t len) {
|
||||
@@ -56,7 +73,8 @@ String uint8tToString(uint8_t* data, size_t len) {
|
||||
bool udpPacketValidation(String& data) {
|
||||
if (data.indexOf("iotm;") != -1 && data.indexOf(getChipId()) != -1) {
|
||||
return true;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user