NymeaWifiService

class NymeaWifiService(scanner: BleScanner, connectionFactory: BleConnectionFactory, dispatcher: CoroutineDispatcher)(source)

GATT client for the nymea-networkmanager WiFi provisioning profile.

Responsibilities:

  • Scan for a device advertising WIRELESS_SERVICE_UUID.

  • Connect and subscribe to the Commander Response characteristic.

  • Send JSON commands (chunked into ≤20-byte BLE packets) via the Wireless Commander characteristic.

  • Reassemble newline-terminated JSON responses from notification packets.

  • Parse the nymea JSON protocol into typed Kotlin results.

Lifecycle: create once per provisioning session, call connect, use scanNetworks / provision, then close.

Constructors

Link copied to clipboard
constructor(scanner: BleScanner, connectionFactory: BleConnectionFactory, dispatcher: CoroutineDispatcher)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Address of the device connect last connected to, or null before a connection.

Functions

Link copied to clipboard
suspend fun close()

Disconnect, which releases the BLE peripheral, then cancel the service scope.

Link copied to clipboard
suspend fun connect(address: String?): Result<String>

Find the device with address, or the one the user picks in the scanner's own chooser, and connect to it.

suspend fun connect(device: BleDevice): Result<String>

Connect to device, which the caller already chose from a scan, and return its advertised name.

Link copied to clipboard
suspend fun provision(ssid: String, password: String, hidden: Boolean = false): ProvisionResult

Provision the device with the given WiFi credentials.

Link copied to clipboard

Trigger a fresh WiFi scan on the device, then return the list of visible networks.