Loading
A one-file web page that charts readings live. Starts with simulated data; swap one function to plug in a real board.
Guide
You need: a text editor and a web browser.
Step 1 of 3
Save this as dashboard.html and double-click it to open it in your browser:
| 1 | <!doctype html> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <meta charset="utf-8" /> |
| 5 | <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 6 | <title>Sensor dashboard</title> |
| 7 | <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.1/dist/chart.umd.min.js"></script> |
| 8 | <style> |
| 9 | body { font-family: system-ui, sans-serif; margin: 0; padding: 24px; background: #0b1118; color: #e6edf3; } |
| 10 | .now { font-size: 48px; font-weight: 700; color: #22d3ee; } |
| 11 | .wrap { max-width: 720px; } |
| 12 | </style> |
| 13 | </head> |
| 14 | <body> |
| 15 | <div class="wrap"> |
| 16 | <p>Temperature now</p> |
| 17 | <div class="now" id="now">--</div> |
| 18 | <canvas id="chart" height="140"></canvas> |
Milestone
The chart moves
A new point appears every two seconds and old ones scroll off.
Step 2 of 3
tick() every 2 seconds.Step 3 of 3
If your ESP32 serves JSON like {"c": 24.6} at http://192.168.1.50/data, replace readSensor() with:
| 1 | async function readSensor() { |
| 2 | const res = await fetch('http://192.168.1.50/data', { cache: 'no-store' }); |
| 3 | if (!res.ok) throw new Error('HTTP ' + res.status); |
| 4 | return res.json(); |
| 5 | } |
The browser blocks requests to another address unless the board allows it: add the header Access-Control-Allow-Origin: * to its response, or serve this page from the ESP32 itself.
Milestone
Real readings charted
Labs
All labs