.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
Add Source
- Open Settings → NuGet → Sources.
- Click +, set URL to
https://anybutton.me/nuget/index.json. - Leave User/Password blank → click OK.
Add Source
- Open Tools → NuGet Package Manager → Package Sources.
- Click +, set Name to AnyButton and Source to
https://anybutton.me/nuget/index.json. - 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)
- Install the SDK package (local or your NuGet feed).
- Create a
ButtonClientwith yourISerialTransport. - Handle connection, button, and Wi-Fi state changes.
- 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
| Property | Type | Description |
|---|---|---|
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
| Property | Type | Description |
|---|---|---|
IsEnabled | bool | Buzzer mirrors LED activity when enabled. |
Hertz | int | Current tone frequency. |
DutyPercent | int | Output duty cycle percentage. |
DeviceInformation
| Property | Type | Description |
|---|---|---|
Id | string? | User‑defined identifier. |
Firmware | string? | Firmware version string. |
LedState
| Property | Type | Description |
|---|---|---|
IsEnabled | bool | LED output globally enabled/disabled. |
IsInverted | bool | Invert behavior to show patterns while OFF. |
Pattern | int | Current pattern index (0–10). |
AutoOffState
| Property | Type | Description |
|---|---|---|
IsEnabled | bool | True when auto‑off behavior is enabled. |
TimeInSeconds | int | Timeout before auto‑off (0 disables). |
WifiState
| Property | Type | Description |
|---|---|---|
Name | string? | SSID of the current network (if connected). |
State | WifiConnectionStateEnum | Unsupported, 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();