Sending trigger from IOT hub to IOT device (from a service bus queue in logic app)

Steven Hurwitt 21 Reputation points
2020-10-25T04:40:46.207+00:00

I originally bought a raspberry pi to get some "at home" cloud experience, so I'm stoked to learn about things like the IOT Hub that enable a sort of cloud-hybrid connectivity.

Trying to reverse engineer this tutorial to set up a Logic App that is essentially a scheduler and triggers a Service Bus Queue message that I can route through my IOT Hub and send a message to my raspberry pi to run my script.

Need to do some more tinkering, but it looks like it can be done (in python) via this iot sdk. I'm a little confused how to execute the routing from Logic App -> Service Bus queue -> IOT Hub -> IOT device though. Looks like I can modify my script to send data as telemetry from the IOT device, but I'm a little stuck trying to trigger the script on my device from a Logic App.

Any help or advice is appreciated! Thanks

Steven

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,133 questions
Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,189 questions
Azure IoT SDK
Azure IoT SDK
An Azure software development kit that facilitates building applications that connect to Azure IoT services.
219 questions
0 comments No comments
{count} votes

Accepted answer
  1. Matthijs van der Veer 4,376 Reputation points MVP
    2020-10-25T07:10:08.793+00:00

    To receive your device messages in a Logic App, Service Bus is definitely a valid option. However to send messages back to your device, you have two options:

    1. Cloud to Device messages
    2. Direct Methods

    On the device side, there are good samples for C2D messages and Direct Methods available in Python. If I was going to run a script because the cloud told me so, I would go for a Direct Method. To make a decision between C2D and Direct Method, try this documentation.

    That brings me to the Logic App, you don't need to use a Service Bus to communicate with your devices. You can use either an HTTP request or the SDK for a Direct Method, or you can use the SDK for a Cloud to Device message. It is completely possible to do an HTTP request for a direct method using this call in a Logic App. But if you do have some affinity with Python, you might want to look into using the Python SDK in an Azure Function instead. Functions can be triggered by the Service Bus Queue you already have, but you're left with the flexibility of writing code to achieve your goal.

    Sorry for the documentation-heavy answer, hope this helps!

    4 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.