Using the new Arduino IDE for ESP8266 and found bugs, report them here

Moderator: igrr

User avatar
By PlanetaryGear
#19651 Good morning!

I am using an ESP-01 and just simply forwarding data from the serial port out to a connected socket. Since the socket.write methods do not packetize in the background and would send each character as separate packets causing 100ms or so delay between each character read it’s necessary to do a little buffering. I’m using the Serial.readBytes method. Creating a 64 byte buffer and reading until it’s full or until 65ms timeout like this:

Code: Select all            Serial.setTimeout( 65)
            while (Serial.available()){
            
               //read for 65ms or until 64 characters are reached.
               byte readBuffer[64];
               byte buffLen = Serial.readBytes( readBuffer, 64);   
               dataSocket.write( readBuffer, buffLen);
            
            }



The serial stream it’s reading is only 9600 baud so very slow and usually less than 64 bytes but I’ve tested with longer strings and it works great. The problem is that once in a while for no reason that I can see it chokes and sends some random junk characters. The program itself does not hang and the connections keep going and the next packet is entirely valid. I’m currently going through the program and doing some memory optimization but there should be plenty of memory at this point. I am in the process of testing that now to be sure. I am relatively new to low level C coding and directly managing things like arrays of bytes but that code just isn’t that complicated.

I dont believe that the serial input is a problem, I’ve had this same code running through an xBee radio interface for a year without any corrupt packets and I am trying to be able to use these wonderful new devices in the future.

Any suggestions or advice would be greatly appreciated thank you!
User avatar
By PlanetaryGear
#19765 nope, not due to restarting. I was actually watching the device when it sent this. The actual string should have been, and was 100’s of times before this, “command(LED)” what it sent was "comma˚°LED)” so it turned the three characters of “nd(“ into 2 characters of value hFB (251) and hA1 (161) and then happily kept going without restarting. For testing I am sending these commands back every 5 seconds and this is happening maybe 3 or 4 times a day.

The same hardware connected to an xBee radio for serial data did not show corruption, but it’s still possible I need extra decoupling caps or something like that. Otherwise the device runs very happily and well without restarts or other issues.