• Create a new Event Grid System Topic
  • [Optional advanced: Create a Service Bus if you’ll be using the same event in multiple ways — docs]
  • Create a Logic Apps app that will listen for the event coming from the IoT Hub
  • Create an event on the IoT Hub that will be sent every time the Raspberry Pi sends temperature data
  • Fine-tune the Logic App to parse the event and do things with it (like post to Twitter)

Create a new Event Grid System Topic

Before we start wiring up the events, we need to create an Event Grid System Topic. This was new to me (and I struggled to figure this out). Looking at the docs, it seems like this was previously hidden (implicit), but is now exposed to allow fine-grained control when you have many many services, endpoints, messages, etc — since this is the only thing I’m doing in my subscription, it’s just an additional step to do.

  1. Search the portal for Event Grid System Topics.

Optional advanced: Create a Service Bus if you’ll be using the event in multiple parallel ways or with more complex logic

If you want to enable more powerful message routing capabilities so that a single message (event) can go to a Storage Account, Logic Apps, SQL, or other, you can create a Service Bus that provides queues, routing, etc.

Create a Logic Apps app that will listen for the event coming from the IoT Hub

We’ll create a new Logic Apps app that will let us create our bot that will tweet whenever some condition is met, similar to Chloe Condon‘s Shania bot (go ahead, try and impress them, I’ll wait).

  1. Create a new Logic App Consumption app. If you already have a VM set up or some specific infrastructure to use logic apps, Standard could be for you. In our case, I don’t want to deal with infrastructure, and just have an app that runs on demand (consumption) without caring for VMs, Docker containers, or Storage.

Create an event on the IoT Hub that will be sent every time the Raspberry Pi sends temperature data

  1. In your IoT Hub, click on Events, and then create a new Event Subscription:

Fine-tune the Logic App to parse the event and do things with it (such as posting to Twitter)

Now that we have an event being sent to the Logic App, let’s fine tune the app to ensure we can unpack the message in the event and do something (Tweet) when certain conditions are met.

  1. Make sure that the IoT hub sends a couple of events / messages to the Logic App. If you wrote the code, you’re already familiar with the JSON structure, but in this case, I’m taking the scenic (lazy) route.
  2. Open the Logic App we created earlier and click on one of the runs to open it (whether successful or failed):

Conclusion

We’ve connected the messages sent from the RaspberryPi to an IoT hub, and then fired events to a Logic App endpoint that tweets when the right conditions are met (temperature above than 29 degrees Celsius). Some tweaks to this could be:

  • Tweet when the temperature is outside a specific range
  • Email (instead of tweeting) when the temperature is at a given range/level.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
José Lara

José Lara

Form + function = tech for humans. PM @Microsoft building the future of @Windows (fmr @Azure_Synapse , @MicrosoftDesign ). Nobody wins unless everybody wins.