How to Connect an ESP32 to DOBI

by dobi_terminal in Circuits > Microcontrollers

3 Views, 0 Favorites, 0 Comments

How to Connect an ESP32 to DOBI

a9d7d9122051.png

DOBI devices follow a single, predictable pattern: they register with a provisioning key, send a heartbeat with metrics, and then listen for commands. This project walks you through that skeleton on an ESP32, so that once it is running you only need to add your sensors and actuators. It takes about ten minutes and you end up with a device visible on the DOBI dashboard.

The guide assumes you already have the Arduino IDE 2.x installed, the ESP32 board added in the Boards Manager, and the following libraries available in the Library Manager: WiFi, HTTPClient, and ArduinoJson. You will also need a provisioning key generated from the DOBI dashboard. The code in each step is injected verbatim from the source guide — do not retype or modify pin mappings that are not shown.

After the ESP32 sends its first heartbeat, open the Devices tab in the dashboard. The device will appear online, with its status and latest metrics. If you do not see it, check the serial monitor for the HTTP response from the registration call.

Supplies

  1. ESP32 (any variant)
  2. USB cable for flashing
  3. Arduino IDE (2.x) with the ESP32 board added in the Boards Manager
  4. Arduino libraries: WiFi, HTTPClient, ArduinoJson (all available in the Library Manager)
  5. Your own provisioning key, generated from the DOBI dashboard

Configure the Device Credentials

Before the ESP32 can talk to DOBI, it needs to know who it is and which account it belongs to. Define four things in your sketch: the device identifier, its human-readable name, the device type, and the provisioning key. The id must be unique within your account — if two devices share an id, the second registration will overwrite or conflict with the first. The type tells DOBI which metrics and actions to expect, so pick a type that matches the sensors you plan to attach later.

The provisioning key is the secret that authorizes registration. Treat it like a password: do not commit it to a public repository, and if you share your sketch, replace it with a placeholder.

Credentials · cpp


#define DOBI_PLATFORM      "https://dobi.guru"
#define WIFI_SSID "YOUR_WIFI"
#define WIFI_PASSWORD "YOUR_PASSWORD"
#define DOBI_DEVICE_ID "my-esp32-01"
#define DOBI_DEVICE_NAME "Living room ESP32"
#define DOBI_PROVISION_KEY "your-provision-key"
#define DOBI_DEVICE_TYPE "iot_sensor"

The usual failure here is a mismatched id or a key copied with trailing whitespace. If registration returns an error, print the raw response and compare the id and key character by character.

Register the Device on the Platform

Registration is what creates the device record on the platform. You make a POST request to /api/devices/register with the provisioning key in the payload or header, as defined in the skeleton. The call is idempotent, which means you can restart the ESP32 as many times as you want without duplicating the device record — the server recognizes the same id and returns the existing device.

This idempotency is deliberate: it lets you reboot during development without cleaning up the dashboard each time. If you change the device id, however, you will create a new device.

Registration · cpp


void dobiRegister() {
HTTPClient http;
http.begin(String(DOBI_PLATFORM) + "/api/devices/register");
http.addHeader("Content-Type", "application/json");

StaticJsonDocument<256> doc;
doc["provision_key"] = DOBI_PROVISION_KEY;
doc["id_asset"] = DOBI_DEVICE_ID;
doc["device_name"] = DOBI_DEVICE_NAME;
doc["device_type"] = DOBI_DEVICE_TYPE;

String body;
serializeJson(doc, body);
http.POST(body);
http.end();
}

The typical failure is a network-level one: the ESP32 connects to Wi-Fi but the DNS lookup or TLS handshake to dobi.guru fails. Check the HTTP response code and any error string returned by the client before assuming the credentials are wrong.

Send a Heartbeat Every 30 Seconds

