Skip to content

Commit 5f173db

Browse files
Improve readme (#1)
***NO_CI***
1 parent df8fab7 commit 5f173db

File tree

1 file changed

+20
-153
lines changed

1 file changed

+20
-153
lines changed

README.md

Lines changed: 20 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,38 @@
11

2-
Some notes to improve lib:
2+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=nanoFramework.Aws.IoTCore.Devices&metric=alert_status)](https://sonarcloud.io/dashboard?id=nanoFramework.Aws.IoTCore.Devices)
3+
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=nanoFramework.Aws.IoTCore.Devices&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=nanoframework.Aws.IoTCore.Devices)
4+
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
5+
[![NuGet](https://img.shields.io/nuget/dt/nanoFramework.Aws.IoTCore.Devices.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.Aws.IoTCore.Devices/)
6+
[![#yourfirstpr](https://img.shields.io/badge/first--timers--only-friendly-blue.svg)](https://github.com/nanoframework/Home/blob/main/CONTRIBUTING.md)
7+
[![Discord](https://img.shields.io/discord/478725473862549535.svg?logo=discord&logoColor=white&label=Discord&color=7289DA)](https://discord.gg/gCyBu8T)
38

4-
* Better documentation about ensuring "persistent" connections (or not) with documentation (including cloud policy doc for support)
5-
* Add some integration tests, including (scripts to auto provision cloud broker (and/or)) manual setup documents to ensure ease of use.
6-
* Partial Greengrass support?!
7-
* Websocket support?!
8-
* fleet provisioning support?!
9-
10-
11-
12-
13-
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=nanoframework_Aws_IoTCore_Devices&metric=alert_status)](https://sonarcloud.io/dashboard?id=nanoframework_Aws_IoTCore_Devices) [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=nanoframework_Aws_IoTCore_Devices&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=nanoframework_Aws_IoTCore_Devices) [![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) [![NuGet](https://img.shields.io/nuget/dt/nanoFramework.Aws.IoTCore.Devices.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.Aws.IoTCore.Devices/) [![#yourfirstpr](https://img.shields.io/badge/first--timers--only-friendly-blue.svg)](https://github.com/nanoframework/Home/blob/main/CONTRIBUTING.md) [![Discord](https://img.shields.io/discord/478725473862549535.svg?logo=discord&logoColor=white&label=Discord&color=7289DA)](https://discord.gg/gCyBu8T)
149

1510
![nanoFramework logo](https://github.com/nanoframework/Home/blob/main/resources/logo/nanoFramework-repo-logo.png)
1611

1712
-----
1813

19-
# Welcome to the **nanoFramework** Aws.IoTCore.Devices Library repository!
14+
# Welcome to the **nanoFramework** Aws.IoTCore.Devices repository!
2015

2116
## Build status
2217

2318
| Component | Build Status | NuGet Package |
2419
|:-|---|---|
25-
| nanoFramework.Aws.IoTCore.Devices | [![Build Status](https://dev.azure.com/nanoframework/Aws/IoTCore/Devices/_apis/build/status/nanoFramework.Aws.IoTCore.Devices?branchName=main)](https://dev.azure.com/nanoframework.Aws.IoTCore.Devices/_build/latest?definitionId=81&branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.Aws.IoTCore.Devices.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.Aws.IoTCore.Devices/) |
20+
| nanoFramework.Aws.IoTCore.Devices | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.Aws.IoTCore.Devices/_apis/build/status/nanoframework.nanoFramework.Aws.IoTCore.Devices?branchName=main)](https://dev.azure.com/nanoframework/nanoframework.Aws.IoTCore.Devices/_build/latest?definitionId=81&branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.Aws.IoTCore.Devices.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.Aws.IoTCore.Devices/) |
2621
| nanoFramework.Aws.IoTCore.Devices (preview) | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.Aws.IoTCore.Devices/_apis/build/status/nanoframework.nanoFramework.Aws.IoTCore.Devices?branchName=develop)](https://dev.azure.com/nanoframework/nanoFramework.Aws.IoTCore.Devices/_build/latest?definitionId=81&branchName=develop) | [![NuGet](https://img.shields.io/nuget/vpre/nanoFramework.Aws.IoTCore.Devices.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.Aws.IoTCore.Devices/) |
2722

2823
## See it in action
2924

30-
TODO!
25+
TODO! Please help us to add some samples!
3126

3227
## Usage
3328

34-
**Important**: You **must** be connected to a network with a valid IP address **and** a valid date. Please check the examples with the Network Helpers on how to help you making sure you have both.
29+
**Important**: Due to TLS, You **must** be connected to the internet (which means already having an IP address from your router) **and** a valid (minimum of today) date and time. Please check the examples that use networking (especially those that include TLS/NTP) to help you ensure it will work.
3530

36-
This AWS IoT SDK is using MQTT. So you need to ensure you can connect to port 8883 using TLS protocol. If you are in an enterprise network, this may be blocked. In most cases, this is not an issue.
31+
This AWS IoT SDK is using MQTT. So you need to ensure you have an outbound firewall port open to the TCP port 8883. If you are in an enterprise network, this may be blocked.
3732

3833
If it is, in future, we plan to add WebSocket support.
3934

40-
The the name of the classes and the methods try to get close to the .NET C# Azure IoT SDK. This should allow an easier portability of the code between both cloud provider environments.
35+
The the name of the classes and the methods try to get close to the [.NET nanoFramework C# Azure IoT SDK](https://github.com/nanoFramework/nanoFramework.Azure.Devices). This should allow an easier portability of the code between both cloud provider environments.
4136

4237
### Certificate
4338

@@ -84,7 +79,7 @@ X509Certificate awsRootCACert = new X509Certificate(Resources.GetBytes(Resources
8479
MqttConnectionClient awsIoT = new MqttConnectionClient(IotBrokerAddress, ThingId, clientCert, MqttConnectionClient.QoSLevel.AtLeastOnce, awsRootCACert);
8580
```
8681

87-
Note: when the certificate expires, you will have to reflash fully the device with the new certificate, or build a mechinisum into your code to include a primary and secondary certificate.
82+
Note: when the certificate expires, you will have to fully reflash the device with the new certificates and keys, or build a mechanism into your code to include primary and secondary versions of them.
8883

8984
#### Storing the certificate into the device
9085

@@ -115,7 +110,7 @@ Note: please see the previous section to understand how to better pass the certi
115110

116111
### Getting and updating Device Shadow
117112

118-
You can request your Azure IoT Twin simply by calling the `GetTwin` function.
113+
You can request your Shadow simply by calling the `GetShadow` function.
119114

120115
```csharp
121116
var shadow = awsIoT.GetShadow(new CancellationTokenSource(20000).Token);
@@ -211,37 +206,6 @@ void CloudToDeviceMessageEvent(object sender, CloudToDeviceMessageEventArgs e)
211206

212207
Note: the `sender` is a `MqttConnectionClient` class, you can then send a message back with a confirmation or any logic you've put in place.
213208

214-
<!-- ### Method callback
215-
216-
Method callback is supported as well. You can register and unregister your methods. Here are a few examples:
217-
218-
```csharp
219-
awsIoT.AddMethodCallback(MethodCallbackTest);
220-
awsIoT.AddMethodCallback(MakeAddition);
221-
awsIoT.AddMethodCallback(RaiseExceptionCallbackTest);
222-
223-
string MethodCallbackTest(int rid, string payload)
224-
{
225-
Debug.WriteLine($"Call back called :-) rid={rid}, payload={payload}");
226-
return "{\"Yes\":\"baby\",\"itisworking\":42}";
227-
}
228-
229-
string MakeAddition(int rid, string payload)
230-
{
231-
Hashtable variables = (Hashtable)JsonConvert.DeserializeObject(payload, typeof(Hashtable));
232-
int arg1 = (int)variables["arg1"];
233-
int arg2 = (int)variables["arg2"];
234-
return $"{{\"result\":{arg1 + arg2}}}";
235-
}
236-
237-
string RaiseExceptionCallbackTest(int rid, string payload)
238-
{
239-
// This will properly return as well the exception error
240-
throw new Exception("I got you, it's to test the 504");
241-
}
242-
```
243-
244-
**Important**: method names are case sensitive. So make sure you name your functions in C# the same way. -->
245209

246210
### Status update event
247211

@@ -263,112 +227,15 @@ void StatusUpdatedEvent(object sender, StatusUpdatedEventArgs e)
263227

264228
Note that they are status change based, so once the connect or disconnect event arrives, they'll be replaced by other events as soon as something else happened like receiving a shadow.
265229

266-
<!-- ## Azure IoT Device Provisioning Service (DPS) support
267-
268-
This SDK supports as well Azure IoT Device Provisioning Service. Group and individual provisioning scenarios are supported either with a symmetric key either with certificates. To understand the mechanism behind DPS, it is recommended to read the [documentation](https://docs.microsoft.com/azure/iot-dps/).
269-
270-
### Provisioning using symmetric key
271230

272-
For symmetric key provisioning you only need the following elements:
231+
## Future work items for discussion:
273232

274-
- A registration ID
275-
- The ID Scope
276-
- The device name
277-
- The key or the derived key for group provisioning
278-
279-
The code is then straight forward:
280-
281-
```csharp
282-
const string RegistrationID = "nanoDPStTest";
283-
const string DpsAddress = "global.azure-devices-provisioning.net";
284-
const string IdScope = "0ne01234567";
285-
const string SasKey = "alongkeyencodedbase64";
286-
287-
// See the previous sections in the SDK help, you either need to have the Azure certificate embedded
288-
// Either passing it in the constructor
289-
X509Certificate azureCA = new X509Certificate(DpsSampleApp.Resources.GetBytes(DpsSampleApp.Resources.BinaryResources.BaltimoreRootCA_crt));
290-
var provisioning = ProvisioningDeviceClient.Create(DpsAddress, IdScope, RegistrationID, SasKey, azureCA);
291-
var myDevice = provisioning.Register(new CancellationTokenSource(60000).Token);
292-
293-
if(myDevice.Status != ProvisioningRegistrationStatusType.Assigned)
294-
{
295-
Debug.WriteLine($"Registration is not assigned: {myDevice.Status}, error message: {myDevice.ErrorMessage}");
296-
return;
297-
}
298-
299-
// You can then create the device
300-
var device = new DeviceClient(myDevice.AssignedHub, myDevice.DeviceId, SasKey, nanoFramework.M2Mqtt.Messages.MqttQoSLevel.AtMostOnce, azureCA);
301-
// Open it and continue like for the previous sections
302-
var res = device.Open();
303-
if(!res)
304-
{
305-
Debug.WriteLine($"can't open the device");
306-
return;
307-
}
308-
```
309-
310-
Note: like for the `DeviceClient` you need to make sure you are connected to a network properly and also have a proper data and time set on the device.
311-
312-
### Provisioning using certificates
313-
314-
For symmetric key provisioning you only need the following elements:
315-
316-
- A registration ID
317-
- The ID Scope
318-
- The device name
319-
- The device certificate
320-
- Make sure that your IoT Hub is as well aware of the root/intermediate certificate you are using otherwise you won't be able to connect to your IoT Hub once your device is provisioned
321-
322-
The code is then straight forward:
323-
324-
```csharp
325-
const string RegistrationID = "nanoCertTest";
326-
const string DpsAddress = "global.azure-devices-provisioning.net";
327-
const string IdScope = "0ne0034F11A";
328-
329-
const string cert = @"
330-
-----BEGIN CERTIFICATE-----
331-
Your certificate
332-
-----END CERTIFICATE-----
333-
";
334-
335-
const string privateKey = @"
336-
-----BEGIN ENCRYPTED PRIVATE KEY-----
337-
the encrypted private key
338-
-----END ENCRYPTED PRIVATE KEY-----
339-
";
340-
341-
// See the previous sections in the SDK help, you either need to have the Azure certificate embedded
342-
// Either passing it in the constructor
343-
X509Certificate azureCA = new X509Certificate(DpsSampleApp.Resources.GetBytes(DpsSampleApp.Resources.BinaryResources.BaltimoreRootCA_crt));
344-
// Note: if your private key is not protected with a password, you don't need to pass it
345-
// You can as well store your certificate directly in the device certificate store
346-
// And you can store it as a resource as well if needed
347-
X509Certificate2 deviceCert = new X509Certificate2(cert, privateKey, "1234");
348-
349-
var provisioning = ProvisioningDeviceClient.Create(DpsAddress, IdScope, RegistrationID, deviceCert, azureCA);
350-
var myDevice = provisioning.Register(new CancellationTokenSource(60000).Token);
351-
352-
if(myDevice.Status != ProvisioningRegistrationStatusType.Assigned)
353-
{
354-
Debug.WriteLine($"Registration is not assigned: {myDevice.Status}, error message: {myDevice.ErrorMessage}");
355-
return;
356-
}
357-
358-
// You can then create the device
359-
var device = new DeviceClient(myDevice.AssignedHub, myDevice.DeviceId, deviceCert, nanoFramework.M2Mqtt.Messages.MqttQoSLevel.AtMostOnce, azureCA);
360-
// Open it and continue like for the previous sections
361-
var res = device.Open();
362-
if(!res)
363-
{
364-
Debug.WriteLine($"can't open the device");
365-
return;
366-
}
367-
```
368-
369-
### Additional payload
233+
* Better documentation about ensuring "persistent" connections (or not) with documentation (including cloud policy doc for support)
234+
* Add some integration tests, including (scripts to auto provision cloud broker (and/or)) manual setup documents to ensure ease of use.
235+
* Partial Greengrass support?!
236+
* Websocket support?!
237+
* fleet provisioning support?!
370238

371-
Additional payload is supported as well. You can set it up as as json string in the `ProvisioningRegistrationAdditionalData` class when calling the `Register` function. When the device has been provisioned, you may have as well additional payload provided. -->
372239

373240
## Feedback and documentation
374241

0 commit comments

Comments
 (0)