![OTA firmware upgrade diagram](../../blog/images/covers/cover-ota.svg)

Once devices are deployed in the field, firmware upgrade becomes an unavoidable challenge hanging overhead. A reliable OTA solution must answer three questions at once: the upgrade can be delivered, it won't brick the device, and a bad upgrade can be rolled back.

## OTA Basic Flow

```mermaid
sequenceDiagram
    participant D as Device
    participant P as Platform
    P->>D: Push upgrade notification (version + package URL + signature)
    D->>D: Verify version and storage space
    D->>P: Request firmware data in chunks
    P-->>D: Firmware fragments
    D->>D: Verify signature + write to backup partition
    D->>P: Report upgrade result
    D->>D: Reboot into new firmware
```

## Key Design Points

* **Dual partition (A/B)**: the new firmware is written to the backup partition, and the boot partition is switched only after verification passes, so an interrupted upgrade won't brick the device;
* **Chunking and resumable transfer**: under weak network conditions, download in fixed-size blocks and record completed block numbers, resuming from the breakpoint after a disconnection;
* **Signature verification**: the firmware package must carry a hash and signature; the device discards it immediately if verification fails, preventing tampered firmware from being flashed;
* **Version negotiation**: the device reports its current version, and the platform decides whether an upgrade is needed, supporting cross-version and forced upgrade policies.

## Canary Release

Full-scale rollout is the main source of OTA incidents. The recommended cadence is staged pushes — "internal test devices → 5% → 30% → full rollout" — observing the failure rate and device reboot rate for each batch, with one-click pause when anomalies appear.

## Implementation in FastBee

FastBee device-side firmware has built-in OTA capability: after a single-file firmware is uploaded on the platform, upgrade tasks are dispatched per device, and the device automatically completes download, verification, and reboot, with progress trackable in the device logs. For the partition table and boot logic on the ESP32/ESP8266 side, see the [Device Development Documentation](https://www.fastbee.cn/doc/en/device/v2/dev/development-guide.html).
