Skip to content

Getting Started

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

Getting Started

This guide will help you get up and running with MeshCS in minutes.

Installation

Install MeshCS via NuGet:

dotnet add package MeshCS
Install-Package MeshCS
<PackageReference Include="MeshCS" Version="1.0.0" />

Basic Usage

Connecting to a Radio

using MeshCS;

// Create a radio instance
var radio = new MeshRadio("COM3");

// Open the connection
await radio.OpenAsync();

// Your code here...

// Close when done
radio.Close();

Subscribing to Events

MeshCS uses the standard .NET event pattern:

radio.MessageReceived += (sender, msg) =>
{
    Console.WriteLine($"From: {msg.PubKeyPrefix}");
    Console.WriteLine($"Text: {msg.Text}");
};

radio.ContactUpdated += (sender, contact) =>
{
    Console.WriteLine($"Contact: {contact.PublicName}");
};

radio.ErrorOccurred += (sender, error) =>
{
    Console.WriteLine($"Error: {error.Message}");
};

Sending Messages

// Send to a specific contact by their public key prefix
await radio.SendTextMessageAsync(recipientId, "Hello!");

// Send with optional flags
await radio.SendTextMessageAsync(recipientId, "Important!", 
    PacketBuilder.PATH_TYPE_FLOOD);

Getting Contacts

var contacts = await radio.GetContactsAsync();
foreach (var contact in contacts)
{
    Console.WriteLine($"{contact.PublicName} - Last seen: {contact.LastSeen}");
}

Getting Device Info

var info = await radio.GetSelfInfoAsync();
Console.WriteLine($"Name: {info.Name}");
Console.WriteLine($"Battery: {info.BatteryPercent}%");

Architecture

MeshCS has three abstraction levels:

Class Purpose
MeshRadio High-level async API with events
PacketBuilder Build binary command packets
PacketParser Parse binary response packets
CommandCodes Protocol constants

Choose the level that fits your needs:

  • Most apps: Use MeshRadio for the simplest experience
  • Custom protocols: Use PacketBuilder/PacketParser directly
  • Low-level access: Use CommandCodes for raw values

Next Steps

  • Events - Complete event documentation
  • Examples - More code samples
  • API Reference - Full API documentation

Clone this wiki locally