udp changed for Vadim

This commit is contained in:
Dmitry Borisenko
2020-11-08 18:27:01 +03:00
parent 9d6ec18bb2
commit 6d52a181f0
4 changed files with 41 additions and 22 deletions

View File

@@ -3,8 +3,8 @@
"chipID": "", "chipID": "",
"apssid": "IoTmanager", "apssid": "IoTmanager",
"appass": "", "appass": "",
"routerssid": "VOLODYA", "routerssid": "rise",
"routerpass": "BELCHENKO", "routerpass": "hostel3333",
"timezone": 1, "timezone": 1,
"ntp": "pool.ntp.org", "ntp": "pool.ntp.org",
"mqttServer": "m12.cloudmqtt.com", "mqttServer": "m12.cloudmqtt.com",

View File

@@ -1,4 +1,5 @@
{ {
"widget": "chart", "widget": "chart",
"dateFormat": "HH:mm" "dateFormat": "HH:mm",
"pointRadius": 0
} }

View File

@@ -31,7 +31,7 @@
//#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
//=========Sensors enable/disable================================================================================================================================= //=========Sensors enable/disable=================================================================================================================================

View File

@@ -6,22 +6,21 @@
AsyncUDP asyncUdp; AsyncUDP asyncUdp;
void asyncUdpInit() { void asyncUdpInit() {
//if (asyncUdp.listen(1234)) { if (asyncUdp.listenMulticast(IPAddress(239, 255, 255, 255), 4210)) {
if (asyncUdp.listenMulticast(IPAddress(239, 255, 255, 255), 1234)) {
asyncUdp.onPacket([](AsyncUDPPacket packet) { asyncUdp.onPacket([](AsyncUDPPacket packet) {
//Serial.print("UDP Packet Type: "); Serial.print("UDP Packet Type: ");
//Serial.print(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast" : "Unicast"); Serial.println(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast" : "Unicast");
//
//Serial.print(", From: "); Serial.print("From: ");
//Serial.print(packet.remoteIP()); Serial.print(packet.remoteIP());
//Serial.print(":"); Serial.print(":");
//Serial.print(packet.remotePort()); Serial.println(packet.remotePort());
//
//Serial.print(", To: "); Serial.print("To: ");
//Serial.print(packet.localIP()); Serial.print(packet.localIP());
//Serial.print(":"); Serial.print(":");
//Serial.print(packet.localPort()); Serial.println(packet.localPort());
//
//Serial.print(", Length: "); //Serial.print(", Length: ");
//Serial.print(packet.length()); //Serial.print(packet.length());
// //
@@ -34,15 +33,33 @@ void asyncUdpInit() {
if (udpPacketValidation(data)) { if (udpPacketValidation(data)) {
udpPacketParse(data); udpPacketParse(data);
//Serial.println("', Packet valid"); //Serial.println("', Packet valid");
} else { }
else {
//Serial.println("', Packet invalid"); //Serial.println("', Packet invalid");
} }
//reply to the client //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) { String uint8tToString(uint8_t* data, size_t len) {
@@ -56,7 +73,8 @@ String uint8tToString(uint8_t* data, size_t len) {
bool udpPacketValidation(String& data) { bool udpPacketValidation(String& data) {
if (data.indexOf("iotm;") != -1 && data.indexOf(getChipId()) != -1) { if (data.indexOf("iotm;") != -1 && data.indexOf(getChipId()) != -1) {
return true; return true;
} else { }
else {
return false; return false;
} }
} }