Remote OTA firmware updates for ESP32 via Telegram. Flash from anywhere — no LAN, no port forwarding, no USB after the first time.
By Wyltek Industries · Companion to TelegramSerial
- Build your sketch → export
.bin - Send
/flashto your bot with the.binattached - Device downloads, verifies, flashes, reboots
- New firmware reports back:
✅ Running v1.1
Arduino Library Manager: search TelegramOTA
PlatformIO:
lib_deps = toastmanAu/TelegramOTA#include <WiFi.h>
#include <TelegramOTA.h>
TelegramOTA ota("YOUR_BOT_TOKEN", "YOUR_CHAT_ID");
void setup() {
WiFi.begin("ssid", "pass");
while (WiFi.status() != WL_CONNECTED) delay(500);
ota.begin("1.0.0"); // version string — shown after flash
}
void loop() {
ota.handle(); // polls Telegram every 5s
}| Command | Action |
|---|---|
/flash + .bin |
Flash new firmware |
/rollback |
Revert to previous firmware |
/reboot |
Restart device |
/status |
Heap, uptime, RSSI, flash usage |
/version |
Firmware version + build date |
/log |
Last 50 log lines |
/help |
Command list |
#include <TelegramSerial.h>
#include <TelegramOTA.h>
TelegramSerial tgSerial(BOT_TOKEN, CHAT_ID);
TelegramOTA ota(BOT_TOKEN, CHAT_ID);
void setup() {
// ...WiFi...
tgSerial.begin(); // Serial → Telegram
ota.begin("1.0.0"); // OTA via Telegram
}
void loop() {
tgSerial.handle();
ota.handle();
// Serial.println() now streams to your chat
}Full remote dev loop: push code → build → /flash → read serial output — all from Telegram.
Replace Serial.println() with ota.log() to keep a ring buffer accessible via /log:
ota.log("Sensor: " + String(reading));ota.onFlash([](bool ok, const String& msg) {
// called after flash attempt
});
ota.onProgress([](size_t written, size_t total) {
// called during download
});
ota.onCommand([](const String& cmd, const String& args) -> bool {
if (cmd == "/sensor") { /* handle */ return true; }
return false; // let TelegramOTA handle it
});If new firmware crashes on boot, the previous firmware is still in the inactive OTA partition. Send /rollback to revert (requires the device to be at least partially booting and connected to WiFi).
For automatic rollback on crash: call esp_ota_mark_app_valid_cancel_rollback() in your setup once you're happy the firmware is stable.
- Only the configured
CHAT_IDcan trigger OTA or commands - Add additional authorised chats:
ota.addAuthorisedChat("987654321") - All Telegram traffic is HTTPS
Override in platformio.ini build_flags:
build_flags =
-DTOTA_POLL_INTERVAL_MS=3000 ; poll every 3s (default 5s)
-DTOTA_LOG_BUFFER_LINES=100 ; bigger log buffer
-DTOTA_CHUNK_SIZE=2048 ; larger OTA chunks- ESP32 (any variant)
- ArduinoJson >= 7.0.0
- WiFi connection with internet access