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
Prerequisites
Section titled “Prerequisites”| Requirement | Details |
|---|---|
| Python | Version 3.8 or later |
requests library | pip install requests |
| SiliconWit.IO Account | Starter plan or above |
| API Key | Created from Dashboard > Settings > API Keys |
Step 1: Create an API Key
Section titled “Step 1: Create an API Key”- Log in to SiliconWit.IO
- Go to Dashboard > Settings > API Keys
- Click Create API Key and give it a name (e.g. “Daily Report Script”)
- Copy the key immediately - it starts with
swk_and is only shown once
Step 2: Test the Connection
Section titled “Step 2: Test the Connection”Verify your key works with a quick curl command:
curl https://api.siliconwit.io/v1/devices \ -H "Authorization: Bearer swk_your_key_here"You should see a JSON response listing your devices.
Step 3: Build the Report Script
Section titled “Step 3: Build the Report Script”Create a file called daily_report.py:
import requestsfrom 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()Step 4: Run It
Section titled “Step 4: Run It”pip install requestspython daily_report.pyExample output:
=== SiliconWit.IO Daily Report ===Generated: 2026-02-10 08:00 UTCTotal 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 dataStep 5: Schedule with Cron
Section titled “Step 5: Schedule with Cron”Run the report automatically every morning at 8:00 AM:
crontab -eAdd this line (adjust the path to your script):
0 8 * * * /usr/bin/python3 /home/user/daily_report.py >> /home/user/reports.log 2>&1Step 6: Email the Report (Optional)
Section titled “Step 6: Email the Report (Optional)”Extend the script to email the report using Python’s smtplib:
import smtplibfrom email.mime.text import MIMETextfrom io import StringIOimport 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["To"] = to_email
with smtplib.SMTP("smtp.yourdomain.com", 587) as server: server.starttls() server.send_message(msg)
# Capture print output as a stringoutput = StringIO()sys.stdout = outputgenerate_report()sys.stdout = sys.__stdout__report_text = output.getvalue()
# Print to console and send emailprint(report_text)Ideas for Extending This
Section titled “Ideas for Extending This”- 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
Summary
Section titled “Summary”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.
Next Steps
Section titled “Next Steps”- Google Sheets Integration - Auto-update a spreadsheet with live data
- Public API Reference - All available endpoints
- API Keys - Manage your API keys