-->
Page 1 of 1

SPIFFS JSON FILES

PostPosted: Sat Nov 07, 2015 11:54 am
by danbicks
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

Re: SPIFFS JSON FILES

PostPosted: Sat Nov 07, 2015 12:02 pm
by martinayotte
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

Re: SPIFFS JSON FILES

PostPosted: Sat Nov 07, 2015 4:46 pm
by Mario Mikočević
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

Re: SPIFFS JSON FILES

PostPosted: Thu Nov 26, 2015 9:11 pm
by domonetic
if not too late
https://github.com/bblanchon/ArduinoJson/wiki/Encoding-JSON

run fine with esp8266-staging