Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nepton/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.
https://github.com/nepton/Thingsboard.Net
csharp dotnetcore thingsboard
Last synced: 3 months ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/nepton/Thingsboard.Net
- Owner: nepton
- License: mit
- Created: 2022-10-17T01:53:00.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-02-23T07:12:31.000Z (9 months ago)
- Last Synced: 2024-04-27T04:21:16.964Z (7 months ago)
- Topics: csharp, dotnetcore, thingsboard
- Language: C#
- Homepage:
- Size: 406 KB
- Stars: 11
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-thingsboard - Thingsboard.NET - .NET client library for Thingsboard IoT Platform (SDKs and REST clients)
README
# Thingsboard.Net
[![Build status](https://ci.appveyor.com/api/projects/status/evbtetf22sxxrph7?svg=true)](https://ci.appveyor.com/project/nepton/thingsboard-net)
[![CodeQL](https://github.com/nepton/Thingsboard.Net/actions/workflows/codeql.yml/badge.svg)](https://github.com/nepton/Thingsboard.Net/actions/workflows/codeql.yml)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nepton/Thingsboard.Net/blob/master/LICENSE)Thingsboard.NET is a .NET client library for [Thingsboard](https://github.com/thingsboard/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](https://img.shields.io/nuget/v/Thingsboard.Net.Abstractions.svg)](https://www.nuget.org/packages/Thingsboard.Net.Abstractions/) | [![stats](https://img.shields.io/nuget/dt/Thingsboard.Net.Abstractions.svg)](https://www.nuget.org/packages/Thingsboard.Net.Abstractions/) |
| Thingsboard.Net.Flurl | [![nuget](https://img.shields.io/nuget/v/Thingsboard.Net.Flurl.svg)](https://www.nuget.org/packages/Thingsboard.Net.Flurl/) | [![stats](https://img.shields.io/nuget/dt/Thingsboard.Net.Flurl.svg)](https://www.nuget.org/packages/Thingsboard.Net.Flurl/) |
| Thingsboard.Net.Flurl.DependencyInjection | [![nuget](https://img.shields.io/nuget/v/Thingsboard.Net.Flurl.DependencyInjection.svg)](https://www.nuget.org/packages/Thingsboard.Net.Flurl.DependencyInjection/) | [![stats](https://img.shields.io/nuget/dt/Thingsboard.Net.Flurl.DependencyInjection.svg)](https://www.nuget.org/packages/Thingsboard.Net.Flurl.DependencyInjection/) |## Usage
Creating a client and trying to invoke getCurrentUser method:### Basic usage
Install the NuGet package [Thingsboard.Net.Flurl](https://www.nuget.org/packages/Thingsboard.NET.Flurl/).
```
PM> Install-Package Thingsboard.NET.Flurl
```Then put following code into your project
```csharp
// 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:
```
Hello [email protected]
```### 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:
```csharp
// 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:
```csharp
public class HomeController : Controller
{
private readonly ITbAuthClient _authClient;public HomeController(ITbAuthClient authClient)
{
_authClient = authClient;
}public async Task Index()
{
var userInfo = await _authClient.GetCurrentUserAsync();
return View(userInfo);
}
}
```### Customization options
You can customize the client options before invoke RPC methods:```csharp
public class HomeController : Controller
{
private readonly ITbAuthClient _authClient;public HomeController(ITbAuthClient authClient)
{
_authClient = authClient;
}public async Task Index()
{
var userInfo = await auth
.WithCredentials("[email protected]", "your-password")
.WithBaseUrl("https://tb-server")
.GetCurrentUserAsync();
return View(userInfo);
}
}
```
## Thanks
* Thanks to [Flurl](https://flurl.dev/) for the great HTTP library.
* Thanks to [Thingsboard](https://thingsboard.io/) for the great IoT platform.
* Thanks to [Polly](https://github.com/App-vNext/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