Edge Hub does not really care who is calling into it as long as the right credentials are provided. The caller could be in a Docker container, in another process on the host or a downstream device. So during development, when using Visual Studio it should be possible for you to simply F5 (launch debugger) your module project and have it connect and communicate with Edge Hub. You'd just need to make sure that you provide it the right context. For example, you may have to setup your VS debug settings so that the EdgeHubConnectionString
value is setup properly.
Right now though, unfortunately, the Azure portal (or the Azure CLI) does not have support for fetching module credentials which you'd need to build your connection string to connect to Edge Hub. Support for this should be arriving soon.
In the meantime you can workaround this by doing a deployment the normal way (i.e. via "Set Modules" in the portal and having the Edge Agent deploy the container for you) and then run the following command (or something like it) from a bash
terminal to print the value of the connection string:
docker inspect \
--format='{{range $e := .Config.Env}}{{printf "%s\n" $e}}{{end}}' \
YourContainerName | \
grep EdgeHubConnectionString | \
cut -c 25-
Replace YourContainerName
in the command above with the name of your module/container.
In addition to this you'll also want to skip TLS cert validation when you connect to Edge Hub. This is because when running on your PC it is not setup to trust the server cert that Edge Hub uses. You can use the following snippet to skip cert validation in your module:
var mqttSetting = new MqttTransportSettings(TransportType.Mqtt_Tcp_Only);
mqttSetting.RemoteCertificateValidationCallback =
(sender, certificate, chain, sslPolicyErrors) => true;
ITransportSettings[] settings = { mqttSetting };
DeviceClient deviceClient =
DeviceClient.CreateFromConnectionString(connectionString, settings);
After this you should be able to debug your module from VS.