Connect ESP32 to Qubitro with MicroPython

4 min readMay 19, 2022


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 and download the appropriate platform-based file and install it on your pc.

Thonny IDE web page

After that, download the ESP32 micropython firmware file. Go to, then download the latest version.

Micropython Firmware

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.

esptool package on Thonny

Now go to Run > select Interpreter, select Micropython(ESP32), and the COM port.

Select Interpreter Tab

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.

Firmware install window

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.

Open device page

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 file. This only runs once the device is booted up.

import time
import network
import machine as m
sta_if = network.WLAN(network.STA_IF);
sta_if.scan() # Scan for available access points
sta_if.connect("SSID", "password") # Connect to an AP

We have to add our Qubitro Credentials in the code; this will run once the runs; refer to my previous tutorials to set up the Qubitro and for Credentials.

from umqtt.robust import MQTTClient
import machine as m
from machine import Pin
DeviceID = ""
DeviceToken =""
client = MQTTClient(DeviceID, "", 1883, user = DeviceID, password = DeviceToken)def checkwifi():while not sta_if.isconnected():
def publish():
while True:

msg = b'{"Latitude": 72.7661 ,"Langitude": 337.7772, "Temperature": 27, "Humidity": 76}'
client.publish(DeviceID, msg)


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.

Rak11200 data in Qubitro 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.




Infrastructure for the Internet of Things solutions. Build connected solutions faster than ever.