azure - Do leaf/downstream devices connect directly to iot-hub even when edge is used as gateway?
问题描述
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://docs.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)
解决方案
如果您的连接字符串包含网关主机名 - 并且您在设备上使用的 SDK 可以正确处理此问题,则设备仅连接到网关,而不连接到 IoT 中心。
您可以在此处查看 .NET SDK 中的示例:
this.HostName = builder.GatewayHostName == null || builder.GatewayHostName == "" ? builder.HostName : builder.GatewayHostName;
如果设置了网关主机名,它实际上会覆盖连接的 IoT 中心主机名。
推荐阅读
- json - 使用 JMeter 中的正则表达式提取器从 JSON 中获取值
- javascript - 如何更改所有 TinyMCE 静态文件的基本根目录?
- ios - 深度链接二维码在 iOS 14 中打开 Safari 而不是 App
- python - Python 尝试返回致命错误,除非在 pyinstaller 中编译
- typescript - Jest & TypeScript:VS Code 找不到名称
- java - 在运行时将数据加载到 hazelcast
- leaflet - 检查重复标记传单风水师
- python - 如何在没有 Numpy 库的 python 中找到特征值和特征向量?
- python - 在 IBM 的技能实验室(在线 Jupyter 笔记本)中使用 Selenium Webdriver 和 Python 时出错
- reactjs - Reactjs - TypeError:无法读取未定义的属性“项目”