Openhab2 & MQTT: OTA Firmware update ESP8266

Hi, I was trying to figure out how to update firmware of my “Things” once they are installed on hard to reach places.
I came up with a working solution. It has many steps and would like to see if any of you have some advice on how to simplify it or if there is already something else.

I have the following setup:

Server: Raspberry Pi 3 B with Openhabian (Openhab 2) and Mosquitto all updated as of (6/13/2017)

“Things” are ESP8266 (different versions) programmed in Arduino IDE using:

ESP8266WiFi.h --------------> WiFi Connection
PubSubClient.h ---------------> MQTT client (Suscribe/Publish)
ESP8266HTTPClient.h -----> htpp client
ESP8266httpUpdate.h ------> OTA httpupdate

OTA Firmware update configuration:

— In my openhab sitemap I have a “Firmware update” section with one switch item for each ESP8266 deployed.
— Every switch item has an outgoing mqtt binding to trigger the corresponding OTA update.
— ESP8266s are suscribed to their own “OTA update” topic

OTA Update process:

  1. Program changes to the Arduino skecth
  2. Always have a mqqt “OTA update” response to execute: "ESPhttpUpdate.update(OTA_FIRMWARE)"
    where OTA_FIRMWARE is the http link to your openhab webserver where static pages are stored incluiding the name of the firmware file .bin e.g. ( #define OTA_FIRMWARE “http://192.168.2.11:8080/static/firmware/Test_OTA.bin”)
  3. Always have the ESP.restart() function called after the update function.
  4. Compile program in Arduino IDE
  5. Export binary (IDE menu: Sketch -> Export Compiled Binary)
  6. Copy and rename the corresponding .bin file from your arduino folder to the openhab static/firmware folder
  7. On openhab basic ui, trigger the update from the corresponding item
  8. Wait a few second for the update and restart of your ESP8266

Note The first time upload to the ESP8266 has to be with physical connection and a reset is needed for the following OTA updates to work. (I don’t know the reason, any ideas?)

I tried to be brief, let me know if you have any questions or suggestions.

1 Like

This is a very elegant solution! Would you mind sharing the *.ino file with the OTA example?
Thanks!