parseInt() on WiFiClient stream returns a 0 in Arduino Uno R4 #419
Open
Description
opened on Dec 24, 2024
parseInt() returns zero when called on the WiFiClient stream. Here's the simplest example. Paste this into a new ESP32 example on www.wokwi.com, or use an actual ESP32 board, or any non Renesas Arduino board.
#include <WiFi.h>
#define SECRET_SSID "Wokwi-GUEST" /// CHANGEME when using a real board
#define SECRET_PASS "" /// CHANGEME when using a real board
WiFiClient client;
int t;
String s;
void setup() {
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect.
}
}
void loop() {
if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect to SSID: ");
Serial.println(SECRET_SSID);
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(SECRET_SSID, SECRET_PASS);
Serial.print(".");
delay(5000);
}
Serial.println("\nConnected.");
} else {
if (client.connect("httpbin.org", 80)) {
Serial.println("connected to server");
client.println("GET /ip HTTP/1.1");
client.println("Host: httpbin.org");
client.println("Connection: close");
client.println();
}
t = client.parseInt();
Serial.println(t,DEC);
delay(5000);
}
}
Now, paste the same thing in Arduino IDE that is programming a Arduino Uno R4 and see that it always returns 0.
Also refer to the Stream utility class' parseInt method documentation here: https://www.arduino.cc/reference/tr/language/functions/communication/stream/streamparseint/
It appears that the WifiClient here does not behave the way other communication streams on Arduino work.
Activity