0

With my ESP32 Board, Wemos Lolin32, I would like to make a http GET request to "http://www.arduino.cc/asciilogo.txt", read the text file and print the text file to the serial monitor.

The question is: Why isn't basically the txt file written to the serial monitor? How can it be achieved? Do I need some kind of conversion of the char?

I am using similar code to that from this example https://www.arduino.cc/en/Tutorial/HttpClient. Basically the code can be reduced to this minimal example:

#include <WiFi.h>
#include <HttpClient.h>

void setup() {

  Serial.begin(9600);

  WiFi.begin(ssid, password);
  Serial.println("Connecting to WiFi..");
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println(".");
  }
  Serial.println("Connected to the WiFi network");

  pinMode(LED_BUILTIN, OUTPUT);
  Serial.println("SETUP FINISHED");
}

void loop() {
  Serial.println("Connecting to httpClient");


 HttpClient httpClient;
  httpClient.get("http://arduino.cc/asciilogo.txt");
  while (httpClient.available()) {
    char c = httpClient.read();
    //Serial.print(c);
    Serial.write(c);
  }
}

The expected result is: I would like to see the characters from the txt file (https://www.arduino.cc/asciilogo.txt) in the serial monitor.

The actual result is: The connection to the WiFi can be established. In the serial monitor either question marks or strange symbols are displayed.

I have checked the baud and it is the same in the code and in the monitor. I tried to change this value, but it did not help. Serial monitor

1

it is http://arduino.cc/asciilogo.txt. without www. www is redirected to https. you can verify it from a browser

  • I have edited the URL, the result is the same. – Mckunz Jan 25 at 19:11
  • Serial.write(c); if you read raw byte, then write raw byte. print converts number to text – Juraj Jan 25 at 19:13
  • The server also gzip encodes the content. He needs to add a Accept-Encoding: identity header. – gre_gor Jan 25 at 19:46
  • Unfortunately it does not work. – Mckunz Feb 1 at 19:35
  • Yes, I did change it to Serial.write(c); – Mckunz Feb 1 at 21:45
0

When switching from HttpClient to HTTPClient and using String payload = http.getString(); Serial.println(payload); I can achieve the expected result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.