Android App UDP -> ESP8266 -> Arduino Mega. 1sec limitation?
Posted: Mon Apr 24, 2017 7:56 am
Hi every body,
My project needs to exchange data between Androd app and Arduino mega through wifi. I'm using esp8266 (esp01 board), to do it.
It's connected to arduino trhough serial 115200 baud.
Android request in udp, esp transfert the 'R' char to arduino. Once read, arduino send back data maximum 1100 byte.
1) I first used AT command, but if i request more than 1 frame per second, it begins to be lost.
2) So i decided to reflash my own firmware in ESP8266 with arduino IDE. Just a serial bridge with time out. ESP received the request from Android, transfert it to arduino mega, arduino mega answer quiet fast, and here is my issue. ESP seems to not send back via UDP if the request rate is again more than 1 time per second.
Is here something in the serial managament that avoid to read serial buffer more than once a second?
What could be the solution?
Flash my own firmware by modifing source code and interupt etc by using the SDK with eclipse etc ?
Thanks a lot cause my project is a bit stuck a the moment because of this refresh rate issue.
This is my code for ESP8266. Remember transfert from android to arduino works fine, but send back to the android on serial read is the bloker as if by default serial port is not read more than once a second.
My project needs to exchange data between Androd app and Arduino mega through wifi. I'm using esp8266 (esp01 board), to do it.
It's connected to arduino trhough serial 115200 baud.
Android request in udp, esp transfert the 'R' char to arduino. Once read, arduino send back data maximum 1100 byte.
1) I first used AT command, but if i request more than 1 frame per second, it begins to be lost.
2) So i decided to reflash my own firmware in ESP8266 with arduino IDE. Just a serial bridge with time out. ESP received the request from Android, transfert it to arduino mega, arduino mega answer quiet fast, and here is my issue. ESP seems to not send back via UDP if the request rate is again more than 1 time per second.
Is here something in the serial managament that avoid to read serial buffer more than once a second?
What could be the solution?
Flash my own firmware by modifing source code and interupt etc by using the SDK with eclipse etc ?
Thanks a lot cause my project is a bit stuck a the moment because of this refresh rate issue.
This is my code for ESP8266. Remember transfert from android to arduino works fine, but send back to the android on serial read is the bloker as if by default serial port is not read more than once a second.
Code: Select all
void loop() {
/********************************************************
Tablette -> Arduno Mega
********************************************************/
int packetSize = Udp.parsePacket();
if (packetSize)
{
//Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
//1 : on transmet la requete a l'arduino mega
int len = Udp.read(incomingPacket, 255);
if (len > 0)
{
incomingPacket[len] = 0;
}
Serial.printf("%s\n", incomingPacket);
/********************************************************
Arduno Mega -> Tablette
********************************************************/
String data;
char a=-1;
unsigned long start = millis();
while ((millis() - start < 1000) ) {
while(Serial.available() > 0) { //tant qu'on recoit des donne on rempli data
a = Serial.read();
data += a;
//Serial.print(data);
if(a == '\r') {
//Serial.printf("CR recu\r\n");
break; //si eof, send data to Tablette
}
}
if(a == '\r'){ //si l'octet recu est zero, on arrette et on transmet a la tablette
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); // send back a reply, to the IP address and port we got the packet from
Udp.write(data.c_str());
Udp.endPacket();
break;
}
}//end timeout
if(a != '\r'){
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); // send back a reply, to the IP address and port we got the packet from
Udp.write("Arduino Timeout...\r");
Udp.endPacket();
}
}//end if requete udp recu
}//end loop