https://github.com/alandoherty/devicepilot-api-net
A .NET API client for the Device Pilot analytics system
https://github.com/alandoherty/devicepilot-api-net
api-client csharp devicepilot iot netframework45 netstandard13
Last synced: about 1 year ago
JSON representation
A .NET API client for the Device Pilot analytics system
- Host: GitHub
- URL: https://github.com/alandoherty/devicepilot-api-net
- Owner: alandoherty
- License: mit
- Created: 2019-05-30T09:52:46.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T05:37:46.000Z (over 3 years ago)
- Last Synced: 2023-08-06T13:11:29.427Z (over 2 years ago)
- Topics: api-client, csharp, devicepilot, iot, netframework45, netstandard13
- Language: C#
- Homepage: https://devicepilot.com
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://raw.githubusercontent.com/alandoherty/devicepilot-api-net/master/LICENSE)
[](https://github.com/alandoherty/devicepilot-api-net/issues)
[](https://github.com/alandoherty/devicepilot-api-net/stargazers)
[](https://github.com/alandoherty/devicepilot-api-net/network)
[](https://www.nuget.org/packages/DevicePilot.Api/)
# devicepilot-api
A .NET API client for the Device Pilot IoT analytics platform. Open permissive MIT license and requires a minimum of .NET Standard 1.3.
## Getting Started
[](https://www.nuget.org/packages/DevicePilot.Api/)
You can install the package using either the CLI:
```
dotnet add package DevicePilot.Api
```
or from the NuGet package manager:
```
Install-Package DevicePilot.Api
```
## Usage
Create an instance of the API client and configure your authentication token, you can find this on the API keys page of the platform.
```csharp
ApiClient client = new ApiClient(Environment.GetEnvironmentVariable("DEVICEPILOT_TOKEN"));
```
The client will automatically retry each request 3 times if a transient error occurs.
### Ingesting
You can start ingesting data immediately after creating the client, you can ingest either a single device update or as many as you want. If you ingest more than one device the batch API will be used, if you pass more than 500 devices the client will split up the request automatically.
```csharp
var devices = new DeviceData[] {
new DeviceData() {
Id = "switch1",
Properties = new Dictionary() {
{ "name", "Switch 1" },
{ "isOn", true },
{ "longitude", 53.7005d },
{ "latitude", 2.3015d }
}
},
new DeviceData() {
Id = "switch2",
Properties = new Dictionary() {
{ "name", "Switch 2" },
{ "isOn", false },
{ "longitude", 53.7005d },
{ "latitude", 2.3015d }
}
}
};
await client.BulkIngestAsync(devices);
```
### Mapped types
Optionally you can use .NET objects to represent your device data structure. You can use either `client.IngestAsync` or `client.BulkIngestAsync`.
```csharp
class MyDevice
{
[DeviceId]
public string ID { get; set; }
[DeviceProperty("online")]
public bool Online { get; set; }
[DeviceProperty]
public double Temperature { get; set; }
[DeviceTimestamp]
public DateTime? Timestamp { get; set; }
}
```
```csharp
await client.IngestAsync(new MyDevice() {
ID = "temp1",
Online = true,
Temperature = 16.21d
});
```
## Contributing
Any pull requests or bug reports are welcome, please try and keep to the existing style conventions and comment any additions.