Start work on UDP auto-discovery system.
This commit is contained in:
parent
f87a6eb1ad
commit
64191bb39a
|
@ -7,22 +7,31 @@
|
|||
|
||||
#include <ESP8266WiFi.h>
|
||||
|
||||
char ssid[] = "AJ_HullFromHome_F1EAA6E5";
|
||||
char password[] = "humberbridge";
|
||||
char ssid[] = "ssid";
|
||||
char password[] = "password";
|
||||
|
||||
// The address that the PixelHub beacon is broadcasting on.
|
||||
IPAddress beaconAddress(239, 62, 148, 30);
|
||||
// The port number that the PixelHub beacon is broadcasting on.
|
||||
unsigned int beaconPort = 5050;
|
||||
|
||||
// A UDP Client to allow us to recieve UDP datagrams.
|
||||
WiFiUdp UdpClient;
|
||||
// A buffer to store recieved datagrams in.
|
||||
int datagramBufferSize = 256;
|
||||
byte datagramBuffer[datagramBufferSize];
|
||||
|
||||
void setup()
|
||||
{
|
||||
// put your setup code here, to run once:
|
||||
// Setup the serial connection
|
||||
Serial.begin(4800);
|
||||
|
||||
Serial.println("Hello, world!");
|
||||
|
||||
// Make sure that WiFi is supported
|
||||
|
||||
Serial.println("Beginning connection sequence.");
|
||||
Serial.print("Attempting to connect to ");
|
||||
Serial.print(" - ");
|
||||
Serial.print(ssid);
|
||||
Serial.print(" - ");
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
|
@ -35,13 +44,13 @@ void setup()
|
|||
}
|
||||
|
||||
Serial.println("success!");
|
||||
|
||||
printWiFiInfoLocal();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
delay(1000);
|
||||
printWiFiInfoLocal();
|
||||
delay(1000);
|
||||
|
||||
}
|
||||
|
||||
void printWiFiInfoLocal()
|
||||
|
@ -49,3 +58,38 @@ void printWiFiInfoLocal()
|
|||
Serial.print("IP Address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
|
||||
void findServer()
|
||||
{
|
||||
Serial.print("Initialising PixelHub auto detection system - ");
|
||||
Udp.beginMulticast(WiFi.localIP(), beaconAddress, beaconPort);
|
||||
Serial.println("success!");
|
||||
|
||||
Serial.println("Listening for PixelHub beacon pings.");
|
||||
while(true) {
|
||||
int datagramSize = UdpClient.parsePacket();
|
||||
if(!datagramSize) continue;
|
||||
|
||||
Serial.print("Received datagram #");
|
||||
Serial.print(datagramSize);
|
||||
Serial.print(" bytes in size from ");
|
||||
Serial.print(Udp.remoteIP());
|
||||
Serial.print(":");
|
||||
Serial.print(Udp.remotePort());
|
||||
if(datagramSize > datagramBufferSize) {
|
||||
Serial.println(", but the message is larger than the datagram buffer size.");
|
||||
continue;
|
||||
}
|
||||
Serial.println(".");
|
||||
|
||||
Udp.read(datagramBuffer, datagramSize);
|
||||
|
||||
Serial.print("Content: ");
|
||||
for(int i = 0; i < datagramSize; i++) {
|
||||
Serial.print(datagramBuffer[i], HEX);
|
||||
Serial.print(" ");
|
||||
}
|
||||
Serial.print("\n");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue