Skip to content

Commit cffdce6

Browse files
committed
Initial release
1 parent 09f66e0 commit cffdce6

13 files changed

Lines changed: 1079 additions & 2 deletions

DevicePilot.Api.sln

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.28803.452
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevicePilot.Api", "src\DevicePilot.Api\DevicePilot.Api.csproj", "{0228BF73-A7D8-4134-8696-1FA90DCA9BF7}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{3041DF39-EB80-4F02-89C5-8598A818B251}"
9+
EndProject
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example.PostData", "samples\Example.PostData\Example.PostData.csproj", "{FECE7ED0-FACD-421F-BED0-684339F11B98}"
11+
EndProject
12+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{BFFE4CD8-B17A-47E0-909E-4544DE97A3A7}"
13+
ProjectSection(SolutionItems) = preProject
14+
LICENSE = LICENSE
15+
README.md = README.md
16+
EndProjectSection
17+
EndProject
18+
Global
19+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
20+
Debug|Any CPU = Debug|Any CPU
21+
Release|Any CPU = Release|Any CPU
22+
EndGlobalSection
23+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
24+
{0228BF73-A7D8-4134-8696-1FA90DCA9BF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25+
{0228BF73-A7D8-4134-8696-1FA90DCA9BF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
26+
{0228BF73-A7D8-4134-8696-1FA90DCA9BF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
27+
{0228BF73-A7D8-4134-8696-1FA90DCA9BF7}.Release|Any CPU.Build.0 = Release|Any CPU
28+
{FECE7ED0-FACD-421F-BED0-684339F11B98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{FECE7ED0-FACD-421F-BED0-684339F11B98}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{FECE7ED0-FACD-421F-BED0-684339F11B98}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{FECE7ED0-FACD-421F-BED0-684339F11B98}.Release|Any CPU.Build.0 = Release|Any CPU
32+
EndGlobalSection
33+
GlobalSection(SolutionProperties) = preSolution
34+
HideSolutionNode = FALSE
35+
EndGlobalSection
36+
GlobalSection(NestedProjects) = preSolution
37+
{FECE7ED0-FACD-421F-BED0-684339F11B98} = {3041DF39-EB80-4F02-89C5-8598A818B251}
38+
EndGlobalSection
39+
GlobalSection(ExtensibilityGlobals) = postSolution
40+
SolutionGuid = {955D10F6-8F5A-4682-B765-41EC80EB4308}
41+
EndGlobalSection
42+
EndGlobal

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019 Alan Doherty
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,99 @@
1-
# devicepilot-api-net
2-
A C# API for the Device Pilot analytics system
1+
<div align="center">
2+
3+
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://raw.githubusercontent.com/alandoherty/device-pilot-api-net/master/LICENSE)
4+
[![GitHub issues](https://img.shields.io/github/issues/device-pilot-api-net/protosocket-net.svg?style=flat-square)](https://github.com/alandoherty/device-pilot-api-net/issues)
5+
[![GitHub stars](https://img.shields.io/github/stars/device-pilot-api-net/protosocket-net.svg?style=flat-square)](https://github.com/alandoherty/device-pilot-api-net/stargazers)
6+
[![GitHub forks](https://img.shields.io/github/forks/device-pilot-api-net/protosocket-net.svg?style=flat-square)](https://github.com/alandoherty/device-pilot-api-net/network)
7+
[![GitHub forks](https://img.shields.io/nuget/dt/DevicePilot.Api.svg?style=flat-square)](https://www.nuget.org/packages/DevicePilot.Api/)
8+
9+
</div>
10+
11+
# devicepilot-api
12+
13+
A .NET API client for the Device Pilot IoT analytics platform. Open permissive MIT license and requires a minimum of .NET Standard 1.3.
14+
15+
## Getting Started
16+
17+
[![NuGet Status](https://img.shields.io/nuget/v/DevicePilot.Api.svg?style=flat-square)](https://www.nuget.org/packages/DevicePilot.Api/)
18+
19+
You can install the package using either the CLI:
20+
21+
```
22+
dotnet add package DevicePilot.Api
23+
```
24+
25+
or from the NuGet package manager:
26+
27+
```
28+
Install-Package DevicePilot.Api
29+
```
30+
31+
## Usage
32+
33+
Create an instance of the API client and configure your authentication token, you can find this on the API keys page of the platform.
34+
35+
```csharp
36+
ApiClient client = new ApiClient();
37+
```
38+
39+
### Ingesting
40+
41+
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.
42+
43+
```csharp
44+
var devices = new DeviceData[] {
45+
new DeviceData() {
46+
Id = "switch1",
47+
Properties = new Dictionary<string, object>() {
48+
{ "name", "Switch 1" },
49+
{ "isOn", true },
50+
{ "longitude", 53.7005d },
51+
{ "latitude", 2.3015d }
52+
}
53+
},
54+
new DeviceData() {
55+
Id = "switch2",
56+
Properties = new Dictionary<string, object>() {
57+
{ "name", "Switch 2" },
58+
{ "isOn", false },
59+
{ "longitude", 53.7005d },
60+
{ "latitude", 2.3015d }
61+
}
62+
}
63+
};
64+
65+
await client.BulkIngestAsync(devices);
66+
```
67+
68+
### Mapped types
69+
70+
Optionally you can use .NET objects to represent your device data structure. You can use either `client.IngestAsync<T>` or `client.BulkIngestAsync<T>`.
71+
72+
```csharp
73+
class MyDevice
74+
{
75+
[DeviceId]
76+
public string ID { get; set; }
77+
78+
[DeviceProperty("online")]
79+
public bool Online { get; set; }
80+
81+
[DeviceProperty]
82+
public double Temperature { get; set; }
83+
84+
[DeviceTimestamp]
85+
public DateTime? Timestamp { get; set; }
86+
}
87+
```
88+
89+
```csharp
90+
await client.IngestAsync<MyDevice>(new MyDevice() {
91+
ID = "temp1",
92+
Online = true,
93+
Temperature = 16.21d
94+
});
95+
```
96+
97+
## Contributing
98+
99+
Any pull requests or bug reports are welcome, please try and keep to the existing style conventions and comment any additions.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.2</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\..\src\DevicePilot.Api\DevicePilot.Api.csproj" />
10+
</ItemGroup>
11+
12+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using DevicePilot.Api;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace Example.PostData
7+
{
8+
public class OutletDevice
9+
{
10+
[DeviceId]
11+
public string Id { get; set; }
12+
13+
[DeviceProperty]
14+
public double Latitude { get; set; }
15+
16+
[DeviceProperty]
17+
public double Longitude { get; set; }
18+
19+
[DeviceProperty("isOn")]
20+
public bool IsOn { get; set; }
21+
22+
[DeviceTimestamp]
23+
public DateTime? Timestamp { get; set; }
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Licensed under the MIT License. See LICENSE in the project root for license information.
2+
3+
using DevicePilot.Api;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Threading.Tasks;
7+
8+
namespace Example.PostData
9+
{
10+
class Program
11+
{
12+
static async Task Main(string[] args) {
13+
ApiClient apiClient = new ApiClient(Environment.GetEnvironmentVariable("DP_TOKEN"));
14+
15+
List<DeviceData> datas = new List<DeviceData>();
16+
Random r = new Random();
17+
18+
await apiClient.IngestAsync<OutletDevice>(new OutletDevice() {
19+
Id = "outlet1",
20+
Latitude = 53.70076d,
21+
Longitude = -2.28442d
22+
});
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)