HardwareSerial/Esp8266 Timeout?

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

HardwareSerial/Esp8266 Timeout?

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


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:


Code: Select all



+CWLAP:(5,"UPC Wi-Free",-62,"82:c6:ab:1a:b5:bb",1,-12,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,"Cassiopeia 2.4GHz",-87,"bc:05:43:41:9f:d1",11,32767,0)
+CWLAP:(5,"UPC Wi-Free",-83,"56:67:11:9e:16:46",11,8,0)


CWLAP:(5,"UPC Wi-Free",-60,"82:c6:ab:1a:b5:bb",1,-19,0)
+CWLAP:(0,"HP-Print-4B-Photosmart 5520",-82,"c4:34:6b:e4:2d:4b",6,5,0)
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() {

  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) {
    if (incomingByte == 10) { 

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

  // Esp8266_1 receive
  if (Esp8266_1.available() > 0) {
    while (Esp8266_1.available() > 0) {
      c = Esp8266_1.read();

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

    while (Esp8266_2.available() > 0) {
      c = Esp8266_2.read();

Thank you!

Return to “ESP32 Arduino”

Who is online

Users browsing this forum: No registered users and 3 guests