esp8266 / Arduino

ESP8266 core for Arduino
GNU Lesser General Public License v2.1
16.07k stars 13.33k forks source link

Serial.available() have a issue, its not able to return availiable bytes #9195

Closed The3ven closed 2 months ago

The3ven commented 2 months ago

Basic Infos

Platform

Settings in IDE

Problem Description

Nodemcu Serial.available(); function is not able to send total bytes available on serial it just send 1.

MCVE Sketch


#include "Arduino.h"

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

String tmp = "";

void loop()
{
    while (Serial.available() > 0)
    {
        Serial.println("data in buffer : ");
        Serial.print(Serial.available());
        Serial.println("\n");
        tmp = Serial.readString();
    }

    if (tmp.length() > 4)
    {
        Serial.println("Data : " + tmp);
        Serial.println("Data length : " + String(tmp.length()));
        Serial.flush();
        tmp = "";
    }
}

Debug Messages

⸮R⸮⸮⸮⸮data in buffer : 
1

Data : hi hi hi

Data length : 10
⸮R⸮⸮⸮⸮R⸮⸮fgFj⸮data in buffer : 
1

Data : hihihih

Data length : 9
mcspr commented 2 months ago

function is not able to send total bytes available on serial it just send 1.

does exactly what you have asked, though? tmp = readString() replaces the whole string, perhaps you meant +=