-
-
Notifications
You must be signed in to change notification settings - Fork 1
API Reference
Complete API documentation for the MeshCS library.
| Class | Description |
|---|---|
| MeshRadio | High-level async API for radio communication |
| PacketBuilder | Static methods to build command packets |
| PacketParser | Static methods to parse response packets |
| SelfInfo | Device self-information |
| DeviceInfo | Firmware and model information |
| Contact | Contact entry from device |
| Channel | Channel configuration |
| DirectMessage | Received direct message |
| ChannelMessage | Received channel message |
| Advert | Received advertisement |
| BatteryInfo | Battery status information |
| ScanResult | Result of port scanning |
High-level async API for communicating with a MeshCore companion radio.
public static string[] GetAvailablePorts()Returns all available serial port names on the system.
public static async Task<List<ScanResult>> ScanAllPortsAsync(
int timeoutMs = 2000,
int baudRate = 115200,
bool verbose = false,
CancellationToken ct = default)Scans all serial ports for MeshCore devices.
public static async Task<ScanResult> ScanPortAsync(
string portName,
int timeoutMs = 2000,
int baudRate = 115200,
bool verbose = false,
CancellationToken ct = default)Scans a specific serial port for a MeshCore device.
public static async Task<ScanResult?> FindFirstDeviceAsync(
int timeoutMs = 2000,
int baudRate = 115200,
bool verbose = false,
CancellationToken ct = default)Finds the first available MeshCore device.
public static async Task<MeshRadio?> ConnectFirstAsync(
string appName = "MeshCore",
int timeoutMs = 2000,
int baudRate = 115200,
bool verbose = false,
CancellationToken ct = default)Creates and connects to the first available device.
public MeshRadio(string portName, int baudRate = 115200)Creates a new MeshRadio instance for the specified port.
| Property | Type | Description |
|---|---|---|
Self |
SelfInfo? |
Device self-info (populated after Connect) |
Device |
DeviceInfo? |
Device info (populated after DeviceQuery) |
IsConnected |
bool |
Whether the serial port is open |
PendingMessageCount |
int |
Number of queued direct messages |
PendingChannelMessageCount |
int |
Number of queued channel messages |
VerboseLogging |
bool |
Enable console logging |
public async Task ConnectAsync(string appName = "MeshCore", CancellationToken ct = default)Opens the connection and initializes the companion session.
public void Disconnect()Closes the serial connection.
public void Dispose()Releases all resources.
public async Task<DeviceInfo?> DeviceQueryAsync(CancellationToken ct = default)Gets device firmware and model information.
public async Task<DateTime?> GetTimeAsync(CancellationToken ct = default)Gets the device's current time.
public async Task<bool> SetTimeAsync(CancellationToken ct = default)Syncs device time to system time.
public async Task<BatteryInfo?> GetBatteryAsync(CancellationToken ct = default)Gets battery voltage and percentage.
public async Task<bool> SetNameAsync(string name, CancellationToken ct = default)Sets the device's advertised name.
public async Task<bool> SetCoordsAsync(double latitude, double longitude, CancellationToken ct = default)Sets the device's GPS coordinates.
public async Task<bool> SetTxPowerAsync(sbyte powerDbm, CancellationToken ct = default)Sets transmit power in dBm.
public async Task<bool> SendAdvertAsync(CancellationToken ct = default)Broadcasts a self-advertisement.
public async Task RebootAsync(CancellationToken ct = default)Reboots the device.
public async Task FactoryResetAsync(CancellationToken ct = default)Factory resets the device (erases all data).
public async Task<bool> SendMessageAsync(
byte[] recipientPubKeyPrefix,
string text,
TextType textType = TextType.Plain,
CancellationToken ct = default)Sends a direct message to a contact.
public async Task<bool> SendMessageRawAsync(
byte[] recipientPubKeyPrefix,
byte[] payload,
TextType textType = TextType.CliData,
CancellationToken ct = default)Sends a direct message with raw binary payload.
public async Task<bool> SendChannelMessageAsync(
byte channelIndex,
string text,
CancellationToken ct = default)Sends a message to a channel.
public async Task<DirectMessage?> GetNextMessageAsync(CancellationToken ct = default)Fetches the next queued message from the device.
public bool TryDequeueMessage(out DirectMessage? message)Dequeues a pushed direct message from the local queue.
public bool TryDequeueChannelMessage(out ChannelMessage? message)Dequeues a pushed channel message from the local queue.
public async Task<List<Contact>> GetContactsAsync(uint since = 0, CancellationToken ct = default)Gets all contacts from the device.
public async Task<bool> AddContactAsync(
byte[] publicKey,
string name,
ContactType type = ContactType.Chat,
CancellationToken ct = default)Adds or updates a contact.
public async Task<bool> RemoveContactAsync(byte[] publicKeyPrefix, CancellationToken ct = default)Removes a contact.
public async Task<Channel?> GetChannelAsync(byte channelIndex, CancellationToken ct = default)Gets channel configuration.
public async Task<bool> SetChannelAsync(
byte channelIndex,
string name,
byte[] secret,
CancellationToken ct = default)Configures a channel.
See Events for complete event documentation.
Static class for building MeshCore command packets.
| Method | Description |
|---|---|
AppStart(appName, targetVersion) |
Initialize companion session |
DeviceQuery(targetVersion) |
Query device info |
SendMsg(recipient, text, textType, timestamp) |
Build DM packet |
SendMsgRaw(recipient, payload, textType, timestamp) |
Build raw DM packet |
SendChannelMsg(channelIndex, text, textType, timestamp) |
Build channel message |
GetMsg() |
Fetch next message |
GetContacts(since) |
Request contacts |
UpdateContact(publicKey, name, type, flags) |
Add/update contact |
RemoveContact(publicKeyPrefix) |
Remove contact |
GetChannel(channelIndex) |
Get channel config |
SetChannel(channelIndex, name, secret) |
Set channel config |
GetTime() |
Get device time |
SetTime(unixTime) |
Set device time |
SetTimeNow() |
Set to current time |
GetBattery() |
Get battery info |
SendAdvert() |
Broadcast advertisement |
SetName(name) |
Set device name |
SetCoords(latitude, longitude) |
Set GPS coordinates |
SetTxPower(powerDbm) |
Set TX power |
Reboot() |
Reboot device |
FactoryReset() |
Factory reset |
Static class for parsing MeshCore response packets.
| Method | Description |
|---|---|
GetCode(packet) |
Get response code |
GetBaseCode(packet) |
Get base code (strips push bit) |
IsPush(packet) |
Check if push notification |
ParseSelfInfo(packet) |
Parse SelfInfo response |
ParseDeviceInfo(packet) |
Parse DeviceInfo response |
ParseContact(packet) |
Parse Contact response |
ParseChannelInfo(packet) |
Parse Channel response |
ParseDirectMessage(packet) |
Parse DM (V2 or V3) |
ParseChannelMessage(packet) |
Parse channel message |
ParseAdvert(packet) |
Parse advertisement |
ParseTime(packet) |
Parse time response |
ParseBatteryInfo(packet) |
Parse battery response |
IsOk(packet) |
Check for OK response |
IsError(packet) |
Check for error response |
IsSent(packet) |
Check for sent acknowledgment |
IsNoMoreMessages(packet) |
Check for empty queue |
IsMessageWaiting(packet) |
Check for message waiting push |
Device self-information returned after connection.
| Property | Type | Description |
|---|---|---|
PublicKey |
byte[32] |
Device public key |
Name |
string |
Advertised name |
Latitude |
int |
Latitude (millionths of degrees) |
Longitude |
int |
Longitude (millionths of degrees) |
Frequency |
uint |
Radio frequency in Hz |
Bandwidth |
byte |
LoRa bandwidth (0-9) |
SpreadingFactor |
byte |
LoRa SF (6-12) |
CodingRate |
byte |
LoRa CR (5-8) |
TxPower |
sbyte |
TX power in dBm |
PublicKeyHex |
string |
Full public key as hex |
PublicKeyPrefix |
string |
First 6 bytes as hex |
Firmware and model information.
| Property | Type | Description |
|---|---|---|
FirmwareVersion |
string |
Firmware version string |
Model |
string |
Device model/type |
MaxPacketSize |
ushort |
Max packet size |
ProtocolVersion |
byte |
Protocol version |
Contact entry from the device.
| Property | Type | Description |
|---|---|---|
PublicKey |
byte[32] |
Contact's public key |
Type |
ContactType |
Chat, Room, or Repeater |
Flags |
byte |
Contact flags |
PathLen |
byte |
Path length |
Path |
byte[] |
Routing path |
Name |
string |
Display name |
LastSeen |
uint |
Unix timestamp |
PublicKeyHex |
string |
Full key as hex |
PublicKeyPrefix |
string |
First 6 bytes as hex |
Channel configuration.
| Property | Type | Description |
|---|---|---|
Index |
byte |
Channel index (0-7) |
Name |
string |
Channel name |
Secret |
byte[16] |
Channel secret |
ForwardEnabled |
bool |
Forward messages |
SecretHex |
string |
Secret as hex |
Received direct message.
| Property | Type | Description |
|---|---|---|
SenderPrefix |
byte[6] |
Sender's key prefix |
TextType |
TextType |
Plain or CliData |
PathLen |
byte |
Hop count |
Timestamp |
uint |
Sender's timestamp |
Snr |
sbyte |
Signal-to-noise (V3) |
Payload |
byte[] |
Raw payload |
SenderName |
string |
Sender name (V3) |
SenderPrefixHex |
string |
Prefix as hex |
Text |
string |
Payload as UTF-8 |
IsV3 |
bool |
V3 format flag |
Received channel message.
| Property | Type | Description |
|---|---|---|
ChannelIndex |
byte |
Channel index |
TextType |
TextType |
Plain or CliData |
PathLen |
byte |
Hop count |
Timestamp |
uint |
Sender's timestamp |
Snr |
sbyte |
Signal-to-noise (V3) |
Payload |
byte[] |
Raw payload |
SenderName |
string |
Sender name (V3) |
Text |
string |
Payload as UTF-8 |
IsV3 |
bool |
V3 format flag |
Received advertisement from the mesh.
| Property | Type | Description |
|---|---|---|
PublicKey |
byte[32] |
Sender's public key |
Name |
string |
Advertised name |
Latitude |
int |
Latitude (millionths) |
Longitude |
int |
Longitude (millionths) |
PathLen |
byte |
Hop count |
Snr |
sbyte |
Signal-to-noise |
PublicKeyHex |
string |
Key as hex |
Battery status information.
| Property | Type | Description |
|---|---|---|
VoltageMillivolts |
ushort |
Battery voltage |
Percentage |
byte |
0-100% |
IsCharging |
bool |
Charging status |
FreeStorageBytes |
uint |
Free storage |
Port scan result.
| Property | Type | Description |
|---|---|---|
PortName |
string |
Port name |
Found |
bool |
Device found |
Self |
SelfInfo? |
Device info |
Device |
DeviceInfo? |
Firmware info |
Error |
string? |
Error message |
public enum TextType : byte
{
Plain = 0x00, // Plain text
CliData = 0x01 // CLI/binary data
}public enum ContactType : byte
{
Room = 0x00, // Group/room
Chat = 0x01, // Direct message
Repeater = 0x02 // Repeater node
}MeshCS © 2026 Litruv | MIT License
MeshCS Documentation
Classes
Models
Enums
Links