Skip to content

Latest commit

 

History

History
33 lines (29 loc) · 2.75 KB

README.md

File metadata and controls

33 lines (29 loc) · 2.75 KB

Edge Hub

This project contains the Edge Hub.

Startup execution flow

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

How to debug Edge hub using Visual Studio

  1. 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.
  2. 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 as twin to read confirm from twin, or local to read Edge Hub config from configuration file.
  1. Set Microsoft.Azure.Devices.Edge.Hub.Service as startup project in Visual Studio.
  2. Make sure to rebuild the solution.
  3. 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:

  1. You can either use samples in Azure IoT C# SDK or write your own leaf device application using DeviceClient in Azure IoT C# SDK.
  2. This example uses the direct method sample in Azure IoT C# SDK, you can find it under iothub\device\samples\DeviceClientMethodSample.
  3. 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.
  4. Make sure Edge hub is running first, then you can start sample application by hit F5 in Visual Studio.
  5. Look at Edge hub console window, you will see logs about connecting to a new device.
  6. You can invoke direct method call from Azure IoT Portal or from Device Explorer.
  • Method name: WriteToConsole
  • Method payload: Any valid json
  1. You should see your method payload printed out in sample application console window.