A real-time demo of a Raspberry Pi Pico W publishing LM35 temperature readings to a Hardhat local blockchain, with a live web dashboard showing every reading as it lands on-chain.
┌─────────────────────┐ HTTP POST ┌─────────────────────────┐
│ Raspberry Pi Pico W│ ────────────────► │ Relay Server │
│ (LM35 + MicroPy) │ /reading │ relay/server.js │
└─────────────────────┘ │ localhost:3000 │
└──────────┬──────────────┘
│ ethers.js
▼
┌─────────────────────────┐
│ Hardhat Local Node │
│ localhost:8545 │
│ TemperatureLogger.sol │
└──────────┬──────────────┘
│ SSE events
▼
┌─────────────────────────┐
│ Live Dashboard │
│ localhost:3000/ │
└─────────────────────────┘
cd Blockchain
npx hardhat nodeKeep this running. Copy any of the printed account private keys if needed.
cd Blockchain
npm run deployThis deploys TemperatureLogger.sol and writes deploy-info.json.
cd Blockchain
npm run relayOpen http://localhost:3000 in a browser to see the dashboard.
-
Open
IOT/pico_uploader.pyand edit these lines:SSID = "YOUR_WIFI_SSID" PASSWORD = "YOUR_WIFI_PASSWORD" RELAY_URL = "http://192.168.1.XXX:3000/reading" # your PC's IP
Find your PC's IP: run
ipconfigin PowerShell, look for IPv4 Address -
Flash
pico_uploader.pyto the Pico W using Thonny ormpremote:mpremote connect COM3 cp IOT/pico_uploader.py :main.py
-
The Pico W will:
- Connect to WiFi (LED blinks slowly)
- Read temp every 10 seconds
- POST to relay → relay calls contract → dashboard updates live
Click "▶ Simulate Pico W" on the dashboard to generate synthetic readings every 5 seconds — perfect for presenting without the hardware.
Blockchain/
├── contracts/
│ └── TemperatureLogger.sol ← Smart contract
├── ignition/modules/
│ └── deploy.js ← Deployment + device auth script
├── relay/
│ ├── server.js ← Relay server (Express + ethers.js)
│ └── public/
│ └── index.html ← Live dashboard
├── hardhat.config.js
├── package.json
└── deploy-info.json ← Generated after `npm run deploy`
IOT/
├── lm35_temperature.py ← Standalone sensor test script
└── pico_uploader.py ← Blockchain-connected uploader
TemperatureLogger.sol stores readings with:
timestamp— block timestamptemperatureC— temperature × 100 (preserves 2 decimal places)deviceId— which device sent it
Only authorized devices can write. The deploy script pre-authorizes pico-w-001.
Key functions:
| Function | Description |
|---|---|
recordTemperature(int256, string) |
Write a reading on-chain |
getAllReadings() |
Fetch all readings |
getLatestReading() |
Fetch the most recent |
authorizeDevice(string) |
Owner: add a device |
| Feature | Description |
|---|---|
| 🌡️ Live thermometer | Visual gauge that fills based on temperature |
| 📈 Chart | Rolling 30-point temperature history |
| ⛓️ Chain visualizer | Each reading shown as a block in the chain |
| 📡 TX feed | Live transaction log with block numbers |
| 🔔 Toast notifications | Pop-up on every new on-chain reading |
| 🎮 Simulator | Generates readings without physical hardware |