Skip to content

07 OTA Over the air updates

KlausMu edited this page Nov 8, 2023 · 1 revision

OTA

If you want to upload new firmware OTA (over the air, which means without serial connection), activate

#define useOTAUpdate

in the file "config.h".

Please note that for uploading the first time you have to use a serial connection!

For more details about what OTA is and how to use, please see this video from Andreas Spiess: #332 ESP32 OTA tutorial with tricks (incl. OTA debugging)

If you want to upload a new firmware, use these two lines in file "platform.ini":

upload_protocol = espota
upload_port = <ip-adress of your ESP32, see serial log>

On how to do it with the Arduino IDE, see the video above.

I recommend to activate OTA only when needed for uploading a new firmware. As soon as you activate OTA it takes about 10K of heap space, which leads sometimes to an unstable ESP32 (reboot after some days, hours or even minutes, usually when receiving a WiFi packet). Activate OTA via sending a MQTT message to "esp32_fan_controller/cmnd/OTA" with payload "ON" and then upload the new firmware.

Same holds for using a seperate thread for checking for OTA updates. Creating a seperate thread for this takes also about 10k of heap space, so I don't recommend it. I had instability issues when doing it that way. It's also fine to check for OTA updates in the main loop.

Serial logging

If you have no serial connection, how can you get debug messages? For this I'm using the library jandrassy/TelnetStream. Instead of using "Serial.print(...)" you simply use "TelnetStream.print(...)". Then you can use a telnet connection to your ESP32 to get debug messages.

But what if you sometimes want to have debug messages via serial connection and sometimes via TelnetStream? Always changing the code from "Serial.print(...)" to "TelnetStream.print(...)" and back is not a good solution. For this I created a class called "LogStreamClass". Now in your code you can simply write "Log.printf(format, ...)". In "config.h" you can define one or both of

#define useSerial
#define useTelnetStream

No need to change the code.

Clone this wiki locally