Hey all! I was wondering if anyone can point me to a description of how the OTA programming functionality of the SparkCore actually works? I’m talking about the implementation details of how the hardware, bootloader, application software, and server software all interact to achieve OTA programming.
I’m not the best person but the overall picture is:
-
cloud (gcc) will compile your code into a .binfile like how you use a normal gcc. -
The
.binfile is then encrypted using your core key and a message is sent to your core to initiate OTA flashing -
Flashing occurs and all the data is stored in external flash (might be decrypted as it comes in)
-
Once that is completed, the core will do a check for the integrity of data and copy it into its own internal flash if all is good!
-
The core now resets and runs the new user firmware
Also, the core is using COAP protocol.
Let’s hear what the
team says 
@kennethlimcp you’re probably not too far off… the hand-wavy part where I get a bit confused is, the part where “and a message is sent to your core to initiate OTA flashing.” Allow me to elaborate…
-
If my application code doesn’t have any handling built into it to accept such an “OTA initiation message,” how does
cloud initiate the OTA flashing, and subsequently transfer the binary image (encrypted or otherwise). -
Where is the code that’s running on my
core that handles the incoming binary image data
cloud? How did it get there? -
How does the
cloud reach my
core through my NAT without me setting up port forwarding on my router or something? It seems more likely to me that the
core has to be initiating the transfer and/or polling the
cloud for it to work in the presence of NAT. Amiright?
Please forgive anything I’m saying that is explainable through me just being ignorant. I’m here to learn
!
- I believe the code lies in the bootloader and it’s already baked in the core.
What I also know is, the setup() and loop() is simply part of a bigger actual microcontroller code and there’s the part which communicates with the cloud
-
You can take a look at the
communication-lib repo and see how the stuff are implemented -
This I’m not sure but COAP port seems open on most router (I have 0 clue)
This is why the
core packs a punch! All the difficult stuff have been done by the team and the cloud 
Unlike an Arduino, your application code is not the only code that runs on the Spark Core. There is also a background process that handles incoming messages from the Cloud. This is the process that initiates the OTA flash.
If you download our firmware libraries (starting with core-firmware), you can dig into the nitty gritty, but essentially the software that communicates with the Cloud is compiled in with your application code.
The Core opens a connection with the Cloud, and holds that connection open. This provides a two-way socket between the Core and the Cloud; if the connection is broken, the Core re-establishes it.
Hope that helps!
Z
Hi @vicatcu,
Just throwing this out there
– If you’re interested in licensing / using the core-firmware / spark-protocol / OTA stuff for your commercial dev boards please feel free to send us an email at hello@spark.io – (I always thought it’d be cool to see other devices talking the spark-protocol )
Thanks,
David