Embedded Firmware
Arduino & ESP Client SDK
Official C++ client library for ESP32 and ESP8266 boards using Raina Link Protocol.
Installation
PlatformIO
Add the repository directly to your platformio.ini:
lib_deps =
https://github.com/mengsokool/raina.git#main:sdks/arduinoArduino IDE
Download the sdks/arduino folder as a ZIP file, then install it in Arduino IDE via Sketch > Include Library > Add .ZIP Library...
✓ Zero external library dependencies required (no ArduinoJson or external MQTT client needed).
Basic Example (ESP32)
#include <Raina.h>
const char* WIFI_SSID = "MyWiFi_2.4G";
const char* WIFI_PASS = "SecretPass";
const char* RAINA_HOST = "192.168.1.50"; // Server Host or IP
const char* PROJECT_TOKEN = "tok_H27q5wBayqo2QdOcyBW"; // Device Token from dashboard
const char* DEVICE_ID = "esp32-greenhouse-01"; // Unique Device Identifier
const uint16_t RAINA_PORT = 9000; // 9000 TCP / 8883 TLS
// Actuator Downlink: Listens for dashboard button or slider changes
RAINA_ON("water_pump") {
bool active = value.asBool();
digitalWrite(18, active ? HIGH : LOW);
// Echo state back to cloud to synchronize all connected dashboards
Raina.send("water_pump", active);
}
void setup() {
Serial.begin(115200);
pinMode(18, OUTPUT);
// Initialize WiFi and RLP binary socket connection
Raina.begin(WIFI_SSID, WIFI_PASS, RAINA_HOST, PROJECT_TOKEN, DEVICE_ID, RAINA_PORT);
}
void loop() {
// Keeps socket alive, auto-reconnects, and processes cloud commands
Raina.run();
static unsigned long lastReading = 0;
if (millis() - lastReading >= 3000) {
lastReading = millis();
// Multi-metric telemetry sent in a single atomic RLP binary batch
Raina.send(
"temperature", 27.8,
"humidity", 68.4,
"soil_moisture", 55.0
);
}
}API Reference Summary
| Method | Description |
|---|---|
| Raina.begin(ssid, pass, host, token, id, port) | Initialize network and RLP connection credentials. |
| Raina.run() | Non-blocking background loop handling socket, heartbeats, and commands. |
| Raina.send(key, value) | Queue a single metric into the current auto-flush cycle. |
| Raina.send(k1, v1, k2, v2, ...) | Send 2 or more metrics in a single atomic binary batch. |
| RAINA_ON(variable) | Macro callback triggered when cloud sends an actuator command. |
| Raina.setCACert(pem) | Configure root CA certificate for TLS port 8883 verification. |