HardwareSerial/Esp8266 Timeout?

sserena
Posts: 1
Joined: Sat Dec 30, 2017 7:34 pm

HardwareSerial/Esp8266 Timeout?

Postby sserena » Sat Dec 30, 2017 7:51 pm

Hi!

I connected two Esp8266 to one Esp32 because my project requires me to fetch as much information about the available access points in as little time as possible (AT+CWLAP) and continuously upload this information to a server. So... the two 8266s are fetching info while the esp32 is uploading it via websocket. The connection to the 8266s is done by means of the HardwareSerial library.

I wrote a little script to test things that allows me to send commands to both 8266s at the same time. I found that everything works well if not much information is returned by either device (so, for instance, just information of one access point). However, if I query the entire network, generally what happens is that one device returns all data and one just a part of it. I noticed a similar effect if I add a delay to the loop-function. It is as though the available() methods just timed out at some point. I'll post both, and example return as well as my code:

Return:

Code: Select all

Esp8266_1
---------
+CWLAP:(3,"UPC247434185",-53,"14:49:e0:88:58:68",1,-17,0)
+CWLAP:(3,

Esp8266_2
---------
+CWLAP:(3,"UPC247434185",-42,"14:49:e0:88:58:68",1,-26,0)
+CWLAP:(4,"UPC0040120",-70,"80:c6:ab:1a:b5:b9",1,-19,0)
+

Esp8266_1
---------
"Netgear_WG_2G_EXT",-84,"10:0d:7f:4b:09:5e",1,5,0)
+CWLAP:(4,"UPC0040120",-63,"80:c6:ab:1a:b5:b9",1,-12,0)
+CWLAP:(5,"UPC Wi-Free",-62,"82:c6:ab:1a:b5:bb",1,-12,0)
+CWLAP:(3,"UPC241099055",-87,"14:49:e0:c7:34:a8",1,-37,0)
+CWLAP:(5,"UPC Wi-Free",-94,"56:fa:3e:24:ba:59",1,-9,0)
+CWLAP:(0,"HP-Print-4B-Photosmart 5520",-80,"c4:34:6b:e4:2d:4b",6,13,0)
+CWLAP:(4,"cut-52331",-78,"00:24:c9:48:bc:20",6,3,0)
+CWLAP:(3,"UPC242803555",-89,"dc:71:44:fa:10:08",8,-21,0)
+CWLAP:(3,"HZN247827709",-89,"54:fa:3e:24:ba:59",1,-9,0)
+CWLAP:(4,"ksi-46310",-86,"a4:52:6f:a8:2f:c1",1,31,0)
+CWLAP:(3,"devolo-3a5",-78,"f4:06:8d:23:c3:a5",11,6,0)
+CWLAP:(4,"Cassiopeia 2.4GHz",-87,"bc:05:43:41:9f:d1",11,32767,0)
+CWLAP:(3,"devolo-guest-3a5",-79,"f6:06:8d:23:c3:a5",11,8,0)
+CWLAP:(4,"UPC6894357",-84,"54:67:51:9e:16:46",11,8,0)
+CWLAP:(5,"UPC Wi-Free",-83,"56:67:11:9e:16:46",11,8,0)
+CWLAP:(3,"Coiffure_2G",-94,"e6:f4:c6:14:2d:72",12,25,0)
+CWLAP:(3,"devolo-000B3BED75E4",-86,"00:0b:3b:ed:75:e4",13,0,0)

OK

Esp8266_2
---------
CWLAP:(5,"UPC Wi-Free",-60,"82:c6:ab:1a:b5:bb",1,-19,0)
+CWLAP:(3,"UPC241099055",-93,"14:49:e0:c7:34:a8",1,-44,0)
+CWLAP:(0,"HP-Print-4B-Photosmart 5520",-82,"c4:34:6b:e4:2d:4b",6,5,0)
+CWLAP:(4,"cut-52331",-89,"00:24:c9:48:bc:20",6,-4,0)
+CWLAP:(3,"UP
So in this case, both devices didn't have enough in the buffer to complete the first time around. At the second pass, the first device finished and the other didn't. It all works if I just query one device. But with both of them, the first one always finishes (no matter which of the two is actually first) whereas the second one doesn't. Furthermore, the character count of the final block of the slower device is surprisingly consistent (248 characters, generally).

I'm guessing there's some sort of a timeout, but it all looks too consistent to me... frankly, I don't know and am hoping someone else would.

Here's my (testing-) code:

Code: Select all

#include <HardwareSerial.h>

HardwareSerial Esp8266_1(1);
HardwareSerial Esp8266_2(2);

String serialResponse = "";
byte incomingByte;
char c;

void setup() {

  Serial.begin(115200);
  Esp8266_1.begin(115200, SERIAL_8N1, 25, 26, false);
  Esp8266_2.begin(115200, SERIAL_8N1, 4, 17, false);

}

void loop() {

  // Serial Receive
  while (Serial.available() > 0) {
    incomingByte = Serial.read();
    if (incomingByte == 13) {
      continue;
    }
    if (incomingByte == 10) { 
      Esp8266_1.println(serialResponse);
      Esp8266_2.println(serialResponse);

      serialResponse = "";
    }
    else {
      serialResponse += (char)incomingByte;
    }
  }

  // Esp8266_1 receive
  if (Esp8266_1.available() > 0) {
    
    Serial.println();
    Serial.println("Esp8266_1");
    Serial.println("---------");
  
    while (Esp8266_1.available() > 0) {
      c = Esp8266_1.read();
      Serial.print(c);
    }
  }

  // Esp8266_2 receive
  if (Esp8266_2.available() > 0) {

    Serial.println();
    Serial.println("Esp8266_2");
    Serial.println("---------");
  
    while (Esp8266_2.available() > 0) {
      c = Esp8266_2.read();
      Serial.print(c);
    }
  }

}
Thank you!

Who is online

Users browsing this forum: No registered users and 71 guests