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:
- Program changes to the Arduino skecth
- 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”)
- Always have the ESP.restart() function called after the update function.
- Compile program in Arduino IDE
- Export binary (IDE menu: Sketch -> Export Compiled Binary)
- Copy and rename the corresponding .bin file from your arduino folder to the openhab static/firmware folder
- On openhab basic ui, trigger the update from the corresponding item
- 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.