Publish Data from Wio Terminal to Qubitro IoT Platform

Full tutorial Wio Terminal & Qubitro IoT platform

Step 1. Create Qubitro Project

Create a project on Qubitro
Create a device on Qubitro
Qubitro credentials

Step 2. Code the Wio Terminal

**credential.h**
```h
#define WIFI_SSID "YOUR_WIFI_SSID"
#define WIFI_PASS "YOUR_WIFI_PASSWORD"
#define MQTT_BROKER "broker.qubitro.com"
#define MQTT_USER "YOUR_QUBITRO_DEVICE_ID"
#define MQTT_PASS "YOUR_QUBITRO_DEVICE_TOKEN"
#define MQTT_CLID "YOUR_QUBITRO_DEVICE_ID"
#define MQTT_PORT 1883
#define MQTT_TOPIC "YOUR_QUBITRO_DEVICE_ID"
```
**WioQubitro.ino**
```cpp
// import libraries
#include "credential.h"
#include "TFT_eSPI.h"
#include "LIS3DHTR.h"
#include "rpcWiFi.h"
#include <ArduinoMqttClient.h>
// objects
TFT_eSPI tft;
LIS3DHTR<TwoWire> lis;
int button = 0;
WiFiClient wifiClient;
MqttClient mqttClient(wifiClient);
const char* ssid = WIFI_SSID;
const char* password = WIFI_PASS;
void setup() {
// TFT LCD setup
tft.begin();
tft.setRotation(3);
tft.fillScreen(TFT_BLACK);
// sensors setup
lis.begin(Wire1);
lis.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
lis.setFullScaleRange(LIS3DHTR_RANGE_2G);
pinMode(WIO_LIGHT, INPUT);
pinMode(WIO_MIC, INPUT);
pinMode(WIO_5S_PRESS, INPUT_PULLUP);
// connect WiFi
WiFi.mode(WIFI_STA);
WiFi.disconnect();
tft.setTextSize(2);
tft.drawString("Processing...", 20, 20);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
WiFi.begin(ssid, password);
}
tft.setTextSize(2);
tft.drawString("WiFi connected!", 20, 50);

// connect to Qubitro mqtt broker
mqttClient.setId(MQTT_CLID);
mqttClient.setUsernamePassword(MQTT_USER, MQTT_PASS);
if (!mqttClient.connect(MQTT_BROKER, MQTT_PORT)){
tft.setTextSize(2);
tft.drawString("Failed connect to Qubitro", 20, 80);
}
tft.setTextSize(2);
tft.drawString("Qubitro connected!", 20, 80);
delay(3000);
tft.fillScreen(TFT_BLACK);
}
void loop() {
int light = analogRead(WIO_LIGHT);
int mic = analogRead(WIO_MIC);
float x, y, z;
x = lis.getAccelerationX();
y = lis.getAccelerationY();
z = lis.getAccelerationZ();
// event: if button pressed, publish data to Qubitro
if (digitalRead(WIO_5S_PRESS) == LOW) {
button += 1;
// publish data
mqttClient.poll();
mqttClient.beginMessage(MQTT_TOPIC);
// send JSON string
mqttClient.print("{");
mqttClient.print("\"accx\":");
mqttClient.print(x);
mqttClient.print(",");
mqttClient.print("\"accy\":");
mqttClient.print(y);
mqttClient.print(",");
mqttClient.print("\"accz\":");
mqttClient.print(z);
mqttClient.print(",");
mqttClient.print("\"light\":");
mqttClient.print(light);
mqttClient.print(",");
mqttClient.print("\"mic\":");
mqttClient.print(mic);
mqttClient.print(",");
mqttClient.print("\"button\":");
mqttClient.print(button);
mqttClient.print("}");
mqttClient.endMessage();
}
// show sensor values on TFT LCD
tft.setTextSize(2);
tft.drawString("Acc X:", 20, 20);
tft.drawString("Acc Y:", 20, 95);
tft.drawString("Acc Z:", 20, 165);
tft.drawString("Light:", 180, 20);
tft.drawString("Microphone:", 180, 95);
tft.drawString("Button:", 180, 165);
tft.setTextSize(4);
tft.drawString(String(x), 20, 45);
tft.drawString(String(y), 20, 120);
tft.drawString(String(z), 20, 190);
tft.drawString(String(light), 180, 45);
tft.drawString(String(mic), 180, 120);
tft.drawString(String(button), 180, 190);
delay(100);
}
```
Wio Terminal shows built-in sensor values

Results

Data streams
Analytics
Dashboard

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store