The heartbeat is the pulse that tells DOBI the device is alive. Send it every 30 seconds using the same endpoint structure shown in the skeleton. DOBI uses the heartbeat to mark the device as online and to feed real-time metrics into the dashboard. Without a heartbeat, the device will appear as stale after a while, and any commands you send from the dashboard may not be delivered until it checks in again.

Keep the interval consistent. If you send too frequently you waste bandwidth and power; if too slowly, the dashboard shows stale data. The 30-second value is the baseline in this guide.

Heartbeat · cpp


void dobiHeartbeat() {
HTTPClient http;
http.begin(String(DOBI_PLATFORM) + "/api/devices/" + DOBI_DEVICE_ID + "/heartbeat");
http.addHeader("Content-Type", "application/json");

StaticJsonDocument<256> doc;
JsonArray metrics = doc.createNestedArray("metrics");
JsonObject m = metrics.createNestedObject();
m["name"] = "temperature";
m["value"] = 22.5;
m["unit"] = "C";

String body;
serializeJson(doc, body);
http.POST(body);
http.end();
}

The usual failure is blocking code elsewhere in your loop that delays the heartbeat past the staleness threshold. If the device flickers between online and stale, move the heartbeat call to a non-blocking timer or reduce the work done between calls.

Complete ESP32 Skeleton

This step gives you the complete skeleton in one block, combining the credentials, the registration call, and the heartbeat in a single sketch. Copy and paste the whole thing into your Arduino IDE, then replace the credentials with your own provisioning key and device id.

The full sketch is the reference implementation: it connects to Wi-Fi, registers once, and then loops sending heartbeats every 30 seconds. From here, you only add sensors or actuators. If you change the heartbeat interval, do it in one place.

Complete ESP32 skeleton · cpp


#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>

#define DOBI_PLATFORM "https://dobi.guru"
#define WIFI_SSID "YOUR_WIFI"
#define WIFI_PASSWORD "YOUR_PASSWORD"
#define DOBI_DEVICE_ID "my-esp32-01"
#define DOBI_DEVICE_NAME "Living room ESP32"
#define DOBI_PROVISION_KEY "your-provision-key"
#define DOBI_DEVICE_TYPE "iot_sensor"
#define DOBI_HEARTBEAT_MS 30000

static unsigned long lastTick = 0;

void dobiRegister() {
HTTPClient http;
http.begin(String(DOBI_PLATFORM) + "/api/devices/register");
http.addHeader("Content-Type", "application/json");
StaticJsonDocument<256> doc;
doc["provision_key"] = DOBI_PROVISION_KEY;
doc["id_asset"] = DOBI_DEVICE_ID;
doc["device_name"] = DOBI_DEVICE_NAME;
doc["device_type"] = DOBI_DEVICE_TYPE;
String body;
serializeJson(doc, body);
http.POST(body);
http.end();
}

void dobiHeartbeat() {
HTTPClient http;
http.begin(String(DOBI_PLATFORM) + "/api/devices/" + DOBI_DEVICE_ID + "/heartbeat");
http.addHeader("Content-Type", "application/json");
StaticJsonDocument<256> doc;
JsonArray metrics = doc.createNestedArray("metrics");
JsonObject m = metrics.createNestedObject();
m["name"] = "temperature";
m["value"] = 22.5;
m["unit"] = "C";
String body;
serializeJson(doc, body);
http.POST(body);
http.end();
}

void setup() {
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) delay(500);
dobiRegister();
lastTick = millis() - DOBI_HEARTBEAT_MS;
}

void loop() {
if (WiFi.status() != WL_CONNECTED) {
WiFi.reconnect();
delay(1000);
return;
}
if (millis() - lastTick >= DOBI_HEARTBEAT_MS) {
dobiHeartbeat();
lastTick = millis();
}
delay(200);
}

The most common failure with the full sketch is forgetting to change the placeholder credentials, which leads to a 401 or 403 from the register endpoint. A second common issue is the board not rebooting into the Wi-Fi connection because the serial monitor is still open at the wrong baud rate — close it, verify the baud, and reset the board.