This repository contains a small demo of a software-based smart street lighting system.
Features:
- Node.js + Express server
- Socket.IO real-time updates
- Simple frontend UI showing lamps, ambient sensors and controls
- Auto/manual mode with ambient lux threshold
- Session-based authentication for admin panel
- MQTT bridge for real sensor integration
- Persistent JSONL logging + CSV export
- Optional TLS/HTTPS support
Quick start (PowerShell on Windows):
# 1. Install dependencies
npm install
# 2. Run the server
npm start
# Then open http://localhost:3000 in your browserNotes:
- This is a demo / simulation. Replace sensor simulation with real sensor integration to make it real.
- The frontend is at the root
index.htmland static assets are inpublic/.
MQTT Integration (bridge)
- The server can bridge to an MQTT broker to receive real sensor data and send control commands.
- Environment variables:
MQTT_URL(defaultmqtt://localhost:1883)MQTT_PREFIX(defaultstreet)
Simulator
- A simple MQTT simulator is included at
scripts/mqtt_simulator.js. - It publishes sensor values to
street/light/{id}/sensorand listens forstreet/light/{id}/set.
Run the simulator (requires a reachable MQTT broker):
# Use a local Mosquitto broker or a public broker. Example using local broker:
npm run simulator
# To run server with MQTT broker URL and custom prefix:
#(set env var in PowerShell) $env:MQTT_URL = 'mqtt://test.mosquitto.org:1883'; npm startIf you don't have an MQTT broker locally, install Mosquitto or use a public broker for quick testing.
TLS/HTTPS (optional)
- Self-signed certificates can be placed in
./certs/cert.pemand./certs/key.pem. - If present, the server will use HTTPS; otherwise, it falls back to HTTP.
- Generate self-signed certs using OpenSSL (on Windows or WSL):
mkdir certs
openssl req -x509 -newkey rsa:2048 -keyout certs/key.pem -out certs/cert.pem -days 365 -nodes -subj "/CN=localhost"- Then restart the server — it will auto-detect HTTPS.
Authentication
- The logs endpoint (
/public/logs.html) requires a login. - Default password:
admin - Override with env var:
$env:ADMIN_PASSWORD = 'your-password'; npm start
Docker (recommended quick-start)
- A
docker-compose.ymlis provided to run a Mosquitto broker, the Node app and the simulator together. - Start everything with:
docker compose up --build-
The web UI will be available at
http://localhost:3000. -
To stop and remove containers:
docker compose down