Publish Data from BOSCH XDK to Qubitro IoT Platform

Qubitro
4 min readMay 10, 2022

--

Publish built-in sensors’ BOSCH XDK data to Qubitro IoT platform through MQTT protocol.

In this tutorial, we’re going to learn how to publish sensor readings from XDK BOSCH to the Qubitro IoT platform through the MQTT protocol.

Qubitro is the fastest way to build IoT applications with predictable pricing, developer-friendly features, and scalability you’ll love. You can connect your hardware to Qubitro, collect the data and create data visualization on your dashboard. For more information about Qubitro, you can check its official site: qubitro.com.

We will use the BOSCH XDK, an all-in-one IoT solution from BOSCH based on a 32-Bit microcontroller (ARM Cortex M3) with Bluetooth 4.0 low energy, Wireless Local Area Network, and an Internal Lithium-Ion battery. It also has several built-in sensors like an accelerometer, gyroscope, magnetometer, temperature sensor, air pressure, humidity, and light sensor. For more information about BOSCH XDK, you can check its official site: developer.bosch.com.

To follow this tutorial, here are the requirements:

  1. Qubitro account, create here for free: click here
  2. BOSCH XDK110 device, specification: click here
  3. XDK Workbench, download for free: click here

Step 1. Create Qubitro Project

Signup or login to Qubitro Portal, then create a new project. Click the New Project button, add the project name & description, then click Create Project button.

Create a project on Qubitro

Then create a new device inside your project. Choose your device connectivity method, in this case, MQTT. Then enter device details from the name, description, brand, model, and location.

Create a device on Qubitro

After that, you’ll get your credentials (host, port, username, password & clientId) to connect to the Qubitro MQTT broker. Please note these values because we’ll use them on our code later. You can check these values on the device Settings menu. Your username & clientId are your Qubitro Device ID, and your password is your Qubitro Device Token.

Qubitro MQTT credentials

Step 2. Code the BOSCH XDK

Open the XDK Workbench, then connect our XDK on bootloader mode. To do that, connect our XDK to the computer using a micro USB cable while pressing button 1 (button with a dot on top of it). Then switch the XDK on. The status of our XDK will be shown on XDK Workbench.

Connect XDK110 to XDK Workbench

On application.mita editor, write these lines:

```javascript
package main;
import platforms.xdk110;
// resource for accelerometer
setup accelerometer {
bandwidth = BW_500Hz;
range = Range_8G;
}
// resource for gyroscope
setup Gyroscope_BMI160 {
bandwidth = BW_10_7Hz;
range = Range_250s;
}
// resource for light sensor
setup light {
manual_mode = false;
}
// resource for environment sensor
setup environment {
power_mode = Normal;
standby_time = 1000;
temperature_oversampling = OVERSAMPLE_1X;
}
// resource for WiFi connectivity
setup wifi : WLAN {
ssid = 'YOUR_WIFI_NAME';
authentication = Personal(psk = 'YOUR_WIFI_PASSWORD');
}
// resource for Qubitro MQTT Broker
setup qubitroBroker : MQTT {
transport = wifi;
cleanSession = true;
url = 'mqtt://broker.qubitro.com:1883';
clientId = 'YOUR_QUBITRO_DEVICE_ID';
authentication = Login('YOUR_QUBITRO_DEVICE_ID', 'YOUR_QUBITRO_DEVICE_TOKEN');
var qubitroTopik = topic('YOUR_QUBITRO_DEVICE_ID', 0);
}
// create event: every 5 sec read sensors & send to Qubitro
every 5 seconds {
// read sensors
var accx = accelerometer.x_axis.read();
var accy = accelerometer.y_axis.read();
var accz = accelerometer.z_axis.read();
var gyx = gyroscope.x_axis.read();
var gyy = gyroscope.y_axis.read();
var gyz = gyroscope.z_axis.read();
var light = light.intensity.read() / 1000.0;
var temperature = environment.temperature.read() / 1000.0;
temperature = temperature - 6.5975;
var humidity = environment.humidity.read() / 1000.0;
var pressure = environment.pressure.read() / 1000.0;

// create JSON string
var json = `{
"accx": ${accx}, "accy": ${accy}, "accz": ${accz},
"gyx": ${gyx}, "gyy": ${gyy}, "gyz": ${gyz},
"light": ${light}, "temperature": ${temperature},
"humidity": ${humidity}, "pressure": ${pressure}
}`;
// publish data to qubitro
qubitroBroker.qubitroTopik.write(json);
println(json);
}
```

Build the project then flash the code. Your XDK’s activities can be checked on the XDK Workbench console. Now every 5 seconds, the XDK will publish the data to Qubitro.

Step 3. Create a dashboard on Qubitro

On the Qubitro device Data tab, you’ll see the data stream from your XDK. You can create data visualization on the Analytics tab or create your own centralized Dashboard in the Monitoring section.

Datastream
Data analytics
Dashboard

--

--

Qubitro
Qubitro

Written by Qubitro

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

No responses yet