So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By yonatan_irv
#59005 first of all i would like to thank everyone who is part of this community. i strated to use the esp8266 few days ago and the information you provide helped me a lot. thanks.

i'm using an arduino mega to send data from an imu to matlab via esp8266 wit UDP protocol.

in order to optimize the transfer rate , each uint16_t is divided into upper and lower hex (see udp_send_hex function).
my problem is that if i dont use delay between each byte that i send i'm getting bad data on the other side, which lowers my trasfer rate.

does anyone got any idea what is the reason for that? is there any better way to send the data? would you use other method to send the data?

thanks!



i'm using the follwing code on the arduino:

Code: Select alluint32_t last_t=0;
String str_to_send;
#define  dataLength 9
uint16_t returnData[dataLength] = {11000,12000,13000,14000,15000,16000,17000,18000,19000};

void setup() {

  Serial2.begin(115200   );//921600 78600
  Serial.begin(115200);
  Serial.println(" start testing 115200");
  delay(2);
  set_udp();
 

}

void loop() {

    udp_send_hex(returnData);
}

void set_udp()
{
  String str1;
  String str2;
  String str3;
  String str4;
  String str5;
  String str6;


  str1="AT+CWMODE=3";
  str2="AT+CWJAP=\"**SSID**\",\"**password**\"";
  str3="AT+CIFSR";
  str4="AT+CIPMUX=1";
  str5="AT+CIPSTART=4,\"UDP\",\"192.168.43.111\",8080,1112,0";

  Serial2.println();
 
  Serial2.println(str1);
  delay(3000);
  while(Serial2.available())Serial.write(Serial2.read());
  while(Serial.available())Serial2.write(Serial.read());
  Serial2.println(str2);
  while(Serial2.available())Serial.write(Serial2.read());
  while(Serial.available())Serial2.write(Serial.read());
  delay(3000);
 
  Serial2.println(str3);
 
  while(Serial2.available())Serial.write(Serial2.read());
  while(Serial.available())Serial2.write(Serial.read());
  delay(3000);
  Serial2.println(str4);
  while(Serial2.available())Serial.write(Serial2.read());
  while(Serial.available())Serial2.write(Serial.read());
  delay(2000);
  Serial2.println(str5);
 

  while(Serial2.available())Serial.write(Serial2.read());
  while(Serial.available())Serial2.write(Serial.read());
  delay(2000);

 
 


}

void udp_send_hex(uint16_t returnData[dataLength])
{
  String str_command;
  int hex,hexL,hexR;
  str_command="AT+CIPSEND=4,18";
  Serial2.println(str_command);

  Serial2.flush();

    for (int ii=0; ii<dataLength; ii++)
    {
    hex=(int)returnData[ii];
    hexL=highByte(hex);
   
    delayMicroseconds(200);
    Serial2.write(hexL);
    hexR=lowByte(hex);
    delayMicroseconds(80);
    Serial2.write(hexR);
   

   }
}

void udp_send(String str_to_send)
{
  int b;
  int ii=0;
  uint32_t send_t;
 
  String str_command;
  b=str_to_send.length();


  Serial2.flush();

  str_command="AT+CIPSEND=4,161";

 
  Serial2.println(str_command);
 
 
  delay(2);
  Serial2.flush();

  send_t=micros();
  Serial2.println(str_to_send);
  Serial.println(micros()-send_t);
  delay(2);
 
}