AllThingsTalk 1.0.0

dotnet add package AllThingsTalk --version 1.0.0
NuGet\Install-Package AllThingsTalk -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AllThingsTalk" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AllThingsTalk --version 1.0.0
#r "nuget: AllThingsTalk, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AllThingsTalk as a Cake Addin
#addin nuget:?package=AllThingsTalk&version=1.0.0

// Install AllThingsTalk as a Cake Tool
#tool nuget:?package=AllThingsTalk&version=1.0.0

C-Sharp-SDK

AllThingsTalk C# SDK provides C# APIs to manage and implement AllThingsTalk devices.

Installation

Download SDK and open in Visual Studio. Build the project and include built AllThingsTalk.dll in your project. Add dependencies.

Dependencies

MQTTnet 2.8.2 https://github.com/chkr1011/MQTTnet

Newtonsoft.Json 11.0.2 https://www.newtonsoft.com/json

Quickstart

Create an account in AllThingsTalk Maker, and create a device. All examples require DeviceID and DeviceToken, which can be found under Device Settings.

using AllThingsTalk;
using System.Threading;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var client = new Client("<DeviceToken>");
            var counterDevice = client.AttachDeviceAsync("<DeviceId>").Result;
            var counter = counterDevice.CreateSensor<int>("Counter");
            Thread.Sleep(2000);
            
            for (var i = 0; i < 10; ++i)
            {
                counter.PublishState(i);
                Thread.Sleep(2000);
            }
        }
    }
}

HowTo

Initializing a client and a device

To manage a device, you must obtain a DeviceID (which is an unique device identifier within AllThingsTalk Maker) and DeviceToken (which this SDK uses to obtain access to APIs), both of which can be found on Device Settings page within AllThingsTalk Maker.

var client = new Client("<DeviceToken>");
var device = client.AttachDeviceAsync("<DeviceId>").Result;

Creating assets

Assets are added to initialized device and if they don't exist in maker platform, they are also created there. There are 3 types of assets: sensor, actuator and virtual.

Creating a sensor

Sensor is added by:

var sensor = device.CreateSensor<int>("<sensorName>");
Thread.Sleep(2000);

where int defines the data type and sensorName is the identifier that has to be the same as the one used in maker, if you want to attach to an existing sensor. Be sure to add Thread.Sleep(2000) so there is enough time for sensor to be created before we send any data.

Sending sensor data

Data is sent through:

temperature.PublishState(23);

which will update temperature asset state in Maker with value 23. If we send the wrong type an exception will be thrown.

Creating an actuator

This is a complete, simplest code for adding an actuator.

namespace ConsoleActuator
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var client = new Client("<DeviceToken>");
            var counterDevice = client.AttachDeviceAsync("<DeviceId>").Result;
            var button = counterDevice.CreateActuator<bool>("Button");
            button.OnCommand += OnCommandHandler;
        }

        private static void OnCommandHandler(object sender, Asset asset)
        {
            Console.WriteLine(asset.State.State.Value);
        }
    }
}

This code will create an asset as actuator (if it is not already there), with name "Button" and type boolean, under Device we used to initialize the code. In Maker, we create a pinboard with this asset and can send boolean value to the app, which will be displayed in the console.

Attach event handler to an actuator
button.OnCommand += OnCommandHandler;

Method you attach to an actuator will receive Object sender, which in this case is the Device that holds the Asset and Asset itself, from which you can retrieve State, which holds the Value, sent from Maker.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.0.0 837 10/12/2018