send

fun send(packet: MeshPacket): MessageHandle(source)

Enqueue an outbound packet for transmission.

Returns immediately with a MessageHandle tracking the packet's lifecycle. The engine assigns id and from from the local node's info; callers may override these if needed.

Payload size: enforced client-side against DATA_PAYLOAD_LEN (233 bytes). Oversized payloads throw MeshtasticException.PayloadTooLarge before enqueue — no handle is returned.

Return

a handle tracking delivery state

Parameters

packet

the packet to send

Throws

if not currently connected

if the payload exceeds the device limit

if the packet is malformed


suspend fun send(portnum: PortNum, payload: ByteArray, to: NodeId = NodeId.BROADCAST, channel: ChannelIndex = ChannelIndex(0), wantAck: Boolean = false, hopLimit: Int? = null): MessageHandle(source)

Convenience: build a MeshPacket for the given portnum with payload and enqueue it.

Constructs a packet with decoded = Data(portnum, payload, want_response = false) and forwards to send. Exists so callers do not need to import org.meshtastic.proto.Data to send a typed application payload.

hopLimit = null (the default) leaves the field at the proto-default 0, which the firmware interprets as "use the device's configured default hop limit". Set it explicitly only when you need to override that default for a single packet.

Example:

client.send(
portnum = PortNum.TEXT_MESSAGE_APP,
payload = "ack".encodeToByteArray(),
to = NodeId(0xa1b2c3d4.toInt()),
wantAck = true,
)

Suspend-safe but does not actually suspend — it delegates to the non-suspending send entry point. The suspend modifier is reserved so future versions can apply back-pressure on the engine inbox without a source-incompatible signature change.

Return

a MessageHandle tracking delivery state

Since

0.1.0

Parameters

portnum

the application port number (PortNum.TEXT_MESSAGE_APP, PortNum.POSITION_APP, …)

payload

the wire-encoded payload bytes (must be ≤ DATA_PAYLOAD_LEN)

to

destination NodeId; defaults to NodeId.BROADCAST

channel

ChannelIndex to send on; defaults to channel 0 (primary)

wantAck

request a reliable delivery ACK (firmware-side ACK, not end-to-end)

hopLimit

explicit hop limit override; null keeps the device default

Throws

if not currently connected

if payload exceeds the device limit


suspend fun send(portnum: PortNum, payload: Buffer, to: NodeId = NodeId.BROADCAST, channel: ChannelIndex = ChannelIndex(0), wantAck: Boolean = false, hopLimit: Int? = null): MessageHandle(source)

Convenience: build a MeshPacket for the given portnum from a kotlinx.io.Buffer payload.

Identical to the ByteArray-accepting send overload but reads from a kotlinx.io.Buffer, allowing callers to compose payloads with the kotlinx-io sink/source API instead of raw byte arrays. The buffer is consumed (read fully) on invocation.

Return

a MessageHandle tracking delivery state

Since

0.1.0

Parameters

portnum

the application port number

payload

a kotlinx.io.Buffer containing the wire-encoded payload (≤ DATA_PAYLOAD_LEN)

to

destination NodeId; defaults to NodeId.BROADCAST

channel

ChannelIndex to send on; defaults to channel 0 (primary)

wantAck

request a reliable delivery ACK

hopLimit

explicit hop limit override; null keeps the device default

Throws

if not currently connected

if the buffer content exceeds the device limit