Skip to content

PacketBuilder

Max Litruv Boonzaayer edited this page Feb 15, 2026 · 2 revisions

Static class for building MeshCore command packets to send to the companion radio.

All methods return byte arrays ready for COBS framing and transmission.

public static class PacketBuilder

Table of Contents

🔧 Properties

⚙️ Methods


Properties

SendAdvert

static readonly

SendAdvert : byte[]

Builds a packet to broadcast an advertisement.

public static byte[] SendAdvert { get; }

GetMsg

static readonly

GetMsg : byte[]

Builds a packet to retrieve the next pending message.

public static byte[] GetMsg { get; }

GetBattery

static readonly

GetBattery : byte[]

Builds a packet to get battery status.

public static byte[] GetBattery { get; }

SetTimeNow

static readonly

SetTimeNow : byte[]

Builds a packet to set device time to current system time.

public static byte[] SetTimeNow { get; }

GetTime

static readonly

GetTime : byte[]

Builds a packet to get device time.

public static byte[] GetTime { get; }

Reboot

static readonly

Reboot : byte[]

Builds a packet to reboot the device.

public static byte[] Reboot { get; }

FactoryReset

static readonly

FactoryReset : byte[]

Builds a packet to factory reset the device.

public static byte[] FactoryReset { get; }

Methods

AppStart

static

public static byte[] AppStart(string appName = "MeshCore", byte targetVersion = 3)

Builds an AppStart packet to initialize the companion session.

Parameter Type Description
appName string Application name (up to 32 chars)
targetVersion byte Protocol version (default: 3)

Returns: byte[] - Command packet ready for transmission.


DeviceQuery

static

public static byte[] DeviceQuery(byte targetVersion = 3)

Builds a DeviceQuery packet to get firmware/model info.

Parameter Type Description
targetVersion byte Protocol version (default: 3)

Returns: byte[] - Command packet ready for transmission.


SendMsg

static

public static byte[] SendMsg(
    byte[] pubKeyPrefix,
    string text,
    TextType type = TextType.Plain,
    uint? timestamp = null)

Builds a packet to send a text message to a contact.

Parameter Type Description
pubKeyPrefix byte[] 6-byte public key prefix of recipient
text string Message text
type TextType Message type (Plain, Signed, etc.)
timestamp uint? Optional timestamp (defaults to now)

Returns: byte[] - Command packet ready for transmission.


SendMsgRaw

static

public static byte[] SendMsgRaw(
    byte[] pubKeyPrefix,
    byte[] data,
    TextType type = TextType.Plain,
    uint? timestamp = null)

Builds a packet to send raw bytes as a message.

Parameter Type Description
pubKeyPrefix byte[] 6-byte public key prefix of recipient
data byte[] Raw message data
type TextType Message type
timestamp uint? Optional timestamp (defaults to now)

Returns: byte[] - Command packet ready for transmission.


SendChannelMsg

static

public static byte[] SendChannelMsg(
    byte channelIdx,
    string text,
    TextType type = TextType.Plain,
    uint? timestamp = null)

Builds a packet to send a channel message.

Parameter Type Description
channelIdx byte Channel index (0-7)
text string Message text
type TextType Message type
timestamp uint? Optional timestamp (defaults to now)

Returns: byte[] - Command packet ready for transmission.


GetContacts

static

public static byte[] GetContacts(uint filterFlags = 0)

Builds a packet to retrieve contacts.

Parameter Type Description
filterFlags uint Optional filter flags

Returns: byte[] - Command packet ready for transmission.


UpdateContact

static

public static byte[] UpdateContact(
    byte[] pubKeyPrefix,
    string name,
    ContactType type,
    byte flags = 0)

Builds a packet to add or update a contact.

Parameter Type Description
pubKeyPrefix byte[] 6-byte public key prefix
name string Contact name
type ContactType Contact type
flags byte Optional flags

Returns: byte[] - Command packet ready for transmission.


RemoveContact

static

public static byte[] RemoveContact(byte[] pubKeyPrefix)

Builds a packet to remove a contact.

Parameter Type Description
pubKeyPrefix byte[] 6-byte public key prefix

Returns: byte[] - Command packet ready for transmission.


GetChannel

static

public static byte[] GetChannel(byte channelIdx)

Builds a packet to get channel configuration.

Parameter Type Description
channelIdx byte Channel index (0-7)

Returns: byte[] - Command packet ready for transmission.


SetChannel

static

public static byte[] SetChannel(byte channelIdx, string name, byte[] psk)
public static byte[] SetChannel(byte channelIdx, string name, string psk)

Builds a packet to configure a channel. Two overloads available for PSK as bytes or string.

Parameter Type Description
channelIdx byte Channel index (0-7)
name string Channel name
psk byte[] or string Pre-shared key

Returns: byte[] - Command packet ready for transmission.


SetName

static

public static byte[] SetName(string name)

Builds a packet to set the device name.

Parameter Type Description
name string New device name

Returns: byte[] - Command packet ready for transmission.


SetCoords

static

public static byte[] SetCoords(double lat, double lon)

Builds a packet to set GPS coordinates.

Parameter Type Description
lat double Latitude
lon double Longitude

Returns: byte[] - Command packet ready for transmission.


SetTxPower

static

public static byte[] SetTxPower(sbyte dbm)

Builds a packet to set transmission power.

Parameter Type Description
dbm sbyte Power level in dBm

Returns: byte[] - Command packet ready for transmission.


SetTime

static

public static byte[] SetTime(uint unixTime)

Builds a packet to set device time.

Parameter Type Description
unixTime uint Unix timestamp

Returns: byte[] - Command packet ready for transmission.


Example

using MeshCS;

// Build and send packets manually
byte[] initPacket = PacketBuilder.AppStart("MyApp");
byte[] queryPacket = PacketBuilder.DeviceQuery();
byte[] advertPacket = PacketBuilder.SendAdvert;

// Send a message
byte[] msgPacket = PacketBuilder.SendMsg(
    pubKeyPrefix: new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 },
    text: "Hello!",
    type: TextType.Plain);

// Configure a channel
byte[] channelPacket = PacketBuilder.SetChannel(
    channelIdx: 0,
    name: "General",
    psk: "my-secret-key");

See Also

Clone this wiki locally