HTTP Data Ingestion
Send telemetry data from your devices using HTTP POST as an alternative to MQTT. This is useful for devices that can make HTTP requests but don’t support MQTT, or for serverless and cloud-to-cloud integrations.
Endpoint
Section titled “Endpoint”POST https://siliconwit.io/api/devices/ingestAuthentication
Section titled “Authentication”Include your Device ID and Access Token in the request body:
{ "device_id": "YOUR_DEVICE_ID", "access_token": "YOUR_ACCESS_TOKEN", "data": { ... }}Or use the Authorization header for the token:
Authorization: Bearer YOUR_ACCESS_TOKENExamples
Section titled “Examples”Python
Section titled “Python”import requestsimport json
DEVICE_ID = "your-device-id"ACCESS_TOKEN = "your-access-token"
data = { "device_id": DEVICE_ID, "access_token": ACCESS_TOKEN, "data": { "temperature": 25.5, "humidity": 60 }}
response = requests.post( "https://siliconwit.io/api/devices/ingest", json=data)
print(response.json()) # {"success": true}ESP32 / Arduino (HTTP)
Section titled “ESP32 / Arduino (HTTP)”For devices where MQTT libraries are unavailable or you prefer HTTP:
#include <WiFi.h>#include <HTTPClient.h>
const char* ssid = "YOUR_WIFI";const char* password = "YOUR_PASSWORD";const char* device_id = "YOUR_DEVICE_ID";const char* access_token = "YOUR_ACCESS_TOKEN";
void setup() { Serial.begin(115200); WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("WiFi connected");}
void sendData(float temperature, float humidity) { HTTPClient http; http.begin("https://siliconwit.io/api/devices/ingest"); http.addHeader("Content-Type", "application/json");
String payload = "{\"device_id\":\"" + String(device_id) + "\",\"access_token\":\"" + String(access_token) + "\",\"data\":{\"temperature\":" + String(temperature) + ",\"humidity\":" + String(humidity) + "}}";
int httpCode = http.POST(payload);
if (httpCode == 200) { Serial.println("Data sent successfully"); } else { Serial.printf("HTTP error: %d\n", httpCode); }
http.end();}
void loop() { float temp = 25.5; // Replace with actual sensor reading float hum = 60.0;
sendData(temp, hum); delay(30000); // Send every 30 seconds}MicroPython
Section titled “MicroPython”import urequestsimport jsonimport time
DEVICE_ID = "your-device-id"ACCESS_TOKEN = "your-access-token"URL = "https://siliconwit.io/api/devices/ingest"
def send_data(temperature, humidity): payload = { "device_id": DEVICE_ID, "access_token": ACCESS_TOKEN, "data": { "temperature": temperature, "humidity": humidity } }
response = urequests.post( URL, data=json.dumps(payload), headers={"Content-Type": "application/json"} ) print(response.json()) response.close()
while True: send_data(25.5, 60) time.sleep(30)curl -X POST https://siliconwit.io/api/devices/ingest \ -H "Content-Type: application/json" \ -d '{ "device_id": "your-device-id", "access_token": "your-access-token", "data": { "temperature": 25.5, "humidity": 60, "battery": 85 } }'Node.js
Section titled “Node.js”const response = await fetch("https://siliconwit.io/api/devices/ingest", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ device_id: "your-device-id", access_token: "your-access-token", data: { temperature: 25.5, humidity: 60 } })});
const result = await response.json();console.log(result); // { success: true }MQTT vs HTTP
Section titled “MQTT vs HTTP”| Feature | MQTT | HTTP |
|---|---|---|
| Connection | Persistent | Per-request |
| Best for | Continuous streaming | Periodic readings |
| Overhead | Low (small packets) | Higher (HTTP headers) |
| Bidirectional | Yes (commands) | No (send only) |
| TLS | Required (port 8883) | Required (HTTPS) |
| Battery usage | Lower (keep-alive) | Higher (reconnect each time) |
Use MQTT when your device sends data frequently (every few seconds) or needs to receive commands.
Use HTTP when your device wakes up periodically, sends data, then sleeps. Also good for cloud integrations, webhooks, and serverless functions.
Error Handling
Section titled “Error Handling”Always check the response status:
| Status | Meaning | Action |
|---|---|---|
| 200 | Success | Data stored |
| 400 | Bad request | Check payload format |
| 401 | Unauthorized | Check device_id and access_token |
| 403 | Forbidden | Device is paused in dashboard |
| 500 | Server error | Retry after a delay |
Next Steps
Section titled “Next Steps”- MQTT Basics - For persistent connections
- ESP32 Setup - Full hardware guide
- Topics & Payloads - Data format best practices