Code Monkey home page Code Monkey logo

thingsboard.net's Introduction

Thingsboard.Net

Build status CodeQL GitHub license

Thingsboard.NET is a .NET client library for Thingsboard IoT Platform. It is a .NET Standard 2.0 library, so it can be used in .NET Core and .NET Framework applications.

All client API are tested in Thingsboard v3.4.x

Nuget packages

Name Version Downloads
Thingsboard.Net.Abstractions nuget stats
Thingsboard.Net.Flurl nuget stats
Thingsboard.Net.Flurl.DependencyInjection nuget stats

Usage

Creating a client and trying to invoke getCurrentUser method:

Basic usage

Install the NuGet package Thingsboard.Net.Flurl.

PM> Install-Package Thingsboard.NET.Flurl

Then put following code into your project

// Initial factory
var factory = new FlurlTbClientFactory
{
    Options = new ThingsboardNetFlurlOptions()
    {
        BaseUrl  = "http://localhost:8080",
        Username = "[email protected]",
        Password = "tenant",
    }
};

// Get the client
var authClient = factory.CreateAuthClient();
var userInfo = await authClient.GetCurrentUserAsync();
Console.WriteLine($"Hello {userInfo.Email}");

You will get the output from console:

Integration to ASP.NET Core

You can use the Thingsboard.NET.Flurl library in ASP.NET Core applications. Te dependency injection mode is supported.

First, add the Thingsboard.NET.Flurl.DependencyInjection library to your project:

PM> Install-Package Thingsboard.NET.Flurl.DependencyInjection

Then, register the Thingsboard.NET.Flurl services in the ConfigureServices method of Startup.cs:

// add package "Thingsboard.Net.Flurl.DependencyInjection" Version="3.4.1.1"
serviceBuilder.AddThingsboardNet(options =>
{
    options.Username = "[email protected]";
    options.Password = "tenant";
    options.BaseUrl  = "http://localhost:8080";
});

Then you can inject the client factory in your controllers:

public class HomeController : Controller
{
    private readonly ITbAuthClient _authClient;

    public HomeController(ITbAuthClient authClient)
    {
        _authClient = authClient;
    }

    public async Task<IActionResult> Index()
    {
        var userInfo = await _authClient.GetCurrentUserAsync();
        return View(userInfo);
    }
}

Customization options

You can customize the client options before invoke RPC methods:

public class HomeController : Controller
{
    private readonly ITbAuthClient _authClient;

    public HomeController(ITbAuthClient authClient)
    {
        _authClient = authClient;
    }

    public async Task<IActionResult> Index()
    {
        var userInfo = await auth
            .WithCredentials("[email protected]", "your-password")
            .WithBaseUrl("https://tb-server")
            .GetCurrentUserAsync();
        return View(userInfo);
    }
}

Thanks

  • Thanks to Flurl for the great HTTP library.
  • Thanks to Thingsboard for the great IoT platform.
  • Thanks to Polly for the great resilience and transient-fault-handling library.

Final

Leave a comment on GitHub if you have any questions or suggestions.

Turn on the star if you like this project.

License

This project is licensed under the MIT License

thingsboard.net's People

Contributors

nepton avatar thomasprioul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

thingsboard.net's Issues

saveDevice with additionalInfo

Hi,

i've testing around with your project. I stumbled only about one issue. I could not save a device with additionalInfos.
I think there is no way i could add following to the save process.
"additionalInfo": { "gateway": true }

In the thingsboard api docu its and the end of the example thinkboardLink

Hope you could help.

AssetProfile API missing

Is your feature request related to a problem? Please describe.
There isn't a built-in device profile API client, this API exists in TB 3.4.4.

Describe the solution you'd like
Add a method to FlurlTbClientFactory to access the assetprofile client.

Describe alternatives you've considered
Manually using a client for now.

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.