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
2 Answers 2
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– Mckunz2019年01月25日 19:11:02 +00:00Commented Jan 25, 2019 at 19:11
-
Serial.write(c);
if youread
raw byte, thenwrite
raw byte.print
converts number to text2019年01月25日 19:13:02 +00:00Commented Jan 25, 2019 at 19:13 -
The server also gzip encodes the content. He needs to add a
Accept-Encoding: identity
header.gre_gor– gre_gor2019年01月25日 19:46:37 +00:00Commented Jan 25, 2019 at 19:46 -
Unfortunately it does not work.Mckunz– Mckunz2019年02月01日 19:35:37 +00:00Commented Feb 1, 2019 at 19:35
-
Yes, I did change it to Serial.write(c);Mckunz– Mckunz2019年02月01日 21:45:32 +00:00Commented Feb 1, 2019 at 21:45
When switching from HttpClient to HTTPClient and using String payload = http.getString(); Serial.println(payload); I can achieve the expected result.