Ot/Documentation

Arduino Library (OtTelemetry)

OtTelemetry is Ot's official Arduino library for ESP32 and ESP8266 boards. It handles WiFi, the MQTT connection, JSON payload building, and reconnects — your sketch just adds fields and sends.

Installation

Download OtTelemetry.zip from your Devices page (step 2 of device registration), then in the Arduino IDE choose Sketch → Include Library → Add .ZIP Library… and select the file.

One dependency

Also install PubSubClient from the Arduino Library Manager — it is the MQTT client OtTelemetry uses underneath.

A complete sketch

cpp
#include <OtTelemetry.h>
#include "secrets.h"

OtTelemetry ot(OT_PROJECT_ID, OT_DEVICE_TOKEN);

void setup() {
  Serial.begin(115200);
  // WiFi + MQTT in one call. Default broker port is 1883.
  ot.begin(OT_WIFI_SSID, OT_WIFI_PASS, "broker.hivemq.com");
}

void loop() {
  ot.loop();  // keeps WiFi and MQTT alive; call every pass

  if (ot.connected()) {
    // Batch several fields into one message:
    ot.beginPayload();
    ot.addField("temp", readTemperature());
    ot.addField("moisture", readMoisture());
    ot.sendPayload();

    // Or send a single field:
    // ot.send("battery", 92.5);
  }

  delay(10000);
}

Every field name you send (temp, moisture, ph, anything) becomes a plottable field in your dashboard widgets. There is no schema to declare — the field exists as soon as you send it.

API reference

MethodPurpose
OtTelemetry(projectId, deviceToken)Construct with the values from secrets.h.
begin(ssid, pass, broker, port, mqttUser, mqttPass)Connect WiFi and MQTT once in setup(). Port defaults to 1883; user/pass default to none.
loop()Keep connections alive and reconnect if dropped. Call on every loop() pass.
connected()Returns true when both WiFi and MQTT are up.
send(field, value)Publish a single reading. Accepts float, int, or string values.
beginPayload() / addField(field, value) / sendPayload()Batch several fields into one MQTT message — cheaper than sending each separately.

How it travels

The library publishes JSON to the MQTT topic ot/projects/{projectId}/data, including your device token in the payload. The Ot bridge subscribes to these topics, verifies the token, and writes the reading into your account's storage. Your device never holds database credentials.

Security model

If a token is compromised, delete that device in the dashboard — the bridge rejects its messages immediately. Other devices and your account remain unaffected.