connect

suspend fun connect()(source)

Initiate connection to the device.

Activates storage, starts the engine coroutines, connects the transport, and performs the handshake. connection is updated throughout; subscribers can observe ConnectionState.Configuring progress.

Suspend semantics: suspends until ConnectionState.Connected is reached (i.e. the Stage 2 config_complete_id matches the Stage 2 nonce — see protocol.md §6). The function does not wait for any subsequent NodeDB churn.

Cancellation: cooperatively cancellable at every suspension point. If the caller's coroutine is cancelled mid-connect the engine tears down (transport disconnect, storage close, in-flight handles failed with Disconnected) before kotlin.coroutines.cancellation.CancellationException is rethrown. After cancellation the client is observably ConnectionState.Disconnected and may be re-connect()-ed.

Idempotency: throws MeshtasticException.AlreadyConnected if already connected.

Throws

if the transport cannot establish a connection

if the handshake fails or data is malformed

if storage activation fails

if the caller's coroutine is cancelled