Skip to main content
Arduino

Return to Question

added 87 characters in body
Source Link
Daniele
  • 103
  • 2

I'm trying to parse with tinyxml2 a modest XML (3.4kb) to retrieve some data.

My ESP8266 crashes every time I try to use the toCharArray method.

here's my code

// here I'm getting an http request
String payload = https.getString();
// checking the payload, it seems fine in console but I get some garbage characters when àèéùìò are printed
Serial.println(payload);
// Length (with one extra character for the null terminator)
int str_len = payload.length() + 1;
// Prepare the character array
char xml[str_len];
// Copy it over
payload.toCharArray(xml, str_len);
// there I'll parse xml with tinyxml2 but the MCU crashes before getting here

the length of the string is something around 3900, which I'm not sure can fit this kind of array on this device. If it's the case, what will be a better strategy ?

As you can imagine I'm just starting with the c language :)

EDIT: https.getString().c_str() + less variables was the right way to save memory

I'm trying to parse with tinyxml2 a modest XML (3.4kb) to retrieve some data.

My ESP8266 crashes every time I try to use the toCharArray method.

here's my code

// here I'm getting an http request
String payload = https.getString();
// checking the payload, it seems fine in console but I get some garbage characters when àèéùìò are printed
Serial.println(payload);
// Length (with one extra character for the null terminator)
int str_len = payload.length() + 1;
// Prepare the character array
char xml[str_len];
// Copy it over
payload.toCharArray(xml, str_len);
// there I'll parse xml with tinyxml2 but the MCU crashes before getting here

the length of the string is something around 3900, which I'm not sure can fit this kind of array on this device. If it's the case, what will be a better strategy ?

As you can imagine I'm just starting with the c language :)

I'm trying to parse with tinyxml2 a modest XML (3.4kb) to retrieve some data.

My ESP8266 crashes every time I try to use the toCharArray method.

here's my code

// here I'm getting an http request
String payload = https.getString();
// checking the payload, it seems fine in console but I get some garbage characters when àèéùìò are printed
Serial.println(payload);
// Length (with one extra character for the null terminator)
int str_len = payload.length() + 1;
// Prepare the character array
char xml[str_len];
// Copy it over
payload.toCharArray(xml, str_len);
// there I'll parse xml with tinyxml2 but the MCU crashes before getting here

the length of the string is something around 3900, which I'm not sure can fit this kind of array on this device. If it's the case, what will be a better strategy ?

As you can imagine I'm just starting with the c language :)

EDIT: https.getString().c_str() + less variables was the right way to save memory

Source Link
Daniele
  • 103
  • 2

ESP8266 crashes when trying to copy a string into a big char

I'm trying to parse with tinyxml2 a modest XML (3.4kb) to retrieve some data.

My ESP8266 crashes every time I try to use the toCharArray method.

here's my code

// here I'm getting an http request
String payload = https.getString();
// checking the payload, it seems fine in console but I get some garbage characters when àèéùìò are printed
Serial.println(payload);
// Length (with one extra character for the null terminator)
int str_len = payload.length() + 1;
// Prepare the character array
char xml[str_len];
// Copy it over
payload.toCharArray(xml, str_len);
// there I'll parse xml with tinyxml2 but the MCU crashes before getting here

the length of the string is something around 3900, which I'm not sure can fit this kind of array on this device. If it's the case, what will be a better strategy ?

As you can imagine I'm just starting with the c language :)

AltStyle によって変換されたページ (->オリジナル) /