0Pricing
Arduino & IoT Academy · 课时

回滚错误的更新

上传出错时安全恢复

回滚错误的更新 是 CoddyKit 上的免费 Arduino & IoT Academy 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Arduino & IoT Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Arduino & IoT Academy 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Updates Can Go Wrong

Even careful OTA pushes sometimes ship broken code. A solid plan needs a way to roll back to firmware that actually worked.

The Brick Risk

If new firmware can't connect to WiFi, you lose OTA itself. Without a safety net the device becomes a useless brick.

Two Partitions Save You

The ESP32 keeps the old app in one slot while flashing the new one into another. The previous build is still intact if needed.

Mark a Build as Trusted

A fresh update boots in a pending state. Your code must prove it works and then confirm the image so it becomes permanent.

esp_ota_mark_app_valid_cancel_rollback();

Self-Test on Boot

Before confirming, run a quick health check: did WiFi connect, did key sensors respond? Only then mark the build valid.

Auto Rollback on Failure

If a pending build crashes or reboots before confirming, the bootloader quietly returns to the last good firmware on its own.

Trigger It Yourself

You can also force a return to the previous image in code with esp_ota_mark_app_invalid_rollback_and_reboot() when a check fails.

esp_ota_mark_app_invalid_rollback_and_reboot();

Use a Watchdog

A watchdog timer resets a frozen board. Paired with rollback, a hung update reboots straight back into working code.

Version Your Firmware

Stamp each build with a version number you can print over Serial, so you instantly know which image is actually running.

#define FW_VERSION "1.4.2"
Serial.println(FW_VERSION);

Test on One Device First

Never push to your whole fleet at once. Update a single canary device, watch it, then roll out widely. 🐤

Always Keep a Recovery Path

Worst case, a USB cable still reflashes any board. Design so a bad OTA is an inconvenience, never a permanent loss.

Quick Check

Consider what happens if new firmware crashes before it confirms itself.

Recap

Keep two partitions, self-test then confirm each build, lean on auto rollback and a watchdog, and always leave a USB recovery path. 🛡️

常见问题解答

「回滚错误的更新」课时是免费的吗?

是的 — 「回滚错误的更新」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Arduino & IoT Academy 课程的其余内容,请升级到 CoddyKit PRO。 Arduino & IoT Academy 课程共包含 4 节课。

「回滚错误的更新」这节课中我会学到什么?

上传出错时安全恢复 你通过在浏览器中直接运行的动手代码来练习 Arduino & IoT Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Arduino & IoT Academy 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Arduino & IoT Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。

「回滚错误的更新」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Arduino & IoT Academy 课中编写并运行代码吗?

能。每节 Arduino & IoT Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 为什么 OTA 对现场设备很重要
  2. 启用 ArduinoOTA
  3. 托管网页更新页面
  4. 回滚错误的更新
← 返回 Arduino & IoT Academy