ESP32

Getting Started

Before getting started, make sure that required libraries are installed by visiting the setup page

Libraries

Include the Qubitro and WiFi libraries on top of your code.
1
#include <QubitroMqttClient.h>
2
#include <WiFi.h>
3
4
WiFiClient wifiClient;
5
QubitroMqttClient mqttClient(wifiClient);
Copied!

Variables

Define the device data you can get from Qubitro Portal and your WiFi parameters.
1
// Device Parameters
2
char deviceID[] = "PASTE_DEVICE_ID_HERE";
3
char deviceToken[] = "PASTE_DEVICE_TOKEN_HERE";
4
5
// WiFi Parameters
6
const char* ssid = "PASTE_SSID_HERE";
7
const char* password = "PASTE_WIFI_PASSWORD_HERE";
Copied!

Data Structure

Qubitro currently has support for key-value paired JSON objects as a data type. Nested values are not supported yet.
1
{
2
"Key1" : "Value1",
3
"Key2" : true,
4
"Key3" : 90
5
...
6
}
Copied!
An example : "{\"Temp\":33}"

Setup method

The setup method prepares your device to connect to Qubitro.
1
void setup() {
2
// Initialize the serial port
3
serial_init();
4
5
// Initialize wireless connectivity
6
wifi_init();
7
8
// Initialize Qubitro
9
qubitro_init();
10
}
Copied!

Loop method

The loop method continuously generates simulated sensor values and publishes them to Qubitro.
1
void loop() {
2
// Generate random values
3
int sensor_value_1 = random(0, 100);
4
int sensor_value_2 = random(0, 100);
5
6
// Print the random values
7
Serial.print("Sensor value 1: ");
8
Serial.println(sensor_value_1);
9
Serial.print("Sensor value 2: ");
10
Serial.println(sensor_value_2);
11
12
// Send telemetry
13
String payload = "{\"Sensor 1\":" + String(sensor_value_1)
14
+ ",\"Sensor 2\":" + String(sensor_value_2) + "}";
15
mqttClient.poll();
16
mqttClient.beginMessage(deviceID);
17
mqttClient.print(payload);
18
mqttClient.endMessage();
19
20
// Delay
21
delay(30 * 1000);
22
}
Copied!

Example

The following code connects to your wireless network, generates simulated sensor values, and publishes them to the Qubitro.
Example output:
1
Connecting to WiFi...
2
WiFi Connected.
3
Local IP: 192.168.1.100
4
RSSI: -50
5
Connecting to Qubitro...
6
Connected to Qubitro.
7
Sensor value 1: 20
8
Sensor value 2: 40
Copied!

Issues and Feedback

Visit our GitHub page for libraries or documentation issues and examples.
Qubitro
GitHub
Qubitro on GitHub
You may ask any questions through the chatbot or share feedback by visiting the Qubitro Feedback platform.
Last modified 8mo ago