Qubitro is a Device Data Platform (DDP) that aims to simplify IoT development and enable collaboration on-device data and modern applications. Qubitro provides a comprehensive platform that offers tools, services, and infrastructure to streamline IoT application development. Some of the features of Qubitro are
- It supports various protocols such as MQTT and HTTP for connecting IoT devices.
 - It allows users to manage their devices and projects in one place, and integrate with various cloud services and platforms.
 - It delivers device data anywhere it’s needed and enables users to build robust applications and services using Qubitro APIs and SDKs.
 - It offers a free platform credit, instant support, co-marketing and sales opportunities, and exposure to a global ecosystem for startups.
 - It helps enterprises and integrators solve business problems with device data, grow revenue, and scale further without complexity.
 
Qubitro is built for a hyper-connected world and aims to democratize IoT development and make it accessible to everyone.
In this tutorial, we will learn how to connect an M5StickC board to Qubitro using the MQTT protocol and monitor the temperature and humidity data from a BMP280 sensor.
- M5StickC development board
 - A BMP280 sensor unit
 - Grove wires
 - Arduino IDE
 - Qubitro account
 
First, you need to create a Qubitro account if you don’t have one already. Go to the Qubitro website and click on the “Sign Up” button. Enter your full name, email address, country, and password to create your account.
Once logged in, you will be prompted to create a project. Enter a name and a description for your project. For example, I named my project “M5StickC_BMP280”.
Next, you need to add a device to your project. Go to the project page and click on the “+ New Source” button.
You will see many options for the communication protocol: LoRaWAN, MQTT, and Cellular. Choose MQTT for this tutorial.
Then, enter a name and a description for your device. For example, I named my device “M5StickC_BMP280_Device”.
Finally, you will get the credentials for connecting to the Qubitro MQTT broker. You will need the device ID, device token, and the broker address and port. Copy and save these credentials for later use.
The BMP280 sensor has four pins: VCC, Data, Clock, and GND. Connect the grove cable with BMP280 and M5StickC board, these grove wires make the connections easier.
To communicate with the Qubitro MQTT broker and the DHT11 sensor, we must install two libraries: QubitroMQTTClient and Adafruit_BMP280. You can install them from the Arduino IDE by going to Sketch > Include Library > Manage Libraries. Search for QubitroMQTTClient and Adafruit_BMP280 and install the latest versions.
Open a new sketch in the Arduino IDE and copy the following code:
In this code, you need to replace the Wi-Fi and Qubitro credentials with your values.
#include <M5StickC.h>
#include <Adafruit_BMP280.h>
#include <QubitroMqttClient.h>
Adafruit_BMP280 bme;
#define USE_SSL 1
#define PERIOD 5000
#ifdef ARDUINO_ARCH_ESP32
#include <WiFi.h>
#if USE_SSL
#include <WiFiClientSecure.h>
WiFiClientSecure wifiClient;
#else
WiFiClient wifiClient;
#endif
#else
#include <WiFiNINA.h>
#if USE_SSL
WiFiSSLClient wifiClient;
#else
WiFiClient wifiClient;
#endif
#endif
QubitroMqttClient mqttClient(wifiClient);
// WiFi Credentials
char ssid[] = "ELDRADO";
char pass[] = "amazon123";
char deviceID[] = "6c4f4580-6f30-4ad4-8ae4-08ced9062e20";
char deviceToken[] = "mqXPHE2BkU4aX4I5D5XJTzegLsqnUDM-fXTiRTKX";
const char host[] = "broker.qubitro.com";
int port = 1883;
unsigned long next = 0;
void setup()
{
  // Initialize serial port
  Serial.begin(115200);
  while (!Serial) {
    ;
  }
  // connect to Wifi network:
  Serial.print("Connecting to WiFi...");
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED)
  {
    Serial.print(".");
    delay(1000);
  }
  Serial.println("\tConnected to the WiFi !");
  // You need to provide device id and device token
  mqttClient.setId(deviceID);
  mqttClient.setDeviceIdToken(deviceID, deviceToken);
  Serial.println("Connecting to Qubitro...");
#if USE_SSL
#ifdef ARDUINO_ARCH_ESP32
  // Remove if cert verification is added
  wifiClient.setInsecure();
#endif
  port = 8883;
#endif
  if (!mqttClient.connect(host, port))
  {
    Serial.println("Connection failed! Error code = ");
    Serial.println(mqttClient.connectError());
    Serial.println("Visit docs.qubitro.com or create a new issue on github.com/qubitro");
    while (1);
  }
  Serial.println("Connected to the Qubitro !");
  mqttClient.subscribe(deviceID);
  M5.begin();             // Init M5StickC.
  M5.Lcd.setRotation(3);  // Rotate the screen.
  M5.Lcd.fillScreen(BLACK);
  M5.Lcd.setTextSize(1);
  M5.Lcd.setTextColor(TFT_GREEN, TFT_BLACK);
  Wire.begin();  // Wire init, adding the I2C bus.
  while (!bme.begin(
           0x76)) {
    M5.Lcd.println("Could not find a valid BMP280 sensor, check wiring!");
  }
  M5.Lcd.fillScreen(BLACK);  // Clear the screen.
}
float pressure,
      Temp;  // Store the vuale of pressure and Temperature.
void loop()
{
  pressure = bme.readPressure();
  Temp     = bme.readTemperature();
  M5.Lcd.setCursor(0, 0);  //Set the cursor to (0,0)
  M5.Lcd.setTextSize(2);   //Set the font size to 2
  M5.Lcd.printf("Pre:%2.0fPa\nTem:%2.0f^C", pressure, Temp);
  delay(100);
  mqttClient.poll();
  if (millis() > next) {
    next = millis() + PERIOD;
    // Change if possible to have a message over 256 characters
    String payload = "{\"Temperature\":" + String(Temp)
                     + ",\"Pressure\":" + String(pressure) + "}";
    mqttClient.beginMessage(deviceID);
    // Send value
    mqttClient.print(payload);
    mqttClient.endMessage();
    Serial.print("Publishing new data-> ");
    Serial.println(payload);
  }
}Step 5: Upload the Code and Test the ConnectionSelect the correct board and port from the Tools menu and upload the code to the M5StickC board. Open the serial monitor and check if the Wi-Fi and Qubitro connections are successful.
You should also see the sensor readings in the Qubitro portal.
To visualize the data from the M5SticC board, we can create a dashboard on the Qubitro platform. Go to the project page and click on the “+ New Dashboard” button. Enter a name and a description for your dashboard. For example, I named my dashboard “M5StickC_BMP280_Dashboard”.
Next, you need to add widgets to your dashboard. Click on the “+ Add Widget” button
and choose the type of widget you want.
For this tutorial, we will use two-gauge widgets to display the temperature and pressure values. First name the widget and select the data points from your project.
For each widget, you need to enter a name, a description, a unit, a minimum and maximum value, and a color. You also need to select the device and the topic that the widget will subscribe to. For example, for the temperature widget, I entered the following settings:
For the pressure widget, I entered the following settings:
After adding the widgets, you can see the dashboard with the live data from the M5StickC board.
In this tutorial, we learned how to connect an M5StickC board to the Qubitro IoT platform using the MQTT protocol and monitor the temperature and pressure data from a BMP280 sensor. We also learned how to create a dashboard and visualize the data on the Qubitro platform. You can use this tutorial as a starting point for your own IoT projects and explore the features and capabilities of Qubitro.
I hope you liked this blog post. If you have any questions or feedback, please let me know. 😊












Comments