Real-time temperature monitoring for hospital medicine cabinets, with WebSocket alerts and MQTT-connected devices.
技術構成
What the system does#
SMTrack+ monitors the temperature of medicine cabinets across a hospital and reports on it through a set of RESTful APIs. The web client is built with a modern front-end stack, and state management was part of the design from day one — readings do not trickle in, they stream continuously from dozens of cabinets at once.
How a reading reaches the screen#
- An embedded device inside each cabinet samples temperature and humidity, then publishes to its own MQTT topic.
- The server subscribes to every topic, persists each reading to PostgreSQL, and checks it against the configured safe range.
- When a reading falls out of range the server broadcasts over
WebSocket, so any dashboard already open updates itself — nobody has to refresh. - The client keeps the latest values in one store, so the charts, the summary cards and the alert list can never disagree with each other.
javascript
client.subscribe('smtrack/+/temperature', { qos: 1 })
client.on('message', (topic, payload) => {
const deviceId = topic.split('/')[1]
const reading = JSON.parse(payload.toString())
void readings.save(deviceId, reading)
if (readings.isOutOfRange(reading)) gateway.emit('alert', { deviceId, reading })
})An alert that arrives five minutes late is barely different from having no alerting at all.
Shipping and keeping it running#
- Configured GitHub Actions to build and deploy automatically on every merge into the main branch.
- Kept staging and production on separate environments so changes are exercised before they reach a live ward.
- Logged device disconnects separately from application errors, which cut on-site debugging time considerably.
| Layer | Technology | Responsibility |
|---|---|---|
| Web app | Next.js + TypeScript | Dashboard, history charts, device configuration |
| API | NestJS + PostgreSQL | Reading storage and alerting rules |
| Devices | MQTT | Publish sensor readings from inside each cabinet |
| Alerts | WebSocket | Push state changes to open dashboards instantly |