Ready-to-use firmware for connecting IoT devices to Datum.
Location: tests/device_simulator.py
python tests/device_simulator.py \
--device-id dev_xxx \
--api-key sk_live_xxx \
--interval 10Features:
- Simulates temperature, humidity, battery sensors
- Sends data at configurable intervals
- Polls and executes commands
- Auto-acknowledges command completion
Location: examples/arduino/datum_device.ino
Requirements:
- ESP32 or ESP8266 board
- Arduino IDE with ESP32 board package
- ArduinoJson library
Setup:
- Open
datum_device.inoin Arduino IDE - Edit configuration section:
const char* WIFI_SSID = "your-wifi"; const char* DEVICE_ID = "dev_xxx"; const char* API_KEY = "sk_live_xxx";
- Upload to board
Location: examples/micropython/main.py
Requirements:
- ESP32/ESP8266 with MicroPython firmware
- ampy, mpremote, or Thonny for file upload
Setup:
- Edit CONFIG section in
main.py - Upload to device:
ampy --port /dev/ttyUSB0 put examples/micropython/main.py main.py
-
Create device in Datumpy:
curl -X POST http://localhost:8000/dev \ -H "Authorization: Bearer YOUR_JWT_TOKEN" \ -H "Content-Type: application/json" \ -d '{"name": "My Sensor", "type": "temperature"}'
-
Save the response:
{"device_id": "dev_xxx", "api_key": "sk_live_xxx"} -
Flash firmware with these credentials
-
Device sends data:
POST /dev/{device_id}/data Authorization: Bearer {api_key} {"temperature": 25.5, "humidity": 60} -
Check for commands in response:
{"status": "ok", "commands_pending": 1} -
Poll and execute if commands pending
Devices should handle these standard commands:
| Action | Params | Description |
|---|---|---|
reboot |
{delay: 5} |
Restart device |
set_interval |
{seconds: 60} |
Change send interval |
update_firmware |
{version: "1.0.1"} |
OTA update |
For devices that cannot make POST requests with JSON bodies, use the GET push endpoint:
GET /dev/{device_id}/data?key={api_key}&temp=25.5&humidity=60&battery=85// Minimal implementation - no JSON library needed
void sendData(float temp, float humidity, int battery) {
WiFiClient client;
if (client.connect("your-server.com", 8000)) {
String url = "/dev/" + String(DEVICE_ID) + "/data";
url += "?key=" + String(API_KEY);
url += "&temp=" + String(temp, 1);
url += "&humidity=" + String(humidity, 1);
url += "&battery=" + String(battery);
client.print("GET " + url + " HTTP/1.1\r\n");
client.print("Host: your-server.com\r\n");
client.print("Connection: close\r\n\r\n");
while (client.connected()) {
if (client.available()) {
String line = client.readStringUntil('\n');
// Parse response if needed
}
}
client.stop();
}
}- No JSON parsing needed - simpler code, smaller binary
- Single HTTP GET - compatible with basic HTTP libraries
- Auto type detection - numbers, booleans, and strings parsed automatically
- same authentication - uses
keyquery parameter