This project implements a complete IoT telemetry system where simulated devices connect to a backend server, report CPU temperature data, and receive remote commands such as frequency updates and reboots. The system is built with TypeScript, Node.js, Express, PostgreSQL, and WebSockets, and includes a simple frontend dashboard to visualize telemetry data in real-time.
-
Device Simulation
- Devices connect via TCP sockets (
net
module). - Each device reports telemetry (CPU temperature) at a configurable frequency.
- Devices can receive commands (
updateFrequency
,reboot
).
- Devices connect via TCP sockets (
-
Backend (Server)
- Built with Express + WebSockets for real-time updates.
- Stores telemetry data in PostgreSQL.
- Exposes REST APIs:
GET /telemetry
→ fetch all telemetry history.POST /command
→ send commands to devices.
- Broadcasts live telemetry updates via WebSocket to frontend clients.
-
Frontend (Dashboard)
- index.html + app-front.js served by Express.
- Displays a real-time telemetry table with device serial, timestamp, and temperature.
- Commands can be sent via UI controls:
- Update telemetry frequency.
- Reboot device.
- New telemetry data appears instantly at the top of the table.
- Node.js + TypeScript (core server + device simulation)
- Express (API + static frontend hosting)
- express-ws (WebSocket integration)
- PostgreSQL (persistent telemetry storage)
- systeminformation (device CPU temperature data)
- HTML + JavaScript (frontend dashboard)
git clone https://github.com/code-n-cool/upstream-app.git
cd upstream-app
npm install
Create a .env
file:
DB_USER=postgres
DB_PASSWORD=yourpassword
DB_HOST=localhost
DB_PORT=5432
DB_NAME=telemetrydb
DEVICE_SERIAL=device-001
SERVER_HOST=localhost
ts-node src/app.ts
ts-node src/device.ts
http://localhost:8080
- Start server and device.
- Device logs in and begins sending telemetry at default frequency.
- Backend stores data in PostgreSQL and pushes live updates to frontend.
- User opens the dashboard to see telemetry updates in real time.
- User sends Update Frequency or Reboot command from the UI.
- Add authentication & authorization for devices and frontend users.
- Implement historical charts for temperature trends.
- Add multi-device support with filtering in the dashboard.
- Deploy using Docker with PostgreSQL and Node.js services.
In this project, the simulated IoT device (device.ts
) can receive a reboot command from the backend.
By default, calling process.exit(0)
just ends the Node process.
To make it feel like a real device reboot, I use PM2 as a process manager to automatically restart the device when it exits.
npm install -g pm2
pm2 start src/device.ts --interpreter ts-node --name device-001
pm2 list
pm2 logs device-001
To simulate multiple IoT devices
pm2 start src/device.ts --interpreter ts-node --name device-002 -- --DEVICE_SERIAL=device-002
pm2 startup
pm2 save