There are various ways of doing ota update in mongoose os. The architecture of ota is given as follows.

OTA architecture overview
OTA implementation in Mongoose OS has 3 layers:
Layer 1. The lowest layer, implemented by the ota-common library. The API functions that do the work are updater_context_create() to start an update, a sequence of updater_process() to apply the next chunk of firmware, and updater_finish() to finish the update.

Layer 2. The RPC service that provides a remote management API for the low-level OTA API. It is implemented by the rpc-service-ota library. The RPC API are of two kinds: push and pull.

  • OTA.Update is a pull mechanism. Works only via HTTP. You pass a URL to the new .zip file as a parameter of the RPC call, the .zip file gets downloaded and low-level API calls apply it.
  • OTA.{Begin,Write,End} is a push mechanism. It works over any transport, for example, BLE, or MQTT. They are calling corresponding low-level API.

Layer 3. Helper libraries and tools that invoke the 2nd RPC layer,

  • mos ota command calls the “push” RPC, and can work over any transport by specifying the –port … parameter. That is the most universal method.
  • ota-http-client library is able to fetch firmware from a URL. This library is in fact used by the OTA.Update RPC implementation. Also, this library is able to periodically poll a given URL for the new version of firmware, and auto-update.
  • ota-http-server library registers and /update URI handler directly on a device. You can push the new firmware over the HTTP POST. This method is for the development purposes: curl -v -i -F http://IPADDR/update
  • ota-shadow library observes desired.ota.url shadow changes. If it gets a new URL, it triggers the OTA.Update with that URL. This method works for the offline devices – you can change the shadow of the number of devices, and they will get updated as soon as they come online.

In this Blog we will focus on Layer 3 ota-http-server for making ota updates.

For ota-http-server:
Step 1: Clone a project or open your project.

Step 2: Open mos.yml file in
Include the following library in mos.yml file under libs section:

[wifi.sta.ssid, "XXX"]
[wifi.sta.pass, "XXX"]
["wifi.ap.enable", false]
["wifi.sta.enable", true]

Note: Add your WiFi’s SSID in and Your WiFi’s password in

Step 3: Build and Flash the your mos firmware

  • mos build
  • mos flash

Step 4: Note the IP address of NodeMCU
Step 5: Do some changes in the init.js file and build the project again
Step 6:
Then, you can build a new firmware and push it using this command:
curl -v -F file=@build/ http://IP_ADDR/update

Note: You need to be inside the app folder in to use the above code.

If you are still facing issue regarding OTA update in mongoose os Feel free to Ask Doubts in the Comment Box Below and Don’t Forget to Follow us on 👍 Social Networks😉 Happy Splunking >