Post topics, source code that relate to the Arduino Platform

User avatar
By DJRed2000
#22373 I am working on a project that uses the ESP to read UDP packets and then send them to an Arduino Mega2560 over the serial port. The issue I'm having is with latency when writing the packet. Each packet is 638 bytes and I'm only trying to write 512 of those bytes out to the serial port. I've tried different baud rates from 57600, 115200 and 250000 and they all produce latency. If I only send around 100 bytes, there is no latency. Could the issue be with the serial buffer?

Here is the code on the ESP. I am using Arduino IDE 1.6.4 and the ESP plugin. I am using an FTDI to USB chip to upload.
Code: Select all#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

char ssid[] = "SSID"; 
char pass[] = "PASSWORD";       
#define E131_BUFFER_SIZE 638
#define PACKET_BEGIN 0x10
#define START_CODE 0
unsigned int localPort = 5568;     
unsigned char E131Buffer[E131_BUFFER_SIZE];
boolean NewPacket = false;

WiFiUDP udp;
 
void setup()
{
  Serial.begin(115200);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
  }
  udp.begin(localPort);
}

void loop()
{
  int packetSize = udp.parsePacket(); //parse packet 
  if(packetSize)
  {
    udp.read(E131Buffer,E131_BUFFER_SIZE); //read packet into buffer
    NewPacket = true;
  }
    if(E131Buffer[1] == PACKET_BEGIN && E131Buffer[125] == START_CODE && NewPacket == true) //quick check to see if packet is E1.31
   {
     for(int i = 126; i < E131_BUFFER_SIZE; i++)
     {
      Serial.write(E131Buffer[i]); //write channel values 1-512 bytes 126-637 in packet
     }
     NewPacket = false;
}
} //end loop