Over-the-air-Programming

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.

1 Like

I’m not the best person but the overall picture is:

  1. :spark: cloud (gcc) will compile your code into a .bin file like how you use a normal gcc.

  2. The .bin file is then encrypted using your core key and a message is sent to your core to initiate OTA flashing

  3. Flashing occurs and all the data is stored in external flash (might be decrypted as it comes in)

  4. 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!

  5. The core now resets and runs the new user firmware

Also, the core is using COAP protocol.

Let’s hear what the :spark: team says :slight_smile:

@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…

  1. If my application code doesn’t have any handling built into it to accept such an “OTA initiation message,” how does :spark: cloud initiate the OTA flashing, and subsequently transfer the binary image (encrypted or otherwise).

  2. Where is the code that’s running on my :spark: core that handles the incoming binary image data :spark: cloud? How did it get there?

  3. How does the :spark: cloud reach my :spark: core through my NAT without me setting up port forwarding on my router or something? It seems more likely to me that the :spark: core has to be initiating the transfer and/or polling the :spark: 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 :smile:!

  1. 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

  1. You can take a look at the :spark: communication-lib repo and see how the stuff are implemented

  2. This I’m not sure but COAP port seems open on most router (I have 0 clue)

This is why the :spark: core packs a punch! All the difficult stuff have been done by the team and the cloud :slight_smile:

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

2 Likes

Hi @vicatcu,

Just throwing this out there :slight_smile: – 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

1 Like

@zach thanks much. Your answer is very helpful in demystifying the process a bit. @Dave thanks to you too for the suggestion. I’ll send a note by email once I’ve chewed on the concept a bit more! Keep up the good work guys!

1 Like