Skip to content

parseInt() on WiFiClient stream returns a 0 in Arduino Uno R4 #419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
v-c opened this issue Dec 24, 2024 · 0 comments · Fixed by #423
Closed

parseInt() on WiFiClient stream returns a 0 in Arduino Uno R4 #419

v-c opened this issue Dec 24, 2024 · 0 comments · Fixed by #423
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@v-c
Copy link

v-c commented 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.

@v-c v-c changed the title parseInt() on WiFi client stream returns a 0 parseInt() on WiFiClient stream returns a 0 Dec 24, 2024
@v-c v-c changed the title parseInt() on WiFiClient stream returns a 0 parseInt() on WiFiClient stream returns a 0 in Arduino Uno R4 Dec 24, 2024
@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Dec 24, 2024
facchinm added a commit to facchinm/ArduinoCore-renesas that referenced this issue Jan 7, 2025
pennam pushed a commit to facchinm/ArduinoCore-renesas that referenced this issue Feb 10, 2025
@per1234 per1234 added the conclusion: resolved Issue was resolved label Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants