Recently we released IoT Edge v2 Public Preview coming with a bunch of enhancements and new functionality. The runtime is now completely .NET core based and containerized. That in place you’re now able to write and consume models as docker containers. Deployment, Testing, Configuration everything docker offers can be used now in IoT Edge.

Intelligence to the Edge

Beside the fact that you can customize the Edge Device with custom modules you’re also able to provision certain Azure services to the edge device itself. Services available in IoT Edge are Azure Stream Analytics, Azure Machine Learning and the Azure Functions runtime, allowing you to integrate Azure Functions based execution on the edge device. You can leverage the power Azure offers you on premise in your edge environment deployed through containers.

Getting started

To inject business rules into your Internet of Things environment you can write custom modules including the logic you need to manipulate and analyze the collected data in the edge even before submitting it to the IoT Hub. You can connect multiple modules through messaging or direct communication to fulfil the needs of the business.

We provide tutorials to get started with the development for IoT Edge. The current development experience is targeting dotnet core developers but others will follow.

If you are a dotnet core developer you can enhance the dotnet core cli experience through custom IoT Edge templates

1
2
Azure IoT Edge Function aziotedgefunction [C#] Console
Azure IoT Edge Module aziotedgemodule [C#] Console

The templates provide you a good starting point in creating a skeleton project for a custom module. To create one you simply dotnet new aziotedgemodule -n mymodule. Once the project is scaffolded you leverage Microsoft.Azure.Devices.Client to access the IoT Edge runtime from your module to access the message endpoints or device twin properties. This also included the module twin properties.

The following sample is showing how to inject during initialization custom code to emit test data to a message endpoint

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
static async Task<IDisposable> InitEdgeModule()
{
// Open a connection to the Edge runtime using MQTT transport and
// the connection string provided as an environment variable
ITransportSettings[] settings =
{
new MqttTransportSettings(TransportType.Mqtt_Tcp_Only)
{ RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true }
};
DeviceClient IoTHubModuleClient = DeviceClient.CreateFromConnectionString(Environment.GetEnvironmentVariable("EdgeHubConnectionString"), settings);
await IoTHubModuleClient.OpenAsync();
Console.WriteLine("IoT Hub module client initialized.");
return
Observable.Interval(new TimeSpan(0, 0, 1))
.Select(i =>
new MessageBody
{
Values =
Enumerable.Range(0, 12)
.Select(point => new MessageBody.MessageValue { DataPoint = $"Test{point}_Point", Value = rand.Next(0, 1001) }) .ToList()
}
)
.Select(JsonConvert.SerializeObject)
.Select(messageString => Encoding.UTF8.GetBytes(messageString))
.Select(messageBytes => new Message(messageBytes))
.SelectMany(async message =>
{
await IoTHubModuleClient.SendEventAsync("PointOutput", message);
return Unit.Default;
})
.Subscribe(_ => Console.WriteLine($"{DateTime.Now} - Sent message"),
ex =>
{
Console.WriteLine(DateTime.Now + " - Error " + ex.Message);
Console.WriteLine(ex.ToString());
Console.WriteLine();
});
}
}

SendEventAsync is sending the message into the message endpoint of the IoT Edge Device called PointOutput. With a route definition to $upstream - which is the special endpoint to send data to the IoT Hub - generated data can be monitored in the IoT Hub.

If you want to have a full fledged data emitting module you can take a look at this repository https://github.com/dariuszparys/iotedge-simulator-module.

Flexibility your way

IoT Edge allows you to control and work with your data before it goes up to the cloud. You can even just leave it on premise if you want. With custom modules you have all flexibility to define the logic the way you need it for your devices, completely manageable from the cloud. Device and module definitions can be pushed to the corresponding locations and change behavior during runtime. Further with the cloud intelligence on your edge you can leverage the power of Stream Analytics and Machine Learning in the edge environment being able to support even offline scenarios.