Been going through the documentation and I’m not finding what I’m looking for, probably because I’m not thinking in the correct Particle terms.
What I want my firmware to do on startup is read a json file, basically the instructions of what it needs to do will be embedded in the json.
Questions:
can such a piece of json be stored in the Particle Cloud?
I can subscribe to the “cloud_connected” event but I’m not finding an obvious function/method to read from the Particle Cloud from the device. Sounds like I need a webhook? Am I on the right path with that?
Ideally I’d want to use some persistent storage on the device for those instructions, looking at eprom and backup RAM for this. Are those the available options?
The Particle Cloud does not store any data - it is a secure transport layer.
IMHO your device could do one of the following to receive its JSON data package once cloud connected:
Publish an event to the Cloud and have a web service subscribing to the device event stream, the web service could call a Cloud Function on the device and would know that it had been received (return code).
Subscribe to an event stream from your web service. The web service could scan regularly for devices online and publish an event with the JSON when it has seen the device online.
A combination device subscribing to the web service and the web service subscribing to the device stream with the device initiating the exchange by publishing an event “waiting for JSON data” and the web service replying with event “JSON data”. The advantage of using the events is the data load size - 622 bytes with the latest Device OS. The function data call is limited to 63 bytes.
Summary - if you want some data load served to a device when it demands it then you need somewhere to store that data (database) and a capability to respond to a request to send it. The Rules Engine will be able to do that for you. I have used the Particle APIs and not webhooks so I can’t comment on their use.
Regarding persistent storage - it depends how you are going to use it (speed of access, frequency of update). As you identified there are 2 on board solutions: EEPROM (slower and has a use limit) or retained RAM (needs a coin cell battery connected to VBAT on Photon, Electron is different). If these are not enough for your needs then you could try SD card (cheap and lots of storage but slower) or SPI Flash (expensive but quick).
Some minor addendum’s to @armor’s excellent answer:
The EEPROM is emulated in the STM32 flash and includes wear-leveling which makes it possible to write ove a million times without wearing out the underlying flash.
On a Photon, you can wire VBAT to 3V3 so that as long as power is applied, you won’t need a coin cell. This is handy when you put the Photon in deep sleep but want to keep data in retained variables. The Electron has a zero ohm resistor between 3V3 and VBAT which can be removed if a coin cell is preferred.
Besides SPI flash and an SD card you can also use I2C or SPI FRAM which is expensive but fast and non-volatile.