Used for modern ESP32 devices (e.g., Heltec V3, T-Beam S3). This method utilizes the **Unified OTA Protocol**, which enables high-speed transfers over TCP (port 3232) or BLE. The BLE transport uses the **Kable** multiplatform library for architectural consistency and modern coroutine support.
- **Pre-shared Hash Verification**: The app sends the firmware SHA256 hash in an initial `AdminMessage` trigger. The device stores this in NVS and verifies the incoming stream against it.
- **Connection Retry**: Robust logic to wait for the device to reboot and start the OTA listener.
- **Automatic MTU Handling & Fragmentation**: The BLE transport automatically detects the negotiated MTU and fragments data chunks into packets that fit. It carefully manages acknowledgments for each fragmented packet to ensure reliability even on congested connections.
The standard update method for nRF52-based devices (e.g., RAK4631). It leverages the **Nordic Semiconductor DFU library**.
```mermaid
sequenceDiagram
participant App as Android App
participant Radio as Mesh Node
participant DFU as nRF DFU Bootloader
App->>Radio: Trigger DFU Mode
Radio->>Radio: Reboot into Bootloader
App->>DFU: Connect via BLE
App->>DFU: Initialize DFU Transaction
loop Transfer
App->>DFU: Stream ZIP Segments
DFU-->>App: Progress
end
DFU->>DFU: Verify, Swap & Reboot
```
#### 3. USB / UF2 (RP2040, nRF52, STM32)
For devices supporting USB Mass Storage updates. The app triggers the device into its native bootloader mode, then guides the user to save the UF2 firmware file to the mounted drive.
```mermaid
sequenceDiagram
participant App as Android App
participant Radio as Mesh Node
participant USB as USB Mass Storage
App->>Radio: rebootToDfu()
Radio->>Radio: Mounts as MESH_DRIVE
App->>App: Prompt User to Save UF2
App->>USB: Write firmware.uf2
USB->>USB: Auto-Flash & Reboot
```
### Key Classes
-`UpdateHandler.kt`: Entry point for choosing the correct handler.
-`Esp32OtaUpdateHandler.kt`: Orchestrates the Unified OTA flow.
-`WifiOtaTransport.kt`: Implements the TCP/UDP transport logic for ESP32.