1

I am trying to setup an iot-edge device as an edge gateway. We wouldn't want our leaf/sensor/downstream devices directly connecting to the internet/cloud, and thus I would expect the iot-edge-gateway(as it name suggests) to bridge the connection between downstream devices and the cloud/iot-hub. However, I realize that the connection string for iot-hub/edge at any device level is simply

connection-string-for-iothub-with-gatewayhostwayAppended

This makes me assume that downstream devices transmit messages to an endpoint (prolly messages/* )to cloud/iot-hub and it is from there that gateway gets it(works with that data maybe then) and forwards it back to the $upstream, which shuns the whole point of a gateway.

Here in the message routing section of IOT-EDGE-GATEWAY https://learn.microsoft.com/en-us/azure/iot-edge/how-to-create-transparent-gateway, in the ROUTE MESSAGES FROM DOWNSTREAM DEVICES section

{
    "routes":{
        "sensorToAIInsightsInput1":"FROM /messages/* WHERE NOT IS_DEFINED($connectionModuleId) INTO BrokeredEndpoint(\"/modules/ai_insights/inputs/input1\")", 
        "AIInsightsToIoTHub":"FROM /messages/modules/ai_insights/outputs/output1 INTO $upstream" 
    } 
}

makes it sound like the gateway is routing messages falling on the built-in-endpoint(Default) to $upstream. I can't find any other clearer documentations over the web on this subject. I would really appreciate if someone clears this up. I was expecting the connection string for edge-gateway(that i'd mention in the device end to be something along the lines of localhost:port and not cloudaddress+gatewayhostname)

Shahab Uddin
  • 101
  • 1
  • 11

1 Answers1

2

If your connection string contains a gateway hostname - and the SDK you are using on the device properly handles this, the device only connects to the gateway, not to the IoT Hub.

You can see the example from the .NET SDK here:

this.HostName = builder.GatewayHostName == null || builder.GatewayHostName == "" ? builder.HostName : builder.GatewayHostName;

https://github.com/Azure/azure-iot-sdk-csharp/blob/f86cb76470326f5af8426f3c2695279f51f6e0c8/iothub/device/src/IotHubConnectionString.cs#L30

If the gateway hostname is set, it actually overwrites the IoT Hub hostname for the connection.

silent
  • 14,494
  • 4
  • 46
  • 86
  • According to the documentations the gateway hostname is found in /etc/iotedge/config.yaml . In mine its simply the name of my edge device(not a host-address/IP plus port as I would expect it to be). I'm just wondering how the leafstream device would transmit data/messages to a device/edge-gateway without having it's address on the network. – Shahab Uddin Jul 12 '19 at 07:32
  • if you want leaf devices to connect to your Edge device, then you need to use a gateway hostname that is resolvable on your local network. – silent Jul 12 '19 at 07:35
  • Yeap, This is exactly what I mean. I suppose I'll have to set the "hostname" specified in my config.yaml in the local DNS. – Shahab Uddin Jul 12 '19 at 07:41
  • Yes, what goes into config.yaml as `hostname` should be DNS resolvable. Also: If you established a parent/child relationship for this downstream device, then you can simplify the connection string by calling the gateway directly as the connection host. For example: `HostName=myGatewayDevice;DeviceId=myDownstreamDevice;SharedAccessKey=xxxyyyzzz` source: https://learn.microsoft.com/en-us/azure/iot-edge/how-to-authenticate-downstream-device#connect-to-iot-hub-through-a-gateway – Venkat Yalla Jul 13 '19 at 02:34
  • Also, your "hostname" in config.yaml can simply be the IP address of the Edge device. It does not have to be a FQDN. It just has to match whatever the GatewayHostName in your connection string is (i.e. if you use the IP address in the connection string, then you have to also use the IP address as the 'hostname' in config.yaml) – Steve Busby - MSFT Dec 19 '19 at 17:13