--- title: OTA updates tags: TB Developer Guide image: --- # OTA updates [toc] ## procedures ### Provision OTA package to platform repository ``Advanced features > OTA updates > +`` ![image](https://hackmd.io/_uploads/r1P3P0Dwp.png) * Title: * Version: * Version tag: * Device profile: * Package type: **Firmware** | Software ``Many use-cases and applications will need to use FOTA only. `` ``However, LwM2M devices process FOTA and SOTA updates differently.`` * [ ] upload binary file | Use external URL * [ ] Auto-generate checksum | Custom (Checksum algorithm, Checksum) * Description: ### Assign OTA package to device profile or a specific device ### Update process The platform tracks the progress of the update and persists it to the device attributes. * Update states for a successful process ``QUEUED > INITIATED > DOWNLOADING > DOWNLOADED > VERIFIED > UPDATING > UPDATED`` ### Update states reported by the device ## HTTP ## MQTT ## ESP32 :::info OTA 並非是 ESP32 專屬功能,很多Arduino系列也都支援,OTA 目前來說主要分成以下四種模式 1. Basic OTA:在Arduino IDE 中形成一個虛擬的 Port,選擇該Port即可上傳新的程式碼 2. OTAWebUpload:ESP32會變成一台 Webserver,透過 ESP32 網頁上傳 ArduinoIDE 編譯過的bin(binary)檔 3. HTTP Update:將編譯好的 bin 檔放在一個公開的網站上,讓ESP32主動下載。 4. Stream Update:透過MQTT將編譯好的bin檔直接上傳到ESP32中 ::: ![ESP32-CAM Layout](https://hackmd.io/_uploads/H1o7VfIQh.png) * 開發版 (5v USB 供電,降壓 3.3v,自帶 USB2Serial 晶片,CP2102 or CH340,後者便宜。) * VS Code * PlatformIO IDE Extension ### ESP32 By ESP-IDF 1. `sudo apt install git wget flex bison gperf python3 python3-venv python3-setuptools cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0` 2. `git clone git@github.com:espressif/esp-idf.git` 3. `git clone git@github.com:thingsboard/esp32-ota.git` 5. `cd esp-idf` 6. `./install.sh ${model}` example: `./install.sh esp32` | `./install.sh all` 7. `. $HOME/esp-idf/export.sh` 8. `cd ../esp32-ota` 9. `idf.py menuconfig` ### OTA by MQTT sample * pip3 install paho-mqtt mmh3 --user * python3 mqtt_firmware_client.py ``` After getting the following messages, Please write your ThingsBoard host or leave it blank to use default (localhost): - use your localhost, or the platform address; Please write your ThingsBoard port or leave it blank to use default (1883): - you can just continue by pressing “enter”, or input your port number; Please write accessToken for device: - copy device accessToken from ThingsBoard and paste it into the terminal; Please write firmware chunk size in bytes or leave it blank to get all firmware by request: - if you leave it blank, the file will be downloaded at once in the full size. If you want to download in parts, enter the size of the chunk. ``` ## References * [OTA updates](https://thingsboard.io/docs/pe/user-guide/ota-updates/) * [OTA updates](https://thingsboard.io/docs/user-guide/ota-updates/) * [MQTT Firmware API](https://thingsboard.io/docs/reference/mqtt-api/#firmware-api) * [thingsboard3.4版本之OTA升级](https://blog.csdn.net/qq_40351360/article/details/127659776) * [ESP32](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/ota.html) * [Google Groups - OTA How can I use one firmware file for 1 device profile](https://groups.google.com/g/thingsboard/c/jKMOM_k78-A) * [ThingsBoard 3.3 版本 OTA 源码分析](https://www.yiqisoft.cn/blogs/server-side/215.html) * **Github** * *[esp32-thingsboard-mqtt-client](https://github.com/liang-zhu-zi/esp32-thingsboard-mqtt-client) * [thingsboard-arduino-sdk](https://github.com/thingsboard/thingsboard-arduino-sdk) * [esp32-ota](https://github.com/thingsboard/esp32-ota/tree/master)