Forum Discussion
Help understanding IoTHubDeviceClient in distributed modules
petersaverman the modules in IoT Edge do not need to authenticate with IoT Hub directly and you shouldn't use a device connection string nor the IoT HubDeviceClient client in a module. As you have seen you need to use the IoTHubModule client.
The IoTEdge runtime is the one that will have to authenticate using the IoT Edge Device credentials created when provisioning in your IoT Hub(s). BTW I recommend using the Device Provisioning Service rather than connection strings when going to production. See some doc about this https://docs.microsoft.com/en-us/azure/iot-edge/how-to-auto-provision-x509-certs.
Once your IoT Edge devices connect and authenticate to the IoT Hub they were configured for, you can deploy the same module to multiple IoT Edge devices through IoT Hub using the https://docs.microsoft.com/en-us/azure/iot-edge/how-to-deploy-at-scale, the https://docs.microsoft.com/en-us/azure/iot-edge/how-to-deploy-cli-at-scale or your own code using the IoT Hub APIs.
Let me know if that puts you on the right track
Thanks for responding and excuse my late reply. I've actually set up provisioning of my devices and that works fine. I did find a discussion regarding the IoTHubModuleClient not receiving a connection as well as not throwing an error under certain circumstances which I sadly can't remember now but this was my issue as well.
I'm trying to find out just how to use the IoTHubModuleClient to send a message to the Hub right now. Is that where the output comes in (via send_message_to_output) or do I still use the
or should I still use the send_message method?
- OlivierBlochSep 22, 2020Former Employee
The modules communication is enabled by the Edge Hub module which is part of the IoT Edge runtime. The idea is that you configure routes between modules and up to the IoT Hub service at the IoT Edge runtime level and then in your module you can send messages to the output of the module defined in the routing configuration. You can learn more about the IoT Edge runtime concepts in https://docs.microsoft.com/en-us/azure/iot-edge/iot-edge-runtime#module-communication and more on the routing setup in https://docs.microsoft.com/en-us/azure/iot-edge/module-composition.
If you want to send messages to IoT Hub directly from a module then you need to setup a route that takes all outputs from the module and sends to "upstream".
For sending all messages from a specific module to IoT Hub, you would setup the route like this:
"$edgeHub": { "properties.desired": { "routes": { "route1": "FROM /messages/modules/<moduleId>/* INTO $upstream" }, } }
- petersavermanSep 23, 2020Copper Contributor
OlivierBloch That is a totally different approach. From most example code there is embeded connection string which made me think that the modules sent the data themselves. Thanks for clarifying! Still, I tried another https://docs.microsoft.com/en-us/azure/iot-edge/tutorial-python-module and this still doesn't give me any messages when monitoring the endpoints. I'm starting to suspect that something else might be wrong. Is there a good approach to know where the fault is? Logs don't give anything away either. I expected the example above to "just work".
- petersavermanSep 23, 2020Copper ContributorTo clarify: the only output given from above mentioned example is:
IoT Hub Client for Python
The sample is now waiting for messages.
Press Q to quit
Press Q to quit
Press Q to quit
Press Q to quit
... and so on
Nothing is triggered. Am I supposed to do something to trigger this?