Iteration 4 | Jack | Cloud, MQTT, IFTTT

 Iteration 4 - Cloud, MQTT & IFTTT

MQTT Architecture

Above is a custom diagram I made of the MQTT architecture / design pattern we'll be using for our project. I'll explain in detail the function of each step.

  • The DFRobot Cloud Board v1 is the heart of our system. 

Compatibility Issues

The first week of this iteration was plagued with issues. Frustrating as it was, it was a great learning experience that helped us identify certain issues, what causes them, and of course how to solve them. Having a broad understanding of a plethora of potential problems is vital, allowing for efficient dealing of said problems in a demo scenario.

Probably the biggest issue we encountered was related to the WiFi hotspot. Of the 7 of us in the class, 6 have iPhones and only 1 had an Android. After a significant amount of time and frustration, we discovered that the Cloud Board v1 couldn't adequately maintain connection when connected to an iPhone hotspot. We're still not fully sure what the problem is - perhaps the fact that iPhone hotspot uses IPv6 instead of v4, but once we identified the issue, we were able to solve it by using an Android hotspot instead.


It's worth noting that we discovered that running a hotspot from one's laptop was also acceptable*, in the event an Android phone is not available.
* The connection quality with the laptop hotspot was lesser than that of the Android. This could be due to the Eduroam WiFi network, which uses IPv6 and has been known to cause problems in the past. As it stands, the WiFi hotspot quality order is as follows:
πŸ”΄ iPhone - doesn't work
🟑 Laptop - works, but intermittent connection
🟒 Android - works, much more consistent connection

ANDROID PHONE x CLOUD BOARD V1

Start-Up Sequence 🚦

We devised a "Start-Up Sequence" to refine the process of setting up the MQTT connection.

  1. Android Hotspot ON πŸ“±πŸ“Ά
  2. Turn ON the Cloud Board ☁️🚨
  3. Look for the Green Light on the Cloud Board ☁️🟒
  4. Wait for the Heart to display on the Cloud Board LED Matrix πŸš¨πŸ’–
  5. Connect the Client Micro: Bit πŸ”—πŸ“Ÿ
  6. Verify Connection (Correct LEDs Showing) 🚨✅
  7. Go to Phone Client πŸ“ˆπŸ“Š

Cloud Board LEDs ☁️🚨

As well as this, we did some research to figure out what the different LED colours mean on the Cloud Board. Understanding this could be vital when it comes to debugging.
πŸ”΄ No WiFi Connection - check the connection between the Cloud Board and the Android Hotspot, verify the username and password is correct, and the hotspot is on.
πŸ”΅Connecting - The Cloud Board is attempting to connect to the WiFi. This process usually takes 3-10 seconds.
🟣 MQTT Disconnected - The Cloud Board has WiFi, but is unable to connect to the MQTT Broker, which in our case is Beebotte. Verify that the API keys are correct, the Beebotte service is up, and usage is under the limit.
🟒 Connected - All is good and ready to go.

The Cloud Board connected, signified by green LED 🟒

The Cloud Board attempting to connect, signified by blue LED πŸ”΅



On Friday the 8th, we were without Adam, who had the most knowledge and experience when it came to this design pattern. This left us with a decent challenge of trying to get back to where we were the previous day without his help.

1. Get back to where we were on Monday

What did we do?

Got everything hooked back up. Got line graph and gauge.


On Monday the 11th, we kicked off the 3rd week of this iteration - our longest so far. For this class, we refined our code, making use of functions and improving the readability of the LED matrix.

Shown above is the entire code, which I will now break down and go into detail about.

on start

This is the setup function for the Cloud Board. It begins by simply displaying the string 'server', to reduce the chance of Micro: bit confusion.

It extensively uses the Micro:IoT extension, initially to configure the Wi-Fi hotspot, and then to setup MQTT using access keys.

