Hey, so I‘m currently trying to display a image fetched from an XML to an M5paper. The problem is, the xml is quiet big and I only need the part thats between filename:“-„ so I trying to get that but somehow the values returning to me are wrong. Hope someone can help!
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "wifi";
const char* password = "Password";
const String url = "xml file from https...";
void setup() {
Serial.begin(9600);
WiFi.begin(ssid, password);
Serial.println("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println(".");
}
Serial.println("OK! IP=");
Serial.println(WiFi.localIP());
Serial.println("Fetching " + url + "... ");
HTTPClient http;
http.begin(url);
int httpResponseCode = http.GET();
String payload = "";
if (httpResponseCode > 0) {
Serial.print("HTTP ");
Serial.println(httpResponseCode);
payload = http.getString();
int firstElement = payload.indexOf('Filename="');
Serial.println(firstElement);
int lastElement = payload.indexOf('"');
Serial.println(lastElement);
String s = payload.substring(firstElement, lastElement);
Serial.println(s);
}
else {
Serial.println("Error code: ");
Serial.println(httpResponseCode);
Serial.println(":-(");
}
}
void loop() {
}