MQTT Panel to Beebotte to USV - Kevin Power #11

 Introduction

After deciding against moving on with Ubidots, I moved on to working with the team working on sending messages from Beebotte to the USV via MQTT.  The team already had a message going from the Microbit to Beebotte and now it was time to go in the other direction. This blog is going to be formatted more like a tutorial for anyone to set this up.

Requirements

The requirements to get this connection working are as follows:

  • An Android Phone with IoT MQTT Panel installed
  • DFRobot's micro:IoT expansion board
  • A Microbit
  • A Beebotte Account
Once all the above requirements are met, we can start exploring how we connected Beebotte to the Microbit and then to the USV.

Beebotte

The first aspect is to get the DFRobot's micro:IoT expansion board set up. This board comes with its own Makecode extension called, microIoT. We need to install this into Makecode, to do this, go onto Makecode and create a new project. Once a new project is created, click on the extensions button.




That will lead you to the extensions search page. Search for microIoT and install it into the project. This will bring all the required Beebotte blocks into the project.




The MicroIoT extension has a block that is designed for MQTT communication, this is what we are going to use. However, there is an issue with this, when you use the dropdown for selecting which server you would like to use, it does not display Beebotte. To get this part to work I asked my teammates and they directed me to this code: https://makecode.microbit.org/60567-20847-65333-03214

Once you open this code, the extension gets automatically installed into the project and you can now select the Beebotte server. 

Microbit

Once you have the extension downloaded and the code brought in, it's now time to set up the Microbit and the code itself. 




The first part is to fill in the name and password for your wifi, make sure you do the correct capitalization on these. Once that's complete it is time to set up the MQTT connection. Firstly you need the IOT_ID and IOT_PWD these are the API Key and Secret Key from your Beebotte account. You can find them under Account settings on your Beebotte page. 

Once found you can put the API Key in for the IOT_ID and the Secret Key in for IOT_PWD.

Lastly, you need to set up the topic. The topic is the name of the channel and resource you wish to subscribe to. The way you write it is the channel name/resource name. i.e. if I had a channel on Beebotte called test and a resource on that channel called humidity I would write "test/humidity" as the topic name.


After this is all configured, we can move on to actually retrieving data from Beebotte and displaying it.
 



For this, we need to use the on message receive Makecode block. For this, you must select the topic, in this case, we use topic_0. This block will do the code contained inside it whenever a message is sent to topic_0. The OLED show line block will display the message received on the OLED screen on the Beebotte board. 

Next, I had to figure out how to actually send messages to the board and how to handle them once they are received. 

IoT MQTT Panel

The project manager Jason, directed me towards an application on my phone that is great for sending and receiving MQTT messages, IoT MQTT Panel. To set up the application on my phone I followed the steps from this document: https://docs.google.com/document/d/1PxXp2bGaUuDzbLyhKY6jMyAM1dzsvUHl/edit?usp=sharing&ouid=109077347921210322893&rtpof=true&sd=true

I went to part 4.0 Check board connection to Beebotte MQTT broker where it describes how to download and set up the app. 


I created a new connection with the following details: 

Broker Web/ip address mqtt.beebotte.com
Port number: 1883
Network protocol: TCP
Select additional items, then fill in these values
Username:  token_2F8Fe1gxYIbVpZbr
Password(same):   token_2F8Fe1gxYIbVpZbr

The token is the channel token on Beebotte. It then brings you to a panel you can edit, I added in a few text logs and a slider. In this blog, we are going to look at setting up the slider to allow us to send values to the Microbit.

I created two sliders and named them Thruster Left and Thruster Right. I set the topic to test/test and the jsonpath to: left:<slider-payload> for the left thruster and right:<slider-payload> for the right thruster. Next, I set the min payload to 80 and the max to 100. This was to prevent the motors on the USV from spinning too quickly.

This step took a lot of debugging to get working, we figured out that if we don't use strings, on Beebotte the data will come up as [Object, object] which helped manage a lot of errors, and from that point it was a lot of trial and error with the different Makecode script before eventually, we got a full end to end connection from Beebotte to our USV.

The code for the final version can be found on my Github here: https://github.com/Kevin3099/BeebotteRecevingValuesFromMqttBroker






















Comments

Popular posts from this blog

How to: Tello drone to micro bit - Victor Alikberov, Blog#1

Colour Tracking With OpenCV - Jack Pender, Blog #4

Tello and OpenCV - Jack Pender, Blog #3