Parse a part between 2 fields

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() {

} 

I moved your topic to a more appropriate forum category @bs-281.

The Nano ESP32 category you chose is only used for discussions directly related to the Arduino Nano ESP32 board.

In the future, please take the time to pick the forum category that best suits the subject of your question. There is an "About the _____ category" topic at the top of each category that explains its purpose.

Thanks in advance for your cooperation.

I can't test at this moment but does something like that compile? A quote needs to be escaped; you can try

int lastElement = payload.indexOf('\"');

output

Filename="my.file"
"my.file"

String str = "Filename=\"my.file\"";

void
setup (void)
{
    Serial.begin (9600);

    Serial.println (str);

    String fName = str.substring (str.indexOf ("\""));
    Serial.println (fName);
}

void
loop (void)
{
}

That was it thx! It actually did compile, just with an unwanted output. Just a quick question, is therer any easy way to resize an image, since everything I found yet is a complicated mess.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.