In this tutorial, I will show you how to use Qubitro MQTT in MicroPython firmware. The idea is to exchange sensor readings or commands to Qubitro Cloud via an MQTT connection.
Things that you need:
Let's Install MicroPython on Rak11200:
First, you need to install Micropython IDE to work; go to https://thonny.org/ and download the appropriate platform-based file and install it on your pc.
After that, download the ESP32 micropython firmware file. Go to https://micropython.org/download/esp32/, then download the latest version.
Once you have installed the Thonny IDE, connect your RAK11200 to the pc. Then open up the IDE, go to the Tool > Manage Packages, type 'esptool' in the search bar and click install.
Now go to Run > select Interpreter, select Micropython(ESP32), and the COM port.
Next, select 'Install or update firmware' and then select the COM port and select the downloaded firmware file, Then hit install, wait until the process completes.
So, now your Rak11200 is ready to run with Micrpython. Let's do some code…
Download the below git repo into your pc; this repo contains the sample code and library for the MQTT connection.
Now open up the Thonny IDE and connect your Rak11200 with pc, then click Open Icon and select from Micropython option.
And create a folder with the name of lib; inside this folder, we will add our MQTT Library files. Follow this below folder structure.
Change the SSID and Password according to your Wi-Fi Credentials. Create new files based on the structure and replace the codes (from the above git repo). Then open the boot.py file. This boot.py only runs once the device is booted up.
We have to add our Qubitro Credentials in the main.py code; this will run once the boot.py runs; refer to my previous tutorials to set up the Qubitro and for Credentials.
Change the Device ID & Token according to yours. I have sent some dummy sensor values in the JSON format and added LEDs to blink whenever the data is published.
Once you complete all the above steps, we are now to get into action. Click the Run icon.
Ta DA 😃 !!! You can see the payloads in the Terminal Window. Then open up your Qubitro Portal and navigate into the device page and let's observe the readings. You can see all the readings in the portal.
Now you can add some sensors to the RAK11200 and send some values to Qubitro. That's all about this tutorial, Let's do some cool projects, and don't forget to share with our community and Discord Channel.