Blog 4 - Micro: Bit to MQTT Codebase & IFTTT


 


Monday class 4/03/24

Got MQTT working with android Hotspot

The class also had trouble looking at data that was being printed to the makecode website because JSON messages would cut off or lose characters.

In order to get around this Putty was used to view the serial comms.

In order to see this data at a faster rate than the web browser the Serial option of putty has to be selected along with two other variables:

  • The comm port the Micro bit is on. This can be found by going into windows "device manager" and selecting the ports drop-down menu in this instance it is USB Serial Device (COM12).


  •  Speed/baud rate being changed to match the clock of the micro bit, in this case it is 115200. [1]

Example setup


Once this PuTTY is configured correctly you can start a new serial window and watch as the Microbit serial writes data.


Rotation data being serially printed in PuTTY

 

Monday Class 11/03/24

New features:

Made Functions to reduce code quantity.

I Reduced the amount of repeated code by making the sendToNode function which lets users specify what input and value to send to and what LED's should correspond to that particular node.

Also moved the JSON parsing code into its own function along with making another function that prints the MQTT message to the serial console.


New functions
Implementation of sendToNode


Standard delay time.


All pauses in the system are now set to the delay variable.


By doing this it allows users to change how fast or slow messages can be sent/received making this variable act as a "clock" for the system.

This variable seems insignificant when you look at the entire code base but its important to note that there is still a limited amount of messages (50,000) that can be sent daily to Beebotte so the slower this clock is the less messages that will be sent which translates to money saved in industry.

Note:

It is also useful for testing how different speeds effect the system. 

Delay variable and implementation.

It would be interesting to see a feature that would change the clock speed based on how many nodes were connected at one time a good way of doing that could be to add each node to an array and get the length of that array and multiply by the amount of time per node.

Example of Dynamic time scaling feature.


LED Matrix display:

Now that the codebase has been cleaned by making different operations into their own functions it is easier to distinguish what is happening by using the LED Matrix as a reference

Breakdown:
  1. LEDS on the first two rows are a good place to keep the Node LED's because class size is 7 this leaves room for 3 extra nodes if needed.
  2. LEDS on the fifth row are used for MQTT and radio comms. (labeled in the diagram below) 
  3. This leaves two rows free for any other debugging that will be necessary in the future.


New LED Matrix outputs



MQTT App:

Another feature that was implemented Monday was MQTT to microbit communication, 
This was done by using the IoT MQTT Panel app.

A slider was set up in the app that published a JSON string to beebotte every time the slider value was moved and released.

  1. A slider was set up in the app that published a JSON string to beebotte every time the slider value was moved and released.


  2. This was recognized by the cloud boards on MQTT topic1 recieved message.
  3. The JSON parsing function would then be called and would parse this slider values JSON string and extract the output_id and output_value and send them both over the radio network.
  4. Then once the extracted JSON string has been sent over the radio network the node microbit with the corresponding ID number would notice this and print the value of the slider.

Friday 15th March:

On Friday the class focused on setting up IFTTT with the DFRobot cloud board.
The following code sends an IFTTT post request using button A on the microbit.


Once button A is pressed the server microbit sends a post to the IFTTT applet that has been pre-configured and does whatever action was selected from the app.


A good example of this is sending an email using the microbit and IFTTT
IFTTT email sent from Hasan's email to Jason and IoT 4 class.

This new feature unlocks a lot of use case potential because of how vast IFTTT's services are the applications can be anything from emails sending automatically or having LED's turn on and change brightness based on a value like HRV.

The IFTTT website shows various different features that can be implemented using its services

An example of a IFTTT applet. 
This is a service they do with X (Twitter).
With this applet configured, every time you tweet you can trigger a micro bit action.
On Tweet!

If this technology stack were to be fitted to the HRV project it would be possible to have a HRV change the brightness/color of a light bulb based on a users HRV levels. Paired with sonification using band lab the project will look and sound like a simulated heart using and everyday "Thing" such as a light bulb or a dial to show how high or low your HRV level is. 


Dimming a light using IFTTT.

Setting a dial to a value using IFTTT.










References:

[1] https://lancaster-university.github.io/microbit-docs/ubit/serial/#:~:text=By%20default%2C%20the%20baud%20rate%20for%20MicroBitSerial%20is%20115200%20and%20has%20very%20little%20overhead%20up%20until%20it%20is%20used%20to%20send()%20or%20read()%2C%20at%20which%20point%20buffers%20are%20allocated%20in%20order%20to%20accommodate%20incoming%20or%20outgoing%20data.




Comments

Popular posts from this blog

Iteration 2 | Jack | HRV Micro:bit Research

Iteration 5.2 | Lock In | Jack

Week 1: HRV Review