Developer Documentation & SDKs

Connect Any Device In Minutes

OpenIoT communicates using standard MQTT v3.1.1 and v5.0 protocols. Below are complete, production-ready code samples for every supported architecture.

Topic Structure

Telemetry Feed

v1/{dev_id}/{device_id}/telemetry

Publish device sensor JSON frames here. Enforced by dynamic ACL webhooks.

Topic Structure

Downlink Commands

v1/{dev_id}/{device_id}/commands

Subscribe to this topic to receive remote relay, solenoid, and restart commands.

Security

Zero-Trust ACL

Port 1883 / TLS 8883

EMQX blocks any client trying to inspect or publish to topics outside their developer namespace.

/*
 * OpenIoT ESP32 Arduino Client
 * Install: PubSubClient by Nick O'Leary & ArduinoJson
 */

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

const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";

// OpenIoT Cloud Broker
const char* mqtt_server = "mqtt.openiot.cloud";
const int mqtt_port = 1883;

// Credentials from OpenIoT Dashboard
const char* dev_id = "YOUR_DEVELOPER_ID";
const char* device_id = "YOUR_DEVICE_ID";
const char* token = "YOUR_DEVICE_TOKEN";

WiFiClient espClient;
PubSubClient client(espClient);

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nWiFi Connected!");

  client.setServer(mqtt_server, mqtt_port);
  client.setCallback(callback);
}

void callback(char* topic, byte* message, unsigned int length) {
  Serial.print("Downlink Command Received: ");
  for (int i = 0; i < length; i++) {
    Serial.print((char)message[i]);
  }
  Serial.println();
}

void loop() {
  if (!client.connected()) {
    reconnect();
  }
  client.loop();

  // Publish telemetry every 5 seconds
  static unsigned long last = 0;
  if (millis() - last > 5000) {
    last = millis();
    StaticJsonDocument<200> doc;
    doc["power_watts"] = analogRead(34) * 1.25;
    doc["humidity"] = 58.2;
    doc["temperature"] = 26.5;
    doc["status"] = "NORMAL";

    char buffer[256];
    serializeJson(doc, buffer);

    String topic = "v1/" + String(dev_id) + "/" + String(device_id) + "/telemetry";
    client.publish(topic.c_str(), buffer);
    Serial.println("Published to OpenIoT: " + String(buffer));
  }
}

void reconnect() {
  while (!client.connected()) {
    Serial.print("Connecting to OpenIoT MQTT Broker...");
    if (client.connect(device_id, device_id, token)) {
      Serial.println("Connected!");
      String cmdTopic = "v1/" + String(dev_id) + "/" + String(device_id) + "/commands";
      client.subscribe(cmdTopic.c_str());
    } else {
      delay(2000);
    }
  }
}

Platform Error Codes Reference

Status CodeError IdentifierMeaning & Recommended Action
403QUOTA_EXCEEDEDFree tier limit of 2 devices reached. Upgrade to Pro for 15 devices.
401AUTH_REQUIREDMissing or expired JWT / x-api-key header in REST request.
MQTT 0x87NOT_AUTHORIZEDDevice token is invalid or published to an unauthorized topic.