After deciding to no longer use XinaBox to send data from the MicroBit to the cloud, I began exploring the possible route of Beebotte, a publish/subscribe IoT platform.
Beebotte is a platform that provides key building blocks to power Internet of Things (IoT) and real-time connected applications. A rich and easy to use API accelerates the development of connected applications and reduces the total cost and time to market.
To use Beebotte alongside the MicroBit, I needed DFRobot's micro:IoT expansion board. This expansion board comes with its own MakeCode extension, microIoT, which allows for easy setup and communication. Along with the MakeCode extension, the board has an OLED screen, power supply by li-ion battery or external power, and an Integrated Wi-Fi IoT module.
MQTT
The MicroIoT extension has a block specifically designed for MQTT communication, however, the dropdown menu for selecting which server you wish to send to does not display Beebotte. To find this dropdown option, I had to edit the following example code:
https://makecode.microbit.org/60567-20847-65333-03214
Once opened, the MakeCode extension was automatically installed and I was then able to select the Beebotte server. You must also set up your Wi-Fi connection and configure the rest of the MQTT setup as follows:
IOT_ID:
After creating your Beebotte account, the IOT_ID can be found under the heading Account Settings -> Access Management -> API Key.
IOT_PWD:
The IOT_PWD is referred to as the Secret Key which can be found on the same page as the IOT_ID.
Topic:
Your topic is the name of your Channel followed by the name of the Resource you wish to use, separated by a forward slash, for example:
The "subscribe additional" MakeCode block allows for the addition of more topics.
The MQTT setup block should look similar to the image below when complete, along with the Wi-Fi setup.

Once the MQTT settings were configured, I was then able to focus on the main task, sending data to Beebotte.
The MakeCode message block would only allow me to send data in the form of Strings. From the dropdown menu, I chose topic_0 as the Topic to send my data.
I downloaded the code onto my MicroBit and turned on the power button on the DFRobot expansion board. Once powered, the network light flashed from red (failed to connect) to blue (connecting to WiFi), to green (working properly). This connection took approximately 6-7 seconds. However, shortly after connecting to the network, the network light changed to purple, meaning the MQTT had disconnected and messages were not sent. I could not understand what the issue was and spent hours rearranging my MQTT setup configurations.
After some time, I realised my DFRobot expansion board was not getting enough power. The rechargeable battery that came with the board needed to be recharged. My project lead Jason loaned me a brand new 3V battery to use while my other battery charged. This gave the board enough power to successfully send the MQTT message, "hi" to Beebotte.
However, when I attempted to swap out the String "hi" for the value "22.1" (still a String), Beebotte was unable to read the incoming message as expected but instead as "[object, Object]", a string version of an object instance.
Having run into a similar issue on a previous project, Jason decided to try an app, IoT MQTT Panel, that allows you to manage and visualise IoT projects, based on MQTT protocols.
First, we edited the connection to include:
Broker Web/IP address: mqtt.beebotte.com
Port Number: 1883 no SSL, 8883 with SSL
Network Protocol: TCP
Then under "Additional options", we set the Connection = 30 and the Keep alive = 60.
The Username and Password are both set to the Channel Token, which can be found within your chosen channel on Beebotte.
From here, I was able to re-configure a dashboard Jason previously made by changing the topic to microbit/current. This panel was able to display the value in the correct format from Beebotte.
So despite the Beebotte dashboard being unable to display the values, they were still visible on the MQTT app. This meant I could ignore the datatype issue on Beebotte.
Next, I wanted to send the message to make it usable for all widgets on the IoT MQTT panel. To do this, I needed to send the data in the form of a JSON String. For a more detailed explanation of the JSON String format, check out this document created by the Applied Robotics Lab 2021.
After reading this document, I knew to send the data in the format: {"011ai1": VALUE, "is public":true}, replacing "VALUE" with the data I wanted to send. As we were looking to send the value directly from USV, I set the radio group to 1 and listened for certain names and values.
Sending the data in this format meant I was then able to edit some of the panels by ticking "Payload is JSON Data" and setting the JsonPath using a $ and the "name" section of the JSON String, i.e. 011ai2. (first image below)
This allows the graph to read that section of the incoming message and decipher the value.
The second image below shows the full dashboard on the IoT MQTT Dashboard app that we configured to display the live voltage and current values from the USV.
As I don't have an Android phone, I was unable to use the IoT MQTT app as it's only available for Android users. I searched and found an IOS alternative, IoT OnOff. This app does not have as much flexibility as the Android app but it did allow me to display the incoming messages from the USV.
I first set up the MQTT configurations as follows:
I then added a simple message widget and set it to subscribe to the topic: microbit/current.
Once connected to the MQTT broker, the raw messages from the microbit would appear in the message box.
After successfully sending messages from the USV all the way to the phone we wanted to send messages back to the USV.
To do this we added two slider widgets to the IoT MQTT Dashboard, left thruster and right thruster. We used a new topic, test/test, and set the JSON path of the left thruster to "left:<slider-payload>" and the right thruster to "right:<slider-payload>", with a payload of 80-100 to monitor the USV motors and prevent them from splashing water all over the lab.
We ran into issues again with Beebotte expecting Strings and displaying [Object, object]. however, after trial and error on the MakeCode side of things we managed to successfully control the motors via the slider on our phones.
Access to my full code is available here
Comments
Post a Comment