Saturday, February 04, 2017

ESP8266 and OTA upgrades

An OTA (Over The Air) upgrade is not really a new idea. I've worked with Cisco routers for a long time and when we started getting flash file systems we were able to upgrade the firmware and keep a backup copy in case the new version caused too many issues. We'd update the firmware while the router ran and reboot at a convenient time to minimize downtime. While that's not OTA it was as remote as you could get. I had no idea where the equipment was but I could perform the upgrade from the comfort of my laptop at 3 AM. If we add WiFi to the mix it's now what I'm referring to as OTA. Similarly OTA upgrades on the ESP8266 will allow you to have 2 copies of the firmware. You can upgrade without having to physically remove the device from service. Which could be difficult if the ESP8266 is embedded into your house electrical or an appliance such as a dishwasher or garage door opener. I haven't attempted an OTA upgrade yet so I don't know if the device performs its normal functions while it's downloading. That might be a function of the device's firmware. It should be possible but this is still a micro-controller and it does have other limited resources (such as RAM). I'll need to take a look at that.

The reason for the interest in the OTA updates is that I have a bunch of the ESP8266 boards (Adafruit's Huzzah board, ESP01, ESP12, etc.) and they're in a number of devices I've found such as the Sonoff products, a couple of WiFi outlets I picked up at Walmart's and the loose ESP01s which I intend to use for serial to WiFi converters. The Adafruit Huzzah boards have the larger 4MB/32Mb chip (it's shielded so I can't see it). Many of the older devices have the 25Q40 SPI Flash chip (512KB = 4Mb). This is just large enough to support firmware with OTA, flash file system and the firmware image with MQTT support. Not much room there for a second firmware image. But by upgrading to something like a 25Q32 (4MB = 32Mb) there's more than enough room for even 2 copies of large firmware images. I've also poked around found someone using a 25Q128 chip (16MB = 128Mb). For now I'll stick with what I know works, the 25Q32 and keep an eye on the rest. I've also found a nice ESP8266 Memory Map. And finally one interesting note I found. It appears the on board SPI flash needs to support QIO mode and not SPI for the processor to run. Not sure why that is but I'll keep digging.

One thing not mentioned above is security. We'll we need to work on that. But as I understand it the MQTT support also supports secure protocols and login. I'll work with that and see where that takes me. The ESP8266's processor is 32bit so it has more than enough power to handle all the tasks I've listed so far. I'm really looking forward to using the ESP8266's to monitor and control my home. Having control via MQTT will make things easier and with the OTA updates it should make it pretty easy to build a device that's very easily added to a smart home with minimal configuration by the end user. I'll need to put further work into that but we'll were that takes us. It really looks like we've got all the parts that will make Smart Technology easy to use and secure. We'll see.