This project contains the Edge Hub.
Sequence | Description | Code reference |
---|---|---|
1 | Edge hub service starts. | Program.Main |
2 | Load configuration from application json file (appsettings_hub.json) and environment variables. | Program.Main |
3 | Load certificates for Edge hub and install certificate chain if available. | |
4 | Initialize web hosting (ASP.Net Core) and build dependency injection container. | Hosting , IModule.Load |
5 | Instantiate each protocol including amqp, mqtt and http if it is enabled. | IProtocolHead |
6 | Start enabled protocol(s) asynchronously. Each protocol will start a listener for incoming requests. | IProtocolHead.StartAsync |
- Set environment variable
EdgeModuleHubServerCertificateFile
to the path of a SSL Certificate file (e.g. C:\edgeDevice.pfx); for debug purpose, you can create and use a self-signed certificate. Remember to restart Visual Studio to take effect. - Update following values in appsettings_hub.json in Microsoft.Azure.Devices.Edge.Hub.Service project.
IotHubConnectionString
- Edge Hub module connection string; set it as edge device connection string appending with "ModuleId=$edgeHub".configSource
- Set it astwin
to read confirm from twin, orlocal
to read Edge Hub config from configuration file.
- Set Microsoft.Azure.Devices.Edge.Hub.Service as startup project in Visual Studio.
- Make sure to rebuild the solution.
- You can start debugging Edge Hub by hitting F5 in Visual Studio.
If you want to run a leaf device connecting to Edge hub using Visual Studio, then continue to read below:
- You can either use samples in Azure IoT C# SDK or write your own leaf device application using DeviceClient in Azure IoT C# SDK.
- This example uses the direct method sample in Azure IoT C# SDK, you can find it under iothub\device\samples\DeviceClientMethodSample.
- Open that sample application in a new instance of Visual Studio, update connection string and add
GatewayHostName=127.0.0.1
to it in order to connect to Edge hub running locally using Visual Studio. - Make sure Edge hub is running first, then you can start sample application by hit F5 in Visual Studio.
- Look at Edge hub console window, you will see logs about connecting to a new device.
- You can invoke direct method call from Azure IoT Portal or from Device Explorer.
Method name
: WriteToConsoleMethod payload
: Any valid json
- You should see your method payload printed out in sample application console window.