You have a sensor, and you want to see its readings as a line on a screen — not by opening a serial monitor every morning, but a page that keeps the history and tells you when something is off. That is the whole project: firmware sends a reading, a small receiver writes it down, a page draws the line. It fits in an evening if nothing goes wrong, and something always goes wrong.
Here is what you get at the end: a board with a sensor posts a number to your endpoint every minute, a database keeps every value with a timestamp, and a page shows the last day, week, and month as a chart, with a red mark where a value crossed a threshold. You know it works when you unplug the board, wait two minutes, plug it back, and the chart shows a visible gap — not a flat line pretending nothing happened.
That gap is the first thing to care about. Most tutorials show a smooth chart and never mention that the smoothness is fake.
What does the finished thing actually look like?
Three parts, each doing one job.
- Firmware on the board reads the sensor and sends
{"value": 23.4, "ts": 1733000000}over HTTP POST or publishes it to an MQTT topic. - Receiver is a script on a server (or a cheap VPS) that accepts the request, validates it, and inserts a row into a table.
- Dashboard is a page that queries the database through an API and draws the series, plus a check that flags readings outside a range.
For a single sensor, HTTP POST is the right default: fewer moving parts, you can test it with curl, and a lost request is a lost request you can see. MQTT earns its place when you have several boards, spotty Wi-Fi, or you want the broker to hold messages while the receiver restarts. Do not start with MQTT because it sounds more serious.
Which access and keys do you need before writing code?
This is the part people skip, then spend an hour confused by a 401.
- A place to run the receiver. Any VPS with a public IP, or a small cloud instance. You need SSH access and the ability to open one port (80/443 for HTTP, 1883 for MQTT).
- A database. SQLite on the same box is enough for one sensor and months of data — a row per minute is about 500k rows a year, trivial. Move to PostgreSQL when you have several sensors or want concurrent writers.
- A shared secret for the board. Generate a long random token and put it in a header, e.g.
Authorization: Bearer <token>. The receiver rejects anything without it. This is not optional: an open endpoint on a public IP gets found by scanners within hours. - Wi-Fi credentials for the board, kept out of your source file.
If you cannot get a public IP — a home network behind CGNAT, a locked-down office — you have two honest options: run the receiver on a cheap VPS anyway (simplest), or have the board publish to a hosted MQTT broker. What you should not do is expose your home router to the internet for this.
The build, step by step, with an owner for each step
The AI writes most of the code. You own the numbers and the checks. Go in this order and do not move on until the check passes.
Step 1 — Firmware that sends one reading
Ask the AI for an ESP32 sketch: connect to Wi-Fi, read the sensor, POST JSON to your endpoint with the token header, retry once on failure. For a plain Arduino with a Wi-Fi shield the shape is the same; for a board without networking you need a bridge, and that changes the project. More on the topic: “How to Teach Your Child to Read and Count Through Play: A Step-by-Step Plan for Busy Parents, Without Pressure and Tears”.
AI does: generates the sketch, the JSON body, the retry logic, the Content-Type: application/json header.
You check: the sensor's real units and calibration. A raw ADC value of 2048 means nothing until you know the reference voltage and the sensor's transfer function. Do this by hand: put the sensor in a known condition (ice water for a temperature probe, a known weight for a load cell) and confirm the number the board prints matches. If it reads 3 °C off, the chart will be confidently wrong forever. More on the topic: “Prompts That Read a P&L Like a CFO: Unit Economics, Scenarios and Anomaly Hunting vs. Building the Model by Hand”.
Done when: the serial monitor shows a JSON line that a human can read and believe. More on the topic: “Six Prompts That Read Your Time Series Better Than the Chart — Trend, Seasonality, Anomalies and the Breakpoint You Keep Missing”.
Step 2 — The receiver endpoint
The AI writes a small service — FastAPI or Flask in Python, or Express in Node — with one POST route, token check, and an insert. Here is the core of a FastAPI version, matching the versions you install:
pip install fastapi==0.115.0 uvicorn==0.30.6
from fastapi import FastAPI, Header, HTTPException
from pydantic import BaseModel
import sqlite3, time
app = FastAPI()
TOKEN = "replace-with-your-long-random-token"
class Reading(BaseModel):
value: float
ts: int | None = None
@app.post("/ingest")
def ingest(r: Reading, authorization: str = Header(default="")):
if authorization != f"Bearer {TOKEN}":
raise HTTPException(status_code=401)
ts = r.ts or int(time.time())
con = sqlite3.connect("readings.db")
con.execute("INSERT INTO readings(ts, value) VALUES (?, ?)", (ts, r.value))
con.commit()
con.close()
return {"ok": True}
Run it with uvicorn main:app --host 0.0.0.0 --port 8000.
AI does: the route, the schema, the insert, a basic error response.
You check: the timestamp policy. Decide now whether you trust the board's clock or stamp the reading on the server. A board that boots without NTP starts at 1970 and will scatter points across the chart. For one sensor, server-side stamping is safer; keep the board's ts only as a diagnostic field.
Done when: curl -X POST with the right token returns 200 and a row appears in the table; without the token it returns 401.
Step 3 — Storage and the query for the chart
One table is enough:
CREATE TABLE readings (
id INTEGER PRIMARY KEY AUTOINCREMENT,
ts INTEGER NOT NULL,
value REAL NOT NULL
);
CREATE INDEX idx_readings_ts ON readings(ts);
The index matters more than it looks. Without it, a month view scans every row and the page gets slower every day.
AI does: the schema and the aggregation query for each range.
You check: time zones. Store ts as UTC epoch seconds and convert only in the browser. If you store local time, the day the clocks change you get a duplicated hour or a missing one, and a week later you cannot tell whether the spike at 02:00 is real. More on the topic: “Real-Time Systems: Building Real-Time Applications with WebSockets, SSE, and WebRTC — Where to Start and What Comes Next”.
Done when: you can run the query by hand and get a count of points that matches what you expect for the period.
Step 4 — The dashboard page
AI generates a page that fetches /series?from=...&to=... and draws a line chart. Chart.js or a tiny hand-rolled canvas both work; pick one and stay there. Add a threshold check: any point above or below your range gets a marker and a count in a banner.
You check: that gaps show as gaps. If the query returns only existing rows and the chart connects them, an outage looks like a straight line. Either return null buckets for missing minutes, or set the chart's span-gap option so the line breaks.
Done when: you can point at a hole in the chart and say exactly which minutes are missing.
Where does this break in real use?
Three failures account for almost everything, and none of them are about the code being wrong.
Lost packets on a network drop. The board sends, Wi-Fi blinks, the request never lands, and nothing retries because the code moved on. The chart gets a hole. Fix: buffer the last N readings in RAM on the board and resend them on reconnect, or accept the gap and make it visible. Do not silently interpolate — a filled gap is a lie you will believe later.
Duplicates. A retry after a timeout where the first request actually succeeded writes the same reading twice. On a chart it is invisible; in an average it skews the number. Fix: give each reading a client-side id and make the insert idempotent (a unique constraint on it), or deduplicate on (ts, value) at query time. Pick one and write it down.
Sensor drift. A cheap temperature or humidity sensor drifts over weeks. The chart stays smooth, the alerts never fire, and the number is quietly wrong. Fix: a periodic manual reference check against a known condition, and a note in the code of when it was last calibrated. This is a human task — no script catches drift for you.
How do you verify it before calling it done?
Run these by hand, in this order, and watch what the chart does.
- Normal run. Let it collect for 20 minutes. Success sign: one point per interval, no gaps, values in a plausible range.
- Pull the plug. Disconnect the board for 5 minutes. Success sign: a visible gap of about 5 minutes, not a flat line.
- Wrong token. Send a request with a bad token. Success sign: 401, and nothing in the table.
- Clock check. Reboot the board so it starts with no time. Success sign: readings still land with sane timestamps (server-stamped), or you see the skew and know why.
- Threshold. Push a value outside your range. Success sign: the marker appears and the banner counts it.
- Range view. Switch between day, week, month. Success sign: the aggregation returns a sensible number of points and the page stays fast.
If all six pass, you have a working pipeline, not a demo.
What does it cost in time and money?
Time: an evening to a weekend for one sensor, most of it spent on calibration and the gap handling, not on the code the AI writes. The code is the fast part now.
Money, order of magnitude: a small VPS runs a few dollars a month, a domain is optional, the board and sensor are a one-time purchase. There is no per-request cost unless you route through a paid service. The real cost is your attention on the checks above — and if you skip them, you pay it later in wrong numbers you trusted for a month. More on the topic: “Real-Time Systems: Myths, Realities, and the Engineering Behind Live Apps”.
If the build is longer than you want to carry alone, asibiont.com takes such projects on turnkey — the developer names the price and you top up the balance at https://asibiont.com/en/subscription-tiers. More on the topic: “Go for Backend: What Building Reliable and Fast Backends Actually Demands — and Where Beginners Stumble”.
The one habit that keeps this project alive
Every reading that lands should be traceable to a real moment, and every gap should be visible. The chart is the easy part; the discipline of not interpolating, not hiding duplicates, and recalibrating on schedule is what makes the numbers worth looking at. Build the checks into the first version, and the dashboard stays honest as it grows from one sensor to ten. You can start the same build through https://asibiont.com/en/subscription-tiers if you would rather hand it off. More on the topic: “BI Analytics and Dashboards: What to Know Before You Start — Requirements, Pitfalls, and Real Practice”.