Could a Serial Read Buffer on my ESP8266 be overblown ?

Hi to the world :smiley:

could someone please help me out on my question ?

If my main ESP8266 receives constantly a Serial.print from a second ESP8266, and if my main ESP do not use the

while (Serial.available() > 0){}

could the buffer than be overblown ? And than with an overblown buffer the RAM works very sloly ?

Or does is the receiving ESP8266 just ignoring the incoming Serials ?

And what about the Serial Output ? Could it be overblown too ?

Thanks mates

@UKHeliBob @Paul_B

Okay, and where is the buffer located ? In the RAM ? Or is there a particular place only for the SerialBuffer in ESP8266 ?

I am asking this, because I fear that the other ram is filled up quickly when the buffer is on the "normal" ram located.

Yup. Has to be RAM, it's being written to.
You need to tell us more about your application. While it's true your buffer won't overrun other memory, it's entirely possible you're getting corrupted messages due to full buffer issues; it's also possible your source device has a full output buffer, which will slow it down tremendously, but which may look like a problem with your receiving device.

2 Likes

It's a simple Communication between two ESPs. I just wanted to understand how the buffer works. Because it could be importand to understand the serial buffer for future projects.

Okay. So a full output-buffer from source, would slow down the receiving ESP ram, right ?

Okay, this would be no problem, because the sending data are only small words (no huge text)

Okay. I'll throw in some speculation, as you're not sharing.

  1. Source is transmitting at 9600, but sending more than 1000 chars/second. Source quickly fills it's transmit buffer, then slows to a crawl while the outgoing characters go; when each character is transmitted, there's room for one more in the buffer, so it crawls. This is why Serial transmit can be considered to be a 'blocking' code, in some circumstances but not others.
  2. Source is transmitting at a high baud rate, and sending a lot of data, but the transmit buffer is keeping up. The code in the receiving device is unable to keep up(emptying the buffer and processing the data), so the receive buffer fills. Once it's full, what is the receiving code going to do? No, it doesn't go rogue and write to other memory. Instead, it overwrites the stalest data in it's buffer. This is guaranteed to mangle incoming messages.
  3. Some glorious combination of both of the above, which will result in confusion when you fix one side, but not the other.
    Since we know exactly zero about the details of sender and receiver, all of the above may be totally irrelevant. Or not.
2 Likes

The whole discussion is a pointless waste of time until @tolga121 posts the actual code as there's a 100% chance that's where the problem lies.

1 Like

absolute understandable, thanks. This is exactly what I wanted to hear :smiley: So I will use other methods for the Serial (see below in this post)

Yes, this is exactly what I wanted to hear... thanks mates :smiley:

I have no actual code. I just wanna learn how to handle with the ESP (and other electronics)

But I will post a code, how I would handle a Communications between two ESPs... so wait a little..

Yep. That's what I parsed from your earlier comment. If you had said that upfront, we could have focused on the theory. As it was, it sounded like the typical question posted here, where we have to slowly extract the real context in order to determine where something's gone awry.
Anyway, glad you've got what you wanted. I look forward to your proposed handling description.

1 Like

Okay guys, as a positive example of code how to spare the RAM.

Do you guys agree ?

this is the sender code

// ESP number 1

#include <ESP8266WiFi.h>

int DataAlreadSent=0;

void setup() {
  Serial.begin(115200);
}

void loop() {
  
  if (DataAlreadSent == 0)
  { 
    Serial.print("Hello");
    DataAlreadSent=1; // so this indicates, that the data is already sent
  }

}

and this the receivers code

// ESP number 2

#include <ESP8266WiFi.h>

int DataAlreadyReceived=0;

String mystring, combined;

void setup() {
  Serial.begin(115200);
}

void loop() {
  
  while (Serial.available() > 0)
  { 
    char receivedChar = Serial.read();
    String mystring(receivedChar);
    combined = combined + mystring;

    if(combined == "Hello" && DataAlreadyReceived == 0)
    {
      Serial.print("HiThere");
      DataAlreadyReceived=1; // so this indicates, that the data is already received
    }
  }

}

As far as it goes, that might work. Certainly, UIMSO, there's nothing egregious. However, it ignores the context of a continuously looping, repetitive process. Is that relevant? In your application, will there be a single message, sent once, received once? If more than that is involved, then there's more work to be done.

1 Like

No, just a single message. The reason for this messaging, is:

each other should know, that they are there. So it's only one message being sent.

First, I wanted to send constantly a "Hello". (chosing the easy way of coding)

But now, I would never send constantly a Serial.print. And now I understand at least a little, how the Serial effect the ram itself... I know that there is still a lot to learn :smiley:

Thanks to all of you @camsysca @Delta_G

One think I wanted to say:

To be honest: I should know that large serial.print data have an effect on RAM. I sometimes forget to close the Serial Monitor on my Computer while the ESP is sending Serial.prints. And guess what ? My Computer is allways freezing because of the huge data printed on the serial monitor. So it absolutely effects the perfomance on any computer :smiley:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.