Firmware update (OTA)#

DeviceSession.updateFirmware(_:) drives the vendor firmware-update GATT service and emits OtaProgress values.

import BrainAccessKit

func updateFirmware(_ session: DeviceSession, image: [UInt8]) async {
    guard session.supportsFirmwareUpdate else {
        print("OTA not supported by this device")
        return
    }

    do {
        for try await progress in session.updateFirmware(image) {
            switch progress {
            case .requesting:
                print("requesting update mode")
            case .transferring(let sentBytes, let totalBytes):
                print("sent", sentBytes, "of", totalBytes)
            case .finalizing:
                print("finalizing")
            case .done:
                print("transfer complete; reconnect and verify firmware version")
            }
        }
    } catch {
        print("OTA failed:", error.localizedDescription)
    }
}

Preconditions#

  • The device must expose the OTA service; check supportsFirmwareUpdate.

  • The session must be DeviceState.ready. Streaming is refused while DeviceState.updating.

  • The firmware image must be non-empty. The SDK does not fetch or bundle firmware images.

No CRC, no resume, silent rejection#

The wire protocol has no checksum and no resume. Failed or rejected transfers leave the previous firmware active. A device can complete the transfer handshake and still keep its old image, so OtaProgress.done is not proof that the new firmware is running.

The reliable success check is: let the device reboot/re-advertise, reconnect, read DeviceSession.info.value?.firmwareVersion and compare it to the version you intended to flash.