I have a config.json file stored in the Flash SPIFFS memory of my ESP8266-based web server.
My intent is to read this file into a char
array (char string[]
), avoiding the use of Arduino's String
, and send it to the client after an Ajax call.
The config.json is something like this : {"start1h":11,"start1m":20,"stop1h":15,"stop1m":40}
I've tried with the following code, but the problem is that the client receives a string with an '@'
character at the end and fails to parse the string via javascript
#define CONFIGFILE "/config.json"
File configFile = SPIFFS.open(CONFIGFILE, "r");
size_t filesize = configFile.size(); //the size of the file in bytes
char string[filesize + 1]; // + 1 for '\0' char at the end
configFile.read((uint8_t *)string, sizeof(string));
configFile.close();
string[filesize + 1] = '\0';
Serial.print(string);
server.send(200, "text/plane", string);
Serial output: {"start1h":11,"start1m":20,"stop1h":15,"stop1m":40}@
Client receives ajax response :{"start1h":11,"start1m":20,"stop1h":15,"stop1m":40}@
'@'
at the end of string!
What's wrong with my code? Thanks in advance