0

I have created an Azure IoT edge gateway running in Docker with a custom module that is just a pass through (takes the message and sends it upstream).

I created a simple .net console application to send a message to the gateway so that it can be evaluated.

This is the code that I have in the console app.

DeviceClient client =
            DeviceClient.CreateFromConnectionString("HostName=<my iot hub in azure>.azure-devices.net;DeviceId=<the name of the device>;SharedAccessKey=<my access key>;GatewayHostName=<the name of the IoT Edge Device>");

Message message = new Message();

message.Properties.Add("testproperty", "test");

client.SendEventAsync(message).Wait();

It appears that when the SendEventAsync method is called that it will hang forerver. I waited 5 minutes and the app is stuck waiting. If I remove the GatewayHostName from the connection string it executes immediately and my message is sent directly to the IoT Hub in Azure.

Why will it not send the message to the IoT Edge gateway?

maccettura
  • 10,514
  • 3
  • 28
  • 35
Evan Nielsen
  • 193
  • 2
  • 10
  • are your edgeAgent and edgeHub running on your IoT Edge device? Just check with `docker ps` – silent Dec 18 '17 at 15:47
  • Have you looked at and followed the steps described on https://learn.microsoft.com/en-us/azure/iot-edge/how-to-create-transparent-gateway? – Olivier Bloch Dec 18 '17 at 17:01
  • it looks like your downstream device is not correct configured for its connectivity to the IoT Edge gateway, see more details in the https://learn.microsoft.com/en-us/azure/iot-edge/how-to-create-transparent-gateway#configure-a-downstream-device – Roman Kiss Dec 18 '17 at 17:37
  • 1
    Are you able to reach the host that you put in the `GatewayHostName` property in the connection string from the device where you're running the console app? For example, using something like *netcat*, what happens when you run: `nc -v -v -z 8883`? – Raj Dec 18 '17 at 18:52

1 Answers1

1

The client.SendEventAsync call implicitly tries to open a connection to the server (in this case the IoT Edge gateway), which is not able to complete and that is why you are seeing the call hang.

And I feel the problem is in your connection string - "HostName=.azure-devices.net;DeviceId=;SharedAccessKey=;GatewayHostName="

Here the GatewayHostName is not the name of the Edge device, but instead the hostname of the physical device on which the modules are running (fqdn hostname, if available). So the connection string should be something like this - "HostName=.azure-devices.net;DeviceId=;SharedAccessKey=;GatewayHostName="

If your code is executing in your custom module, then you can simply use the the environment variable $EdgeHubConnectionString, which should contain the connection string you can use.

If it is a downstream device, then along with using the right connection string, you also need to make sure the device trusts the certificate used to accept the connection by the gateway device. You can find more info on that here - https://learn.microsoft.com/en-us/azure/iot-edge/how-to-create-transparent-gateway

  • I did follow the instructions about the transparent gateway and added the certificates before I tried it. So that was not the problem. The problem was exactly that I needed to add the FQDN of the machine running my docker container with Edge in the GatewatHostName property. After I did that the message went through. Now I just need to get it to hit my break point in my custom module. – Evan Nielsen Dec 19 '17 at 12:20