Skip to content

Automated Reports with the Public API

The SiliconWit.IO dashboard is great for real-time monitoring, but some tasks need automation: daily reports, data aggregation across devices, or feeding data into your own systems. The Public API makes this possible with simple HTTP requests from any language.

This tutorial builds a Python script that fetches data from all your devices and produces a summary report. You can run it manually, schedule it with cron, or trigger it from a CI pipeline.

What the API Enables That the Dashboard Cannot

Section titled “What the API Enables That the Dashboard Cannot”

The dashboard shows one device at a time. The Public API lets you:

  • Query all devices at once and compare readings across your fleet
  • Pull historical telemetry into your own scripts for custom analysis
  • Automate reports on a schedule without opening a browser
  • Feed data into other tools like spreadsheets, databases, or BI dashboards
  • Build custom alerts with logic more complex than threshold checks
RequirementDetails
PythonVersion 3.8 or later
requests librarypip install requests
SiliconWit.IO AccountStarter plan or above
API KeyCreated from Dashboard > Settings > API Keys
  1. Log in to SiliconWit.IO
  2. Go to Dashboard > Settings > API Keys
  3. Click Create API Key and give it a name (e.g. “Daily Report Script”)
  4. Copy the key immediately - it starts with swk_ and is only shown once

Verify your key works with a quick curl command:

Terminal window
curl https://api.siliconwit.io/v1/devices \
-H "Authorization: Bearer swk_your_key_here"

You should see a JSON response listing your devices.

Create a file called daily_report.py:

import requests
from datetime import datetime, timezone
# ========== CONFIGURATION ==========
API_KEY = "swk_your_key_here"
BASE_URL = "https://api.siliconwit.io/v1"
HEADERS = {"Authorization": f"Bearer {API_KEY}"}
def get_all_devices():
"""Fetch all devices with pagination."""
devices = []
offset = 0
while True:
resp = requests.get(
f"{BASE_URL}/devices",
headers=HEADERS,
params={"limit": 100, "offset": offset},
)
resp.raise_for_status()
batch = resp.json()["data"]
if not batch:
break
devices.extend(batch)
offset += len(batch)
return devices
def get_latest_reading(device_id):
"""Fetch the most recent telemetry for a device."""
resp = requests.get(
f"{BASE_URL}/devices/{device_id}/telemetry/latest",
headers=HEADERS,
)
resp.raise_for_status()
return resp.json()["data"]
def get_telemetry_history(device_id, time_range="24h"):
"""Fetch telemetry history for a device."""
resp = requests.get(
f"{BASE_URL}/devices/{device_id}/telemetry",
headers=HEADERS,
params={"range": time_range, "limit": 1000},
)
resp.raise_for_status()
return resp.json()["data"]
def compute_stats(readings, field):
"""Compute min, max, and average for a given field."""
values = [
r["data"][field]
for r in readings
if field in r.get("data", {})
and isinstance(r["data"][field], (int, float))
]
if not values:
return None
return {
"min": round(min(values), 1),
"max": round(max(values), 1),
"avg": round(sum(values) / len(values), 1),
"count": len(values),
}
def generate_report():
"""Generate a daily summary report."""
now = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")
devices = get_all_devices()
print(f"=== SiliconWit.IO Daily Report ===")
print(f"Generated: {now}")
print(f"Total devices: {len(devices)}")
print()
active = [d for d in devices if d["status"] == "active"]
paused = [d for d in devices if d["status"] == "paused"]
print(f" Active: {len(active)}")
print(f" Paused: {len(paused)}")
print()
for device in devices:
print(f"--- {device['name']} ({device['status']}) ---")
latest = get_latest_reading(device["id"])
if not latest:
print(" No telemetry data")
print()
continue
print(f" Last reading: {latest['time']}")
for key, value in latest["data"].items():
print(f" {key}: {value}")
# Get 24-hour history and compute stats
history = get_telemetry_history(device["id"], "24h")
if history:
print(f" Readings in last 24h: {len(history)}")
# Compute stats for each numeric field
fields = set()
for r in history:
for k, v in r.get("data", {}).items():
if isinstance(v, (int, float)):
fields.add(k)
for field in sorted(fields):
stats = compute_stats(history, field)
if stats:
print(
f" {field}: min={stats['min']}, "
f"max={stats['max']}, avg={stats['avg']}"
)
print()
if __name__ == "__main__":
generate_report()
Terminal window
pip install requests
python daily_report.py

Example output:

=== SiliconWit.IO Daily Report ===
Generated: 2026-02-10 08:00 UTC
Total devices: 3
Active: 2
Paused: 1
--- Office Sensor (active) ---
Last reading: 2026-02-10T07:55:00Z
temperature: 24.3
humidity: 55.7
Readings in last 24h: 144
humidity: min=42.0, max=68.3, avg=55.1
temperature: min=21.5, max=26.8, avg=23.9
--- Warehouse Monitor (active) ---
Last reading: 2026-02-10T07:50:00Z
temperature: 18.2
humidity: 35.0
Readings in last 24h: 288
humidity: min=30.0, max=45.0, avg=36.2
temperature: min=15.0, max=22.0, avg=18.5
--- Garden Sensor (paused) ---
No telemetry data

Run the report automatically every morning at 8:00 AM:

Terminal window
crontab -e

Add this line (adjust the path to your script):

0 8 * * * /usr/bin/python3 /home/user/daily_report.py >> /home/user/reports.log 2>&1

Extend the script to email the report using Python’s smtplib:

import smtplib
from email.mime.text import MIMEText
from io import StringIO
import sys
def email_report(report_text, to_email):
"""Send the report via email."""
msg = MIMEText(report_text)
msg["Subject"] = f"SiliconWit.IO Daily Report - {datetime.now(timezone.utc).strftime('%Y-%m-%d')}"
msg["From"] = "[email protected]"
msg["To"] = to_email
with smtplib.SMTP("smtp.yourdomain.com", 587) as server:
server.starttls()
server.login("[email protected]", "your_password")
server.send_message(msg)
# Capture print output as a string
output = StringIO()
sys.stdout = output
generate_report()
sys.stdout = sys.__stdout__
report_text = output.getvalue()
# Print to console and send email
print(report_text)
email_report(report_text, "[email protected]")
  • CSV export: Write results to a CSV file for spreadsheet analysis
  • Threshold checks: Flag devices where readings exceed safe limits
  • Comparison reports: Compare this week’s averages to last week’s
  • Slack/Discord post: Send the report to a team channel using webhooks
  • Database storage: Save daily summaries for long-term trend analysis

In this tutorial, you used the SiliconWit.IO Public API to:

  • Fetch all devices and their status in a single script
  • Pull the latest and historical telemetry data
  • Compute min, max, and average statistics across 24 hours
  • Generate a human-readable report that can be scheduled or emailed

The same API endpoints work with any language or tool that can make HTTP requests: Node.js, Go, Ruby, shell scripts, or no-code platforms.