Using multicast (x.x.x.255) to send the data to all the tablets, create huge packet loss.
Samsung Tab A 7.0 SM-T280 (2016) > 30%
Samsung Galaxy S5 (2014) > 10%
Samsung Tab 10.1 P7500 (2010) > 4%
Switch to unicast (x.x.x.100) and that one device has very very min packet loss (< 0.5%), but ofcourse only 1 tablet gets updates. Anyone have any idea what to do?
#include <ESP8266WiFi.h>
#include <WiFiUDP.h>
#include <ESP8266WebServer.h>
#include <DNSServer.h>
/* Set these to your desired credentials. */
const char *ssid = "xxx";
const char *password = "xxx";
const unsigned int MAX_INPUT = 512; // how much serial data we expect before a newline
const byte DNS_PORT = 53; // Capture DNS requests on port 53
unsigned int localport = 8888; // local port to broadcast on
IPAddress apIP(10, 10, 10, 1); // Private network address: local & gateway
IPAddress broadcastIP(255, 255, 255, 255);
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; // (wifiudp.h 8192) buffer to hold incoming packet,
char serialBuffer[MAX_INPUT];
String responseHTML = ""
"<!DOCTYPE html><html><head><title>MyPlane_Portal</title></head><body>"
"<h1>MyPlane WiFi</h1><p>You are connected to your Plane's BCM</p></body></html>";
DNSServer dnsServer; // Create the DNS object
WiFiUDP UDP; // UDP protocol on STA interface, localPort
ESP8266WebServer webServer(80); // HTTP web server on common port 80
void setup()
{
Serial.begin(38400);
WiFi.mode(WIFI_AP); // AcessPoint
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); // IPAddress local_ip, IPAddress gateway, IPAddress subnet
WiFi.softAP(ssid, "", 6); //max connection 4 ESP8266WiFi.h
// replay to all requests with same HTML
webServer.onNotFound([]() {webServer.send(200, "text/html", responseHTML);});
webServer.begin();
// original unicast UDP
while (! UDP.begin(localport) ) { // UDP protocol connected to localPort which is a variable
yield(); // Play nicely with RTOS (alias = delay(0))
} // This will loop forever if UDP fails
}
void loop()
{
static unsigned int input_pos = 0;
dnsServer.processNextRequest();
webServer.handleClient();
//Passes data along
if (Serial.available() > 0) {
byte inByte = Serial.read();
if (inByte == '\n') { // end of text
serialBuffer[input_pos] = 0; // terminating null byte
// UDP.beginPacket(IPAddress(10,10,10,101), localport);
// UDP.beginPacketMulticast(IPAddress(10,10,10,101), localport, WiFi.localIP());
// UDP.beginPacket(IPAddress(10,10,10,255), localport);
UDP.beginPacketMulticast(IPAddress(10,10,10,255), localport, WiFi.localIP());
UDP.write(serialBuffer); // read one character
UDP.endPacket(); // clear UDP buffer
delay(10);
// reset buffer for next time
input_pos = 0;
}
else if (input_pos < (MAX_INPUT - 1)) {
serialBuffer[input_pos++] = inByte;
}
}
int packetSize = UDP.parsePacket(); // if there’s data available, read a packet
if (packetSize) {
int len = UDP.read(packetBuffer, MAX_INPUT); // read the packet into packetBufffer
if (len > 0) {
packetBuffer[len] = 0;
}
Serial.write(packetBuffer);
// send a reply, to the IP address and port that sent us the packet we received
UDP.beginPacket(UDP.remoteIP(), UDP.remotePort());
UDP.printf("OK%u", packetSize);
UDP.endPacket();
}
}