I have a pretty weird UDP issue.
My setup is as follows :
- ESP8266 as SoftAP and UDP client
- ESP8266 sending an UDP broadcast packet every 2s.
- Android application connected as Wi-Fi Station and acting as an UDP Server
I'm able to sniff all the UDP packets in the air using another PC running wireshark and clearly see them on a regular 2s frequency.
On my Android app, I only receive packets once in a while in a kind of weird random fashion (I know UDP is not guaranteed - but doing tests in 'clean' air). I know my android application works as I have tested it with some other UDP clients.
I also have an older setup running the same Arduino software but using a Wi-Fi router and an W5100 ethernet controller (just changing from WiFiUdp to EthernetUDP). I don't have the issue with that setup.
I'm running out of ideas of what can be the root cause of this....
Below my code snippet, if anyone would see something wrong :
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
const char* ssid = "PyRC Timing";
WiFiUDP udp;
IPAddress broadcastAddress(255,255,255, 255);
unsigned char udpBuffer[10];
long cnt = 0;
void setup() {
pinMode(16, OUTPUT);
Serial.begin(921000);
while (!Serial);
// Connect to WiFi network
Serial.println();
Serial.println("Setting up SoftAP");
Serial.setDebugOutput(false);
WiFi.mode(WIFI_AP);
WiFi.softAP(ssid);
IPAddress softAPIP = WiFi.softAPIP();
Serial.print("IP address: ");
Serial.println(softAPIP);
Serial.println();
Serial.println("Server started");
udp.begin(4445);
}
void loop() {
digitalWrite(16, HIGH);
delay(1000);
int volt = 500;
long timeStamp = millis();
udpBuffer[0] = (byte) (volt & 0xFF);
udpBuffer[1] = (byte)((volt >> 8) & 0xFF);
udpBuffer[2] = '-';
udpBuffer[6] = (byte) (timeStamp & 0xFF);
udpBuffer[5] = (byte)((timeStamp >> 8) & 0xFF);
udpBuffer[4] = (byte)((timeStamp >> 16) & 0xFF);
udpBuffer[3] = (byte)((timeStamp >> 24) & 0xFF);
udpBuffer[7] = ';';
udp.beginPacket(broadcastAddress, 4445);
udp.write(udpBuffer, 8);
udp.endPacket();
Serial.print("Sent packet : ");
Serial.println(cnt++);
digitalWrite(16, LOW);
delay(1000);
}