UDP Packets appear in wireshark and UDPlistener
This commit is contained in:
parent
c49c511d75
commit
0991343a55
53
UDP.ino
53
UDP.ino
|
@ -1,14 +1,27 @@
|
|||
const char* ssid = "CaveBot";
|
||||
const char* password = "&nHM%D2!$]Qg[VUv";
|
||||
|
||||
#include "WiFi.h"
|
||||
#include "AsyncUDP.h"
|
||||
|
||||
const char * ssid = "CaveBot";
|
||||
const char * password = "Eating0-Untaxed0-Pod6-Jokester8";
|
||||
const IPAddress multicastIP = IPAddress(239, 1, 2, 3);
|
||||
int port = 1234;
|
||||
|
||||
AsyncUDP udp;
|
||||
|
||||
void UdpInit()
|
||||
{
|
||||
void UdpInit() {
|
||||
//Serial.begin(115200);
|
||||
ConnectToWiFi();
|
||||
//udp.connect(multicastIP, port);
|
||||
}
|
||||
|
||||
void UdpLoop() {
|
||||
byte data[8] = {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
udp.writeTo(data, sizeof(data), multicastIP, port);
|
||||
}
|
||||
|
||||
|
||||
void ConnectToWiFi() {
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(ssid, password);
|
||||
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
|
||||
|
@ -17,36 +30,4 @@ void UdpInit()
|
|||
delay(1000);
|
||||
}
|
||||
}
|
||||
if(udp.listenMulticast(IPAddress(239,1,2,3), 1234)) {
|
||||
Serial.print("UDP Listening on IP: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
udp.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(", Length: ");
|
||||
Serial.print(packet.length());
|
||||
Serial.print(", Data: ");
|
||||
Serial.write(packet.data(), packet.length());
|
||||
Serial.println();
|
||||
//reply to the client
|
||||
packet.printf("Got %u bytes of data", packet.length());
|
||||
});
|
||||
//Send multicast
|
||||
udp.print("Hello!");
|
||||
}
|
||||
}
|
||||
|
||||
void UdpLoop()
|
||||
{
|
||||
delay(1000);
|
||||
//Send multicast
|
||||
udp.print("Anyone here?");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue