Skip to content
/ D-OTA Public

Delta Over-the-Air device firmware update implementation using the ESP8266 board and the ESP8266-RTOS-SDK

License

Notifications You must be signed in to change notification settings

thinkty/D-OTA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

D-OTA

Implementation of the delta (differential) over-the-air device firmware update on the ESP8266 board running the ESP8266 RTOS SDK. Delta OTA update is different from a normal OTA update in a way that it receives only the differential of the previous firmware and the new firmware. Therefore, the resulting transactions have relatively low overhead compared to the normal OTA update that sends the entire firmware image.

Requirements

Make sure the development environment is set before building. For how to setup the tools, see the Get Started document from Espressif.

Project Directory

This project directory is expected to be in the ~/esp directory along with the ESP8266_RTOS_SDK and the xtensa-lx106 toolchain since it is for the ESP8266 MCU.

Example:

    \esp
    |----ESP8266_RTOS_SDK/
    |----xtensa-lx106-elf/
    |----project/

For the description on the project structure, check the document.

Internet Connection

Unlike the previous project, the ESP8266 device needs to connect to the internet in order to receive updates and publish sensor values. In order to access the internet, this project utilizes an access point (WiFi). The WiFi SSID and Password needs to be set in the configuration file (sdkconfig) which can be done using the command make menuconfig and selecting the Example Configuration option.

Sensors

This project uses two additional sensors:

  • DHT22 : for collecting temperature and humidity data (app_task_dht.h)
  • SZH-SSBH-011 : a CDS photoresistor sensor to measure light intensity (app_task_cds.h)

The sensor values are read in a preset interval and publishes the data to the pub/sub broker bridge.

Pub/Sub Broker

As mentioned above, the sensor values are published to this broker and also the device subscribes to the update topic to receive firmware updates. Bridge is just another hobby project of mine and it doesn't necessarily have to be Bridge. The user can choose whatever messaging platform/server/protocol they want to use, but it will require some changes to the code to meet the communication protocols for that specific service.

Partitions

The flash partition is stored in the partitions.csv to support OTA and also delta OTA updates.

The OTA partitions to store the new and current images are 640 KB each, and the storage for the delta file is 128 KB. This means that the images should be less than 640 KB. The storage partition is in between the two OTA partitions due to the required offset (that seems to be a bug?).

To specify the partition table, run make menuconfig, select Partition Table > Partition Table > Custom partition table CSV, and specify the file name in Custom partition CSV file. Details on the partition tables can be found here.

In addition, to enable the file system to store the delta file, enable SPIFFS.

Delta Patch Tools

There are various differential generator/patcher algorithms and compression algorithms available. For this project, I've used detools (>= 0.53.0) to create/apply the patch, and heatshrink (>= 0.4.1) to handle the compression/decompression of the patch.

To create the delta file, one can simply install the detools command line tool and run the following command.

detools create_patch --compression heatshrink old-image new-image patch-name

The patch tools are all contained within the components directory.

Usage

Run make menuconfig to configure the project with the sdkconfig file, and make sure to save it.

The default serial port for your ESP8266 board can be set through Serial flasher config > Default serial port. Depending on the OS, on Windows, the port will have names like COM1. On Linux, it will be like /dev/ttyUSB# or /dev/ttyACM#.

Command Description
make menuconfig Open the configuration tool to create the sdkconfig configuration file
make all Compile your project code. In the first time running after installing ESP8266 RTOS SDK, the command will compile all components for the SDK as well and take some time.
make app Compile only the project code.
make flash Compile, generate bootloader, partition table, and application binaries, and flash app image to your ESP8266 board
make flash ESPPORT= <port> Override the port specified in the sdkconfig file and flash
make monitor Open the serial monitor for your ESP8266 board
make flash monitor Compile, flash, and open monitor all-in-one
make partition_table Print the current partition table of the device
make help For additional information about the toolchain or visit the README

Similar to overriding the port when flashing, the port for the monitor can be modfied as well. See the document for more variables that can be specified.

To use this in conjunction with the Bridge pub/sub broker, run the broker first, configure the port and IP address by running make menuconfig, and flash the image onto the ESP8266 board. Once the device successfully boots, it will subscribe to the preset topic (ex. update) to receive the delta file or the whole firmware image. Create a delta file using detools and make sure that the compression is done using heatshrink. It might be a good idea to save each version of the firmware image for convenience. With the delta file ready, send it using any tool that is capable of sending tcp messages (or one can also use the bridge-tester instead) to the pub/sub broker. Once the pub/sub broker receives the file, it will relay it to the subscribed hosts and the patch should be applied as soon as the file arrives. When the patch is applied, the device will automatically go into a software reset and boot with the new firmware image from the appropriate partition.

License

MIT

About

Delta Over-the-Air device firmware update implementation using the ESP8266 board and the ESP8266-RTOS-SDK

Resources

License

Stars

Watchers

Forks

Languages