Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By danbicks
#33369 Hi Guys,

I am sure @martinayotte will know the answer to this one. Does anyone have any routines to upload and download to a server a JSON formatted file and locate in SPIFFS?

The idea is to have a config file on a server for my home system, each node will once connected to the internet pull down this file, store in to SPIFFS Json formatted and set its configuration based on file params.

Vice versa, there will be times when I also want the nodes to upload there current config to a server on the net.

Any examples of how I might go about this.

Cheers Dans
User avatar
By martinayotte
#33370
danbicks wrote:I am sure @martinayotte will know the answer to this one.

Unfortunately, I don't have all answers. I'm learning things on daily basis too ... :)
From a quick googling, here is an Arduino library that seems to be already ESP compatible :
https://github.com/bblanchon/ArduinoJson
User avatar
By Mario Mikočević
#33382 Heya,

yes, thats very nice JSON library, it even works :)

I'll bite ->

Code: Select all// {"esp":"ESP_ROOM_214","config":{"ssid":"foo","pwd":"bar","ch":1},"esp":"ESP_NEXT_ROOM",...}
DynamicJsonBuffer jsonBuffer;
SPIFFS.begin();
fp = SPIFFS.open("/config.txt", "r");
String line = fp.readStringUntil('\n');
JsonObject& DataFile = jsonBuffer.parseObject( line );
for( JsonObject::iterator it = DataFile.begin(); it != DataFile.end(); ++it ) {
  JsonObject& tmpObj = *it;
  if( tmpObj["esp"] == "ESP_ROOM_214" ) { // or whatever distiction of ESPs
    JsonObject& tmpCfg = tmpObj["config"];
    ssid = tmpCfg["ssid"];
// .. and so on
  }
}


point noting is that I do presume that config for all ESPs is stored on SPIFFS beforehand.

--
Mozz