Transport

The app talks to the node over four transports (BLE, USB serial, TCP and WebSocket) behind one abstraction.

Transport Abstraction

The transport layer is abstracted through interfaces defined in core:repository (RadioTransport, RadioTransportFactory, RadioInterfaceService). Each transport’s concrete implementation lives in core:network: BleRadioTransport (BLE), TcpRadioTransport (TCP), WebSocketRadioTransport (firmware’s WebSocket phone API, over Ktor), and SerialRadioTransport (Android USB serial), alongside MockRadioTransport and ReplayRadioTransport for development. core:ble supplies the lower-level BLE connection primitives (scanning, GATT, Kable wiring) that BleRadioTransport builds on — it does not implement RadioTransport itself. This lets the app work identically regardless of the underlying connection type.

Feature UI → RadioController → RadioInterfaceService → RadioTransport (BLE | Serial | TCP | WebSocket)

Every transport address starts with a one-character InterfaceId: x BLE (! is accepted too), s serial, t TCP, w WebSocket (a ws:// or wss:// URL), m mock, r replay, and n for no device selected. RadioTransportFactory.isAddressValid checks that prefix before a connection is attempted.

Bluetooth Low Energy (BLE)

Module: core:network (the BleRadioTransport implementation) built on core:ble (BLE connection primitives)
Platforms: Android, Desktop (JVM via Kable), Web (Kable over Web Bluetooth); code compiles for iOS, but no iOS app ships

The primary transport for mobile devices and also available on desktop:

  • Service discovery for Meshtastic GATT services
  • Characteristic-based read/write for protobuf packets
  • Connection state management and automatic reconnection
  • MTU negotiation for optimal packet sizes

Where the Code Lives

  • BleRadioTransport (core:network) — the RadioTransport implementation for BLE
  • core:ble — BLE scanning, connection, and GATT operations (BleScanner, BluetoothRepository, KableBleConnection), which BleRadioTransport consumes
  • The Kable scanner and connection are shared commonMain code; androidMain and jvmMain hold each platform’s BluetoothRepository, Kable setup, and scan rate limiting, and Android adds bonding and the GATT cache refresh

USB Serial

Module: core:network
Platforms: Android (OTG), Desktop, Web (Web Serial)

Serial communication over USB:

  • Uses usb-serial-for-android library on Android
  • Direct serial port access on Desktop (JVM)
  • Probe table for supported USB vendor/product IDs
  • Automatic detection when USB device is connected; on Web only for a port the user has already granted through the browser’s port picker

Where the Code Lives

  • SerialRadioTransport (core:network, androidMain) — the Android RadioTransport implementation
  • SerialTransport (core:network, jvmMain) — the shared serial-port transport Desktop builds on
  • DesktopRadioTransportFactory (desktopApp) — creates SerialTransport, which uses jSerialComm, for Desktop’s serial addresses

TCP/IP

Module: core:network
Platforms: Android, Desktop (iOS: code compiles, but there’s no iOS app target or RadioTransportFactory — see Transport Factory)

Network-based transport for Wi-Fi-enabled nodes:

  • TCP socket connection to the node’s IP address
  • Default port: 4403
  • Nodes on the local network found through mDNS (_meshtastic._tcp): NsdManager on Android, JmDNS on Desktop
  • Used for development with meshtasticd and simulated nodes
  • Available when BLE/USB is impractical

WebSocket

Module: core:network (WebSocketRadioTransport)
Platforms: Android, Desktop, Web

Firmware’s WebSocket phone API carries one binary ToRadio or FromRadio per message at /api/v1/ws, for one client at a time. Addresses are ws:// or wss:// URLs, and an empty path becomes /api/v1/ws (WebSocketUrl.kt). Released firmware does not serve it yet. In a browser it is the only network transport.

WebSocketRadioTransport reconnects with the same ReconnectBackoff as TCP. A failed dial is named from the upgrade response: a 404 at /api/v1/ws (firmware without the WebSocket route), any other refused upgrade, or a TLS failure. A browser reports none of these: its engine gives no upgrade status, so a 404, a refused upgrade or a TLS failure all read as a failed connection there. A dropped connection is named from its close: a slot given to another client (4001), a message too big (1009), or a contested slot. Those three hold every automatic redial, network recovery included, until the user connects again.

Transport Factory

The RadioTransportFactory interface abstracts transport creation:

interface RadioTransportFactory {
    val supportedDeviceTypes: List<DeviceType>

    /** Whether the virtual demo transports (`m` mock / `r` replay) may be offered and bound right now. */
    val mockTransportEnabled: StateFlow<Boolean>

    /** Whether this build ships a packet capture to replay, rather than degrading to plain mock. */
    val isReplayTransportAvailable: Boolean

    fun createTransport(address: String, service: RadioInterfaceService): RadioTransport
    fun isAddressValid(address: String?): Boolean
    fun toInterfaceAddress(interfaceId: InterfaceId, rest: String): String
}

mockTransportEnabled is a flow, not a one-shot check: the Android Demo Mode gesture (five taps on the Settings app-version row) unlocks the demo transports mid-session, and the device list has to notice. Every consumer must read that one flow — the visibility path and the isAddressValid admission path have to agree, or the demo entry appears and then refuses to connect.

BaseRadioTransportFactory (core:network, commonMain) holds the shared half: it creates BleRadioTransport for BLE addresses and WebSocketRadioTransport for WebSocket ones, admits each address type in isAddressValid, and dispatches every other address in createPlatformTransport: mock and no-device itself, and replay, TCP and serial through hooks a platform overrides. NonWebRadioTransportFactory (nonWebMain) supplies raw TCP for Android and Desktop. On hardware without Bluetooth LE it refuses BLE addresses, and the Android factory refuses serial addresses on hardware with no USB host, so a saved address restored onto such a device is kept but never armed.

Platform-specific implementations:

  • Android: AndroidRadioTransportFactory (core:network, androidMain) supports BLE + USB + TCP; Demo Mode is on in debug builds and Firebase Test Lab, and in release builds once hidden features are unlocked
  • Desktop: DesktopRadioTransportFactory (desktopApp) supports BLE (Kable) + USB + TCP; Demo Mode is a debug-build feature, and an r address opens the plain mock, and an n or unknown prefix opens the no-op transport like every other platform
  • Web: WasmJsRadioTransportFactory (core:network, wasmJsMain) supports BLE (Kable over Web Bluetooth) + USB (Web Serial) + WebSocket. It refuses raw TCP addresses (isRawTcpSupported = false), since a browser opens no sockets, so its Network pane takes WebSocket addresses only
  • iOS: Code compiles for BLE and TCP, but no RadioTransportFactory implementation exists and no iOS app ships

Connection Lifecycle

  1. Discovery — Find available nodes (BLE scan / USB detect / mDNS or a manually entered TCP address or WebSocket URL)
  2. Connection — Establish link to selected node
  3. Handshake — Exchange node info and configuration
  4. Active — Normal message exchange
  5. Disconnection — Clean teardown or error recovery

The app-level state is ConnectionState (Disconnected, Connecting, Connected, DeviceSleep), read through ConnectionStateProvider. MeshConnectionManager writes Connecting, DeviceSleep and Disconnected as it reconciles transport events with the node’s sleep policy, and MeshConfigFlowManager writes Connected once the handshake completes. UI code observes this state, never RadioInterfaceService.connectionState.

Adding a New Transport

  1. Implement RadioTransport interface
  2. Give it an InterfaceId prefix, admit it in isAddressValid, and create it in the platform’s createPlatformTransport
  3. Add connection UI in feature:connections
  4. Update DI bindings for the platform