WifiProvisionViewModel

class WifiProvisionViewModel(bleScanner: BleScanner, bleConnectionFactory: BleConnectionFactory, dispatchers: CoroutineDispatchers, applicationScope: ApplicationCoroutineScope) : ViewModel(source)

ViewModel for the WiFi provisioning flow.

Created per navigation entry, so the instance is scoped to the entry's ViewModelStoreOwner. A fresh NymeaWifiService (and its own BleConnectionFactory-backed org.meshtastic.core.ble.BleConnection) is created lazily for each provisioning session and cleaned up via onCleared. Device discovery and ordering live in DeviceDiscovery; nothing connects until the user taps a listed device or confirms an address.

Constructors

Link copied to clipboard
constructor(bleScanner: BleScanner, bleConnectionFactory: BleConnectionFactory, dispatchers: CoroutineDispatchers, applicationScope: ApplicationCoroutineScope)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

True where the scan is the browser's device chooser, which opens only from a click: the screen waits for one instead of connecting on arrival.

Link copied to clipboard

Functions

Link copied to clipboard
expect open fun addCloseable(closeable: AutoCloseable)
expect fun addCloseable(key: String, closeable: AutoCloseable)
Link copied to clipboard

The user accepted the address held in WifiProvisionUiState.pendingAddress.

Link copied to clipboard
fun connectToDevice(address: String? = null)

Connect to the device with address, or to the one the user picks in the browser's own chooser when address is null there. Where the app scans itself, a null address starts the device list instead: the connection never goes to whichever device advertises first. Pauses at WifiProvisionUiState.Phase.DeviceFound so the user can check the device before proceeding.

Link copied to clipboard

Connect to the listed device with address, which the user tapped.

Link copied to clipboard

Cancel any scan or pending confirmation, close any active BLE connection and return to the initial state.

Link copied to clipboard
expect fun <T : AutoCloseable> getCloseable(key: String): T?
Link copied to clipboard
fun open(address: String?)

Start the screen for address, which a link or caller may supply. Nothing connects here:

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

Send WiFi credentials to the device.

Link copied to clipboard
fun rescan()

Clear the list and scan again, from the list or after a failed scan or connect.

Link copied to clipboard

Called when the user confirms they want to scan networks after device discovery.