![]() |
VOOZH | about |
dotnet add package CrunkA3.Nanoleaf --version 3.0.1
NuGet\Install-Package CrunkA3.Nanoleaf -Version 3.0.1
<PackageReference Include="CrunkA3.Nanoleaf" Version="3.0.1" />
<PackageVersion Include="CrunkA3.Nanoleaf" Version="3.0.1" />Directory.Packages.props
<PackageReference Include="CrunkA3.Nanoleaf" />Project file
paket add CrunkA3.Nanoleaf --version 3.0.1
#r "nuget: CrunkA3.Nanoleaf, 3.0.1"
#:package CrunkA3.Nanoleaf@3.0.1
#addin nuget:?package=CrunkA3.Nanoleaf&version=3.0.1Install as a Cake Addin
#tool nuget:?package=CrunkA3.Nanoleaf&version=3.0.1Install as a Cake Tool
based on (https://github.com/BullFrog13/Nanoleaf-Client)
A .NET Core library for accessing the [RESTful Nanoleaf OpenAPI][1] over HTTP.
This is a convenient way to discover Nanoleaf in local network.
Before running the command make sure Nanoleaf is plugged-in and connected to WiFi.
var nanoleafDiscovery = new NanoleafDiscovery();
var request = new NanoleafDiscoveryRequest
{
ST = SearchTarget.Nanoleaf
};
var discoveredNanoleafs = nanoleafDiscovery.DiscoverNanoleafs(request);
var nanoleaf = discoveredNanoleafs.FirstOrDefault();
A user is authorized to access the OpenAPI if they can demonstrate physical access of Panels. This is achieved by: Holding the on-off button down for 5-7 seconds until the LED starts flashing in a pattern
Run the following code within 30 seconds of activating pairing. The response is a randomly generated auth token.
var token = await nanoleaf.CreateTokenAsync();
You can reuse this token in the following sessions, just make sure to authorize client with it.
Use the token to authorize.
await nanoleaf?.AuthorizeAsync(token);
Provided that you know your local device IP and already have a user token.
var client = new NanoleafClient("<local_device_ip>", "<USER_TOKEN>");
Optionally, you can pass an existing HttpClient to NanoLeafClient if you wish to re-use it.
var httpClient = new HttpClient();
var client = new NanoleafClient("<local_device_ip>", "<USER_TOKEN>", httpClient);
You can also retrieve the hostname from the Nanoleaf Client.
var client = new NanoleafClient("<local_device_ip>");
var hostname = client.HostName;
Disposable
using(var client = new NanoleafClient("<local_device_ip>", "<USER_TOKEN>")
{
// code
}
await nanoleaf.TurnOnAsync();
Thread.Wait(5000);
await nanoleaf.TurnOffAsync();
powerStatus = await nanoleaf.GetPowerStatusAsync();
Includes name, serial number, manufacturer, firmware version, model, state and effects
var info = await nanoleaf.GetInfoAsync();
var brightness = await nanoleaf.GetBrightnessAsync();
var brightness = await nanoleaf.GetBrightnessInfoAsync();
targetBrightness must be from 0 to 100 time is a brightness transition time
await nanoleaf.SetBrightnessAsync(targetBrightness: 100, time: 1000);
await nanoleaf.RaiseBrightnessAsync(20);
await nanoleaf.LowerBrightnessAsync(5);
await nanoleaf.GetLayoutAsync();
await nanoleaf.StartExternalAsync();
Before sending data to your nanoleaf, you must first have authorized to your device. Once authorized, you should call "nanoleaf.StartExternalAsync()";
var client = new NanoleafClient("<local_device_ip>", "<USER_TOKEN>");
await client.StartExternalAsync();
var nanoStream = new NanoleafStreamingClient("<local_device_ip_or_hostname>");
The structure of the data sent to the device depends on the API version. Most devices should use the V2 structure, which is the default setting. If you wish to use V1, specify it in the streaming client's constructor.
var nanoStream = new NanoleafStreamingClient("<local_device_ip_or_hostname>", 1); // Specify version 1
Additionally, if you wish to use an existing UDP client, you can do so in the constructor.
var UdpClient = new UdpClient {Ttl = 5};
UdpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
UdpClient.Client.Blocking = false;
UdpClient.DontFragment = true;
var nanoStream = new NanoleafStreamingClient("<local_device_ip_or_hostname>", 2, UdpClient);
To send color data after initializing a Streaming Client, you first need to know the id's of the panels to address.
Once you have the IDs, create a Dictionary<int, System.Drawing.Color>. Assign the panel ID to the dictionary's key, and the desired color to the corresponding value.
Pass this dictionary to the nanostreaming client with an optional fade time, and repeat as necessary.
// Create client
var client = new NanoleafClient("<local_device_ip>", "<USER_TOKEN>");
// Retrieve our layout
var layout = client.GetLayoutAsync();
// Create a dictionary to pass to the stream
var allRed = new Dictionary<int,Color>();
var allBlack = new Dictionary<int,Color>();
// Create colors
var redColor = Color.FromArgb(255,0,0);
var blackColor = Color.FromArgb(0,0,0);
// Create stream
var nanoStream = new NanoleafStreamingClient("<local_device_ip_or_hostname>", 1); // Specify version 1
// Fill red dict
foreach (var position in layout.PositionData) {
allRed[position.PanelId] = redColor;
}
// Fill black dict
foreach (var position in layout.PositionData) {
allBlack[position.PanelId] = blackColor;
}
// Start streaming
await client.StartExternalAsync();
// Set all panels to red with no delay
await nanoStream.SetColorAsync(allRed);
await Task.Delay(1000);
// Set all panels to black with 500ms fade time
await nanoStream.SetColorAsync(allBlack, 500);
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 is compatible. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.