Reading UDP Packets
Posted: Wed Jul 13, 2016 5:12 pm
I've written code to read UDP packets and then output them to an Arduino Due over serial. The packets are E1.31 (DMX over ethernet) data and each packet is 638 bytes. I can send 3 universes no problem but any more than 3 and the ESP begins to get backed up and the packets are no longer read in real time. If I stop transmitting data, the ESP continues to output that it is still reading data. I am using an ESP-01 chip. Is there anything I can do to improve the throughput?
Here is my simple test code:
Here is my simple test code:
Code: Select all
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
char ssid[] = "******";
char pass[] = "*****";
IPAddress local_ip(192, 168, 1, 15);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
#define E131_BUFFER_SIZE 638
unsigned int localPort = 5568;
unsigned char E131Buffer[E131_BUFFER_SIZE];
WiFiUDP udp;
void setup()
{
Serial.begin(250000);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass); //Connect to Network
WiFi.config(local_ip, gateway, subnet);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
}
udp.begin(localPort);
}
void loop()
{
int packetSize = udp.parsePacket();
if (packetSize)
{
Serial.println(packetSize);
udp.read(E131Buffer, E131_BUFFER_SIZE);
udp.flush();
Serial.println(E131Buffer[114]); //Byte 114 in the packet is the universe number
}
}