(Daniel Lawton) Blog 3 - MQTT | IFTTT

 IoT Apps Blog 3 - MQTT | IFTTT 

Daniel Lawton | 20084608                                                                                 Date:12/01/2025

This blog combines the last two weeks of IoT applications, following the design plan made by Jason, the goal was to setup an Analog Input / Analog Output (AI/AO) system using MQTT (Message Queuing Telemetry Transport), Beebotte as a MQTT Broker, micro:bit to subscribe and publish data to and from the broker.

MQTT Architecture Diagram





Using MQTT to Connect micro:bits to the Cloud                                                                          

Why MQTT?                                                                                                                                                MQTT (Message Queuing Telemetry Transport): is a messaging protocol that is a staple when  connecting IoT devices to a cloud network. In scenarios where a messaging protocol needs to be lightweight, with low bandwidth, low power consumption, and real-time data exchange MQTT fits the mold.

Class on Friday 1/02/2025                                                                                                                            

In the first class, we used BeeBotte as our MQTT broker to connect to a client app, a DFRobot Cloud Board V1, and micro:bits. The goal was to follow the design pattern given by Jason, replicating the MQTT architecture in the above diagram. 

On Start

The code below was used to connect to the CloudBoard to get wifi to set up the communication through the cloud. The cloud board was configured with the MicroIOT extension to setup the connection with the broker. The BeeBotte broker has its own public and secret key, gaining access to the broker and its topic. 



On Radio Received
Looks out for any values from any client micro:bits on the same radio signal to take the message and publish it to the BeeBotte broker.

Analog Output
Once the MQTT message is received from topic one subscription, the function below parses the message to be sent to the output Id.




The Client Micro:Bit:

The client micro:bit communicates to the Cloud micro:bit through radio, in this case both are on the same signal ("9"). The on radio received function contains two if loops, the first one is for receiving messages from the subscribed topic outputs t, and the input if statement that is publishing data to the MQTT broker. This is the client code for the #2 Microbit client. The gyroscope is used for testing purposes to publish data to the broker.




 

IoT MQTT Panel (Client App):



Screen-Recording-02-07-202513-ezgif-com-video-to-gif-converter


                                                                  


Following on from using AI/AO with MQTT, the next step in the design pattern was to learn about IFTTT aka IF this then that, and implement a use case that uses the IFTTT service.

What is IFTTT?
IFTTT is an automation platform that connects apps, devices, and services using event-driven workflows called applets. It operates using RESTful APIs, webhooks, cloud computing and event-driven architecture to trigger actions based on predefined conditions. It uses OAuth for authentication, serverless functions for execution, and databases for storing user configurations.

What was achieved:
I downloaded the app IFTTT, it has a free tier but to get access to using other services like Webhook I upgraded my plan to pro. I created an applet using webhooks, that was triggered when a one of the buttons on my microbit was pressed, leading to the email event, sending an email to my gmail account.

What is a webhook? 
A webhook is a lightweight, event-driven communication that automatically sends data between applications via HTTP. A webhook is triggered by specific events, like in this case the button on a micro:bit being pressed.


Microbit Code
Using the IoT_Cloud_Kit extension I setup a connection to a hotspot, and using my IFTTT applets event name "input" and secret key, to connect to my applet using webhooks. 



To trigger the webhook to begin the event, button A on the micro:bit had to be pressed that would make the IFTTT send function trigger the webhook, sending an email every-time the button was pressed.


Problems faced:

The largest obstacle was trying to get the micro:bit to be the one that triggered the event. I spent some time trying to figure out why my code wasn't working even though the logic was correct, I was looking at past iterations from previous years students who also were using a micro:bit to trigger an IFTTT event, but had no look. Eventually I was able to figure out the issue was caused by the IoT extension.

So I went searching for new extensions to use instead of the original one that was causing issues.

Old IoT extension used








New and Improved




The new extension allowed me to trigger the applet event with zero issues whilst also cutting down the amount of code needed at the same time making it easy to pickup, for anyone to use.

Future Use Cases

Use a soil moisture sensor with the micro:bit to check when a plant needs watering. When the moisture drops below a certain level, the micro:bit sends an MQTT message to the cloud. That message can then trigger an IFTTT applet to send an email or phone notification, reminding you to water your plant.

Set up multiple micro:bits with basic motion sensors around a room. When movement is detected, one of them publishes a message to an MQTT topic. IFTTT can then log the event in a Google Sheet or send a notification if motion is detected during unusual hours (e.g., at night).

Comments

Popular posts from this blog

Blog 2 - HRV Demo

Week 1: HRV Review

Blog 5 - FFT & HRV