Thingsboard.Net
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.
Install / Use
/learn @nepton/Thingsboard.NetREADME
Thingsboard.Net
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 | |
|
| Thingsboard.Net.Flurl |
|
|
| Thingsboard.Net.Flurl.DependencyInjection |
|
|
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 = "tenant@thingsboard.org",
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:
Hello tenant@thingsboard.org
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 = "tenant@thingsboard.org";
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("newuser@thingsboard.com", "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
Related Skills
node-connect
346.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
346.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
346.8kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
