Newer
Older
using System.Threading.Tasks;
namespace Main
{
class Program
{
static async Task Main(string[] args)
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const string ClientName = "{insert}";
const string ClientGuid = "{insert}";
const string BranchGuid = "{insert}";
const string ApiKey = "{insert}";
const string Login = "{insert}";
const string Password = "{insert}";
try
{
// Define connection options with specific credentials and client identifiers
ConnectionOptionsBuilder optionsBuilder = new ConnectionOptionsBuilder();
ConnectionOptions connectionOptions = optionsBuilder
.Url("https://twin.rtls.solutions/api/")
.Client(ClientName)
.ClientGuid(ClientGuid)
.BranchGuid(BranchGuid)
.Timeout(1000)
.ApiKey(ApiKey)
.Version(ConnectionOptions.VERSION_3)
.Login(Login)
.Password(Password)
.Build();
// Create tDevKit connector class instance and authorize by credentials in builder
DevkitConnectorV3 devkitConnector = (DevkitConnectorV3)DevkitFactory.CreateDevkitConnector(connectionOptions);
AuthenticationResponseContract auth = await devkitConnector.Authenticate(false);
Console.WriteLine(auth);
// Define sensors data list of SensorDataContract
var dataList = new[]
{
new SensorDataContract
{
Quantity = "Voltage",
Value = "120",
Unit = "V",
DataType = "Single"
},
new SensorDataContract
{
Quantity = "Frequency",
Value = "1",
Unit = "Hz",
DataType = "Single"
},
new SensorDataContract
{
Quantity = "OK parts",
Value = "600",
Unit = "pcs",
DataType = "Int32"
}
};
// Create sensor contract with specific data
SensorContract sensor = new SensorContract
{
Login = "buffer",
SensorData = dataList.ToArray(),
};
// Send sensor with specified data to Twinzo server
PostResponseContract[] response = await devkitConnector.AddSensorData(new[] { sensor });
Console.WriteLine(response);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
finally
{
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}