TTNet.Data 6.0.0-rc.1

This is a prerelease version of TTNet.Data.
There is a newer prerelease version of this package available.
See the version list below for details.
Install-Package TTNet.Data -Version 6.0.0-rc.1
dotnet add package TTNet.Data --version 6.0.0-rc.1
<PackageReference Include="TTNet.Data" Version="6.0.0-rc.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TTNet.Data --version 6.0.0-rc.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: TTNet.Data, 6.0.0-rc.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install TTNet.Data as a Cake Addin
#addin nuget:?package=TTNet.Data&version=6.0.0-rc.1&prerelease

// Install TTNet.Data as a Cake Tool
#tool nuget:?package=TTNet.Data&version=6.0.0-rc.1&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

TTNet.Data

A .NET library for The Things Network Data API

Install

Available at NuGet:

dotnet add package TTNet.Data

Usage

Create an instance:

var app = new App("Your app ID");

Listen to events:

app.Connected += (s, e) => Console.WriteLine("Connected");

app.MessageReceived += (s, e) =>
{
    Console.WriteLine(e.DeviceID);
    foreach (var f in e.Message.PayloadFields.EnumerateObject())
        Console.WriteLine($"\t{f.Name}: {f.Value}");

    // Or you can convert it to your data type
    var myObject = e.Message.PayloadFields.ConvertTo<MyClass>();
};

Connect:

var c = await app.Connect(cluster, port, withTls, username, apiKey);

Example:

var c = await app.Connect("eu1.cloud.thethings.network", 8883, true, "username@ttn", "XXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

You can add or remove events wether connected or disconnected.

Publish messages:

// Raw payload
await app.Publish(deviceID, new byte[] { 0x10, 0xF1 }, port);
// JSON payload
await app.Publish(deviceID, myObject, port);

Managed

Managed mode is also available. The client is started once and will mantain the connection automatically including reconnecting.

Create a managed instance:

var app = new ManagedApp("Your app ID");

Use Start/Stop instead of Connect/Disconnect:

await app.Start(cluster, port, withTls, username, apiKey, autoReconnectDelay);

Publish messages:

// Raw payload
await app.Publish(deviceID, new byte[] { 0x10, 0xF1 }, port);
// JSON payload
await app.Publish(deviceID, myObject, port);

JSON Payload

Only properties are converted from and to JSON, and they can be private.

The property name can be overriden with JsonPropertyName attribute.

If JsonIgnore attribute is set, the property will be ignored.

Example:

class MyClass
{
    public bool MyBoolean { get; private set; }

    [JsonPropertyName("my_int")]
    public int MyInt { get; private set; }

    [JsonIgnore]
    public string MyString { get; set; }
}

Result JSON:

{"MyBoolean":false,"my_int":0}

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
6.0.0-rc.2 955 11/24/2021
6.0.0-rc.1 48 10/15/2021
5.0.1 563 12/15/2020
5.0.0 165 11/19/2020
3.3.0 187 10/1/2020
3.2.1 255 6/17/2020
3.2.1-rc.1 175 6/16/2020
3.2.0 210 5/19/2020
3.2.0-rc.2 138 5/18/2020
3.2.0-rc.1 199 5/17/2020
3.1.0 229 5/16/2020
3.1.0-rc.2 145 5/16/2020
3.1.0-rc.1 141 5/15/2020
3.0.0 310 1/3/2020