You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If however I use the following, I am able to deserialise successfully where String data is in the json, but I get no data where int data items are i.e. pollRate
File fileConfig = SPIFFS.open("/PM8Config.json", FILE_READ); // Check if we can open the Config file
if (!fileConfig) {
Serial.println("There was an error opening the Config file");
Serial2.print(F("pgInitConfig.t10.txt="Failed"));
//return false;
}else{
Serial.println("Config File was successfully opened");
Serial2.print(F("pgInitConfig.t10.txt="Opened"));
//return true;
size_t fileSize = fileConfig.size();
std::unique_ptr<char[]> buf(new char[fileSize]);
fileConfig.readBytes(buf.get(), fileSize);
StaticJsonDocument<1000> doc;
DeserializationError error = deserializeJson(doc, buf.get());
// Test if parsing succeeds.
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.c_str());
//return;
}
int testJsonRead = doc["sensorData"]["pollRate"];
Serial.print("Test JSON Read variable (should read '30': " );
Serial.println(testJsonRead);
const char* testPW = doc["password"];
Serial.print("Test JSON Read variable (should show PW: " );
Serial.println(testPW); `
The json file in SPIFFS is (and I can Serial.print this without an issue):
I'm struggling to get a Json file in ESP32 SPIFFS to deserialize unless I create a buffer and read that. In the SD example it shows
and then calls
If I open my file using
and then deserialize using
I get a failure indicating "IncompleteInput"
If however I use the following, I am able to deserialise successfully where String data is in the json, but I get no data where int data items are i.e. pollRate
The json file in SPIFFS is (and I can Serial.print this without an issue):
I'm clearly missing something here but can't figure out why I can't simply call the fileConfig object without having to use buf.get()?
Any help would be appreciated and I think it's time to buy the book :-)
The text was updated successfully, but these errors were encountered: