Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By jarnoldbrown
#66289 I have a project which uses an ESP12. It basically reads a couple of sensors, connects to another ESP that is in AP mode, sends the readings and then goes into deep sleep for an hour.

It would be great if I could also update the code via OTA, but I'm a bit confused as to how this would work, since the device is not currently spending any time on the same network as my PC.

Since one of the sensors is an accelerometer, I could, perhaps, turn the thing upside down, say, to get it into OTA mode.
As I say, I'm not 100% clear how the OTA scheme works. Is it like a bootloader that gets a look-in at power-up, or does it require some code added to the main app?

Any kind advice gratefully received.
User avatar
By torntrousers
#66345 The best approach that I have found for this is to have the ESP check if there is new firmware and do the download/update itself. For example, when using Thingspeak you can use the channel metadata to specify the firmware version and a url to the firmware itself and the ESP regularly checks the metadata version and if its newer the ESP goes and downloads/updates with the newer firmware. Ths way when you want to update the firmware you compile a new binary with an incremented version, upload the binary somewhere and then update the Thingspeak metadata with the new version number and url to the firmware binary, and then when the ESP next wakeups and checks the metadata version it will go update itself.

Some code doing that is here, which works with this Thingspeak channel metadata:
Code: Select all{
"firmwareVersion" : "1.0.5",
"firmwareURL" : "http://s3.eu-west-2.amazonaws.com/torntrousers/firmware/UsbDeviceDS18B20.ino.generic-1.0.5.bin",
"publishInterval" : 900,
"tempAdjust" : -0.7
}
User avatar
By jarnoldbrown
#66356 Thanks for the reply. Unfortunately, not only am I not using ThingSpeak, but the ESP is not normally connecting to the internet, just to another ESP in AP mode. I have tested the idea of reading one of the accelerometer axes to dertmine if the device is "standing on its head", and while that works, it's not the best solution, as the device only wakes up every hour, as one might have to wait the best part of an hour to make a change. Since I plan to seal this device up, I might resort to a reed switch, or detect when It's on the charger, either of which could wake the ESP from deep sleep and request that it enter OTA mode.

I suppose I could instruct the other ESP(which is running an MQTT client as well, so IS contactable) and have it tell the first one that an update is available, but currently I have no idea how to have the ESP downoad and program a firmware update.