Once the Beebotte access keys are inputted, you add the topics in the format "Beebotte_Topic/Resource", i.e. USVSensorPod/temp. (USVSensorPod is a preconfigured Beebotte topic we're using to test.

When all's working as intended, the radio group is set and a heart is displayed on the LED matrix.

forever

This forever loop simply calls the sendToNode function, and passes in the desired arguments. I'll showcase the sendToNode funciton in mode detail shortly.

MQTT on <topic_1> received <message>

This block of code runs whenever an output message is received by the Cloud Board from the MQTT client - for example when an output is sent via the slider on the MQTT mobile phone application. It then calls two functions: parseJsonMessage and serialPrintMQTTMessage.






on radio recieved <name> <value>

This block runs whenever the Cloud Board receives a radio signal from one of the client Micro: bits. The clients must be on the same radio group as the Cloud Board server.

The server then sends a JSON string using MQTT to the input topic, and toggles the bottom-most right LED to signify this successful message send.




function <sendToNode>

This function possesses 4 parameters:
- The input number to send to
- The value to send
- The x coordinate to toggle
- The y coordinate to toggle














IFTTT (IF THIS, THEN THAT)

IFTTT stands or "If This, Then That". Basically, when certain conditions are met, then something else will happen.
  • IF This - Trigger
  • Then That - Action
An example of this could be, say you have a security camera, and some smart lights. One could set up an IFTTT task so that when the security camera detects movement, it automatically turns on your home's smart lights, to repulse any potential intruders. The camera's motion sensor is the trigger (If This), while the lights turning on is the action (Then That). ref



IFTTT was created in 2010, launched into the IOT space in 2013, and was worth ~$170 million by the end of 2014. ref



We saw IFTTT as the next step in this iteration, throwing humorous yet interesting ideas around like getting your heart to order you a pizza. We went into Friday 15th March's class with the plan of getting IFTTT setup and working in some form.

Step 1 was to download the IFTTT app, available on iOS and Android devices. We also needed to buy a subscription to access the full array of features. Hasan volunteered to be the test subject, and bought the IFTTT premium on a trial basis.

We tested IFTTT by configuring the Micro: Bit to send a webhook to Hasan's IFTTT applet. It appears to work similar to a HTTP POST request, which I'm already familiar with. Whenever Button A is pressed, this essentially triggers the Applet (or IFTTT function) on Hasan's iPhone, which he can configure to do whatever he wants.


Connection with the IFTTT app is established by means of an API key, which we added to the On Start code block.

I was able to acquire some screenshots of Hasan's IFTTT app setup, since he's not here this week.
First up, you can see the Applet we created. The trigger (If This) is a webhook, activated by the Micro: Bit's POST request, laden with a JSON payload. The actions (Then That) are multiple, both sending the email you will see below, and starting playback on Hasan's Spotify.




Below is the full configuration:




Hasan configured the Email action to send an email to our whole group, and Jason, letting him know we'd got IFTTT working and to come into the room for us to show him.

IFTTT Brainstorm

We were sent off on Friday with the task of researching possible use-cases for this IFTTT technology combined with Micro: Bit in relation to HRV, as well as from a general IOT Applications standpoint.

From what I've seen, this technology is heavily targeted towards those looking for task automation, especially those with an internet presence, like content creators and online educators.
There's a page entirely dedicated to cross posting, where a manual post to one platform acts as a trigger for IFTTT to post to other platforms. Examples include, uploading a YouTube video, and having it automatically post to Discord too, or a blog-poster having their latest blog entry uploaded to LinkedIn.




I'm not sure how useful this is for our HRV use-case, but another idea popped into my mind while researching. 

There's IFTTT integration to Google sheets (similar to MS Excel), with a specify action for adding a row to a spreadsheet. Think if your doctor wanted to keep track of HRV spikes/drops, you could configure logic to add an entry to a spreadsheet whenever such an event happens.

Obviously there's many other use-cases for such an action in IOT generally, such as general logging, or anomaly detection, or error logging.




In the class last week, we came across the IFTTT integration to smart light bulb product, Phillips Hue. We discussed the idea of having a "pulsing lightbulb", in accordance with one's HRV value. In IOT, such a technology could be used for literally anything, a warning light, an 'idea' bulb, a mood indicator, or a temperature indicator with the Micro: Bit temp sensor. The possibilities are virtually endless.


I think something interesting for us to do could be to create one of these blog posts using the Micro: Bit and IFTTT.

IFTTT has blogger integration, making such an idea possible.











Other fun and interesting IFTTT use-cases include:
Planting a tree upon an action. Whenever you turn on your car, you plant a tree πŸ˜†


Monitoring one's temperature while sleeping, and adjusting the room temperature in accordance.

I found that Fitbit is already connected to work with Google Spreadsheets through IFTTT!





One not super-relevant one that I came across and simply had to add in was the ability for IFTTT to send you a notification whenever the International Space Station passes over your house. For space lovers like myself, that would be an awesome little mood boost, and would surely bring a smile to my face.










We've got Technical Up ⬆️ working, getting IFTTT from the Micro: Bit to the outer world, now let's try and see about Technical Down ⬇️, getting the outside world to interact with the Micro: Bit.


























Comments

Popular posts from this blog

Iteration 2 | Jack | HRV Micro:bit Research

Iteration 5.2 | Lock In | Jack

Week 1: HRV Review