.NET SDK for AnyButton

Install the SDK (NuGet)

Add our public static NuGet feed, then install the package. No login required.

CLI (recommended)

# Add the AnyButton nuget feed
 dotnet nuget add source "https://anybutton.me/nuget/index.json" --name "AnyButton"

# Install the SDK into your project
 dotnet add package anybutton.me.sdk --version 1.0.0

NuGet.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="AnyButton" value="https://anybutton.me/nuget/index.json" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>

Place this NuGet.config at your solution root (or add the source in your global config).

Rider / Visual Studio

Rider

Add Source

  1. Open SettingsNuGetSources.
  2. Click +, set URL to https://anybutton.me/nuget/index.json.
  3. Leave User/Password blank → click OK.
Visual Studio

Add Source

  1. Open ToolsNuGet Package ManagerPackage Sources.
  2. Click +, set Name to AnyButton and Source to https://anybutton.me/nuget/index.json.
  3. Click Update (or OK) to save.

Search for anybutton.me.sdk and install the latest version.

Verify

using AnyButton;

var client = new AnyButtonClient();
await client.StartAsync();
await client.GetStatusAsync();

If a login dialog appears, ensure the URL ends with /index.json and the folder is not password-protected on your host.

Quick Start (.NET)

  1. Install the SDK package (local or your NuGet feed).
  2. Create a ButtonClient with your ISerialTransport.
  3. Handle connection, button, and Wi-Fi state changes.
  4. Send commands using client helper methods (see examples below).
// Install
// dotnet add package AnyButton

using AnyButton;

// 1) Client
AnyButtonClient client = new AnyButtonClient();

// 2) Subscribe
client.ConnectionStateChanged += st => Console.WriteLine($"Conn: {st}");
client.ButtonStateChanged     += st => Console.WriteLine($"Button: {st}");
client.WifiStateChanged       += st => Console.WriteLine($"WiFi: {st}");

// 3) Start
await client.StartAsync();

// 4) Ask device for current status snapshot
await client.GetStatusAsync();

// ...later
await client.StopAsync();

using AnyButton;

AnyButtonClient client = new AnyButtonClient();
client.ButtonStateChanged += s => Console.WriteLine($"Button: {s.ButtonState}");
await client.StartAsync();
await client.GetStatusAsync();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
await client.StopAsync();
      

Tip: the client auto-reconnects. You just react to events.

Event Model (C#)

The SDK raises focused events you can subscribe to, but each event payload is the complete, strongly-typed DeviceEventState. Subscribe only to what you need; you still receive the whole snapshot.

Granular C# Events

The SDK raises simple, focused events for each area of the device. Subscribe only to what you need; each event carries the full snapshot.

// Event surface of the client
public class AnyButtonClient
{
    public event Action ConnectionStateChanged;

    public event Action ButtonStateChanged;
    public event Action LedChanged;
    public event Action BuzzerChanged;
    public event Action AutoOffChanged;
    public event Action InformationChanged;
    public event Action WifiStateChanged;
}
  • Focused: each event carries exactly the data you care about.
  • Efficient: events only fire when that area actually changes.
  • Predictable: each event includes the full device snapshot, so you can update UI or store it as‑is.

DeviceEventState Schema

This is the strongly-typed model the SDK raises through events. Properties are grouped by area for quick reference.

Top‑level Properties

PropertyTypeDescription
ButtonState ButtonStateEnum Current button logic state.
Buzzer BuzzerState Enabled flag plus tone/duty settings.
Information DeviceInformation Identifier and firmware version.
Led LedState LED on/off, invert flag, and pattern number.
AutoOff AutoOffState Whether auto‑off is enabled and its timeout.
Wifi WifiState Wi‑Fi SSID (if any) and connection state.

Nested Types

BuzzerState

PropertyTypeDescription
IsEnabledboolBuzzer mirrors LED activity when enabled.
HertzintCurrent tone frequency.
DutyPercentintOutput duty cycle percentage.

DeviceInformation

PropertyTypeDescription
Idstring?User‑defined identifier.
Firmwarestring?Firmware version string.

LedState

PropertyTypeDescription
IsEnabledboolLED output globally enabled/disabled.
IsInvertedboolInvert behavior to show patterns while OFF.
PatternintCurrent pattern index (0–10).

AutoOffState

PropertyTypeDescription
IsEnabledboolTrue when auto‑off behavior is enabled.
TimeInSecondsintTimeout before auto‑off (0 disables).

WifiState

PropertyTypeDescription
Namestring?SSID of the current network (if connected).
StateWifiConnectionStateEnumUnsupported, Disconnected, Reconnecting, Connected, or Error.

Changing Configuration

// Toggle logical state
await client.TurnOnAsync();           // or await client.TurnOffAsync();  await client.ToggleAsync();

// LED / buzzer
await client.SetLedPatternAsync(10);  // 0..10
await client.EnableBuzzerAsync();     // or await client.DisableBuzzerAsync();

// Invert mode
await client.SetInvertAsync(true);    // or await client.SetInvertAsync(false);

// Auto-off (seconds; 0 disables)
await client.SetAutoOffAsync(300);

// Set identifier
await client.SetIdentifierAsync("Studio Button");

Wi‑Fi Basics

IReadOnlyList<string> ssids = await client.ScanWifiAsync();
await client.ConnectWifiAsync("MyWifi", "super-secret");
await client.ForgetWifiAsync();