Am I missing something obvious ?
Danny
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <mywifi.h>
void printWifiStatus();
int status = WL_IDLE_STATUS;
int keyIndex = 0; // your network key Index number (needed only for WEP)
unsigned int port = 1900; // local port to listen on
WiFiUDP Udp;
IPAddress multi(239, 255, 255, 250);
IPAddress uni(192, 168, 1, 102);
void loop1(), loop2();
void loop() {
loop2();
Serial.print(".");
delay(2000);
}
void loop1() {
Udp.beginPacket(uni, port);
Udp.write("this is a unicast packet");
Udp.endPacket();
}
void loop2() {
IPAddress local = WiFi.localIP();
Udp.beginPacketMulticast(multi, port, local);
Udp.write("this is a multicast packet");
Udp.endPacket();
}
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Starting WiFi... ");
WiFi.mode(WIFI_STA);
int wifi_tries = 3;
while (wifi_tries-- >= 0) {
WiFi.begin(MY_SSID, MY_WIFI_PASSWORD);
status = WiFi.waitForConnectResult();
if (status == WL_CONNECTED)
break;
Serial.printf(" %d ", wifi_tries + 1);
}
Serial.println("Connected to wifi");
printWifiStatus();
Serial.println("\nStarting connection to server...");
Udp.begin(port);
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
}