Forum Discussion
Help understanding IoTHubDeviceClient in distributed modules
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?
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?- OlivierBlochSep 23, 2020Former Employee
The example I referenced does the following: It deploys 2 modules on your IoT Edge device, the first one is the SimulatedTempModule, which is a standard temp sensor data simulator that generates random temp values, and the second is your custom module that listens to the SimulatedTempModule module and checks for a temperature threshold (configured using the module Twin). When the threshold is passed, the custom module will create and send an alert message out. The routes should be configured to sen all telemetry outputs from the temp sensor simulator to the custom module and to send all messages from your custom module (alerts for temperature above the threshold) to IoT Hub.
If things are not working as expected, then you can troubleshoot using recommended tools and techniques from this article: https://docs.microsoft.com/en-us/azure/iot-edge/troubleshoot.
I recommend you start by checking your modules are all running, then looking at the output of the temp sensor simulator. If all is ok there, look at your custom module to see if it sends an alert on its output when temp goes above configured threshold. And if everything is ok there then you can use thehttps://docs.microsoft.com/en-us/azure/iot-pnp/howto-use-iot-explorer to monitor what's arriving in your IoT Hub.