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]
Once this PuTTY is configured correctly you can start a new serial window and watch as the Microbit serial writes data.
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.
Standard delay time.
All pauses in the system are now set to the delay variable.
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.
- 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.
- LEDS on the fifth row are used for MQTT and radio comms. (labeled in the diagram below)
- This leaves two rows free for any other debugging that will be necessary in the future.
- A slider was set up in the app that published a JSON string to beebotte every time the slider value was moved and released.
- This was recognized by the cloud boards on MQTT topic1 recieved message.
- 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.
Friday 15th March:
A good example of this is sending an email using the microbit and 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
Post a Comment