I have a project I'm working on where I want to download some binary files from my server and cache them to an SD card or local SPI flash.
The server is Ubuntu 20.04 running Laravel and PostgreSQL.
The devices that need the new binary files are Electrons and Borons.
The options as far as I can see are:
Embed files within device firmware releases
Embed binary files within the Particle device firmware that is flashed to the Electron or Boron via cellular network.
Pros:
- Easiest
- Doesn’t use Particle Events
- Whole OTA update mechanism is pre-built and “just works”
Cons:
- Takes up device flash memory
- Requires device OTA cellular firmware update to update local files (interrupts device functionality temporarily)
- Requires multiple device firmware releases in order to transfer/cache large amounts of data
Particle Cloud API Device Function Calls
Pros:
- Easy
- Secure
- Uses least cellular data?
Cons:
- Consumes particle events
- approximately 50 per 32kB binary file
- this would equate to 150 extra particle events per month per device in my case (2% of monthly total allowance)
TCP Client
Pros:
- Fast (compared to TCP)
- Doesn’t use Particle Events
Cons:
- Uses more cellular data
- Unsecure (will it even work with our sever then?)
UDP Client
Pros:
- Fast (compared to TCP)
- Doesn’t use Particle Events
Cons:
- Uses more cellular data
- Unsecure (will it even work with our sever then?)
TLS TCP Client - Particle Library
Pros:
- Doesn’t use Particle Events
Cons:
- Uses even more cellular data (additional encryption overhead several kB)
- Uses a community library… not verified
Actually, in writing this, the choice seems clear:
I should use Particle Function calls and Particle Webhooks to sync with server:
- Electron sends webhook containing the status/crc/version etc metadata for the files that it currently has stored locally (webhook gets forwarded via Particle webhook integration to my server)
- Server checks local binary file metadata against its latest available versions that it has stored in its database
- If difference exists, server begins sending chunks of the file to the device via Particle Cloud API Functions
- my app caches the data in RAM, and returns the total file bytes written so far
- a few ms later in my app asynchronously cache the chunk to local non-volatile memory
- server continues to pepper the app with particle function calls until it has transferred all of the files
- server can check on the status of the transfer at any time by reading a Particle Variable that I maintain which contains the same JSON string that I publish in the original webhook that was sent (e.g. file statuses, crcs, bytes written, etc etc)
I love the brainstorming forum?
Would love to hear anyone's thoughts on this.