Skip to content

hamedtorky/BMS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

26 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

BMS Server - Building Management System

A complete IoT Building Management System with remote OTA firmware updates, real-time monitoring, and secure MQTT communication. Monitor temperature, humidity, and environmental sensors using ESP32 nodes - update them wirelessly without physical access!

Architecture Docker Node.js PostgreSQL OTA

Features

🌑️ Sensor Monitoring

  • Real-time temperature, humidity, and dew point readings
  • Support for multiple ESP32 sensor nodes
  • WiFi signal strength monitoring
  • Auto-refresh monitoring dashboard

πŸ”’ Secure Communication

  • TLS-encrypted MQTT connections (port 8883)
  • Certificate-based authentication
  • Access control lists (ACL)
  • User authentication for web interface

πŸ“Š Web Dashboard

  • Node management interface
  • Live sensor monitoring with auto-refresh
  • Real-time charts (temperature & humidity history)
  • Historical data viewing
  • Responsive design

πŸ”Œ API Integration

  • RESTful API for node management
  • Public API for sensor data (no auth required)
  • WebSocket support for real-time updates
  • JSON-based data exchange

πŸ”„ OTA Firmware Updates ⭐

  • Remote firmware updates for ESP32 nodes
  • Upload .bin files via web interface
  • One-click OTA trigger for any node
  • Real-time update progress monitoring
  • Firmware version tracking
  • No physical access needed after initial setup
  • Update multiple nodes sequentially

πŸš€ Easy Deployment

  • One-command setup script
  • Docker Compose orchestration
  • Auto-generated ESP32 Arduino code
  • Automatic TLS certificate generation

Quick Start

Prerequisites

  • Docker Desktop installed
  • 2GB RAM minimum
  • Network access for ESP32 nodes

Installation

  1. Clone the repository

    git clone <your-repo-url> BMS-server
    cd BMS-server
  2. Run setup script

    ./setup.sh
  3. Access the system

    • Web Interface: http://<SERVER_IP>:8080
    • Login with credentials you created during setup
  4. Add sensor nodes

    • Click "Add Node" in the web interface
    • Get auto-generated ESP32 code with TLS certificate
    • Flash to your ESP32 device (first time only via USB)
  5. Update firmware remotely (Optional)

    • Go to Firmware tab
    • Upload new .bin file
    • Click OTA button on any node
    • Watch it update wirelessly! πŸš€

That's it! πŸŽ‰

System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ ESP32 Nodes β”‚ ← OTA Updates (WiFi)
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚ MQTT/TLS (8883)
       ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Mosquitto Broker β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Node.js API   │────→│ PostgreSQL β”‚
β”‚  (Port 3000)    β”‚     β”‚ Database   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Web Dashboard  β”‚
β”‚  (Port 8080)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Components

  • MQTT Broker: Eclipse Mosquitto with TLS
  • Database: PostgreSQL 15
  • API Server: Node.js with Express
  • Web Frontend: Vanilla JS + HTML/CSS
  • Sensor Nodes: ESP32 with Arduino

API Endpoints

Public API (No Authentication)

# Get all active sensors
curl http://<SERVER_IP>:3000/api/public/sensors

# Get specific sensor data
curl http://<SERVER_IP>:3000/api/public/sensors/node_1

Authenticated API

  • GET /api/nodes - List all nodes
  • POST /api/nodes - Create new node
  • GET /api/nodes/:id/data - Get sensor data
  • POST /api/firmware/upload - Upload firmware
  • POST /api/nodes/:id/ota-update - Trigger OTA update
  • More in DEPLOYMENT.md

Documentation

  • QUICKSTART_OTA.md - 5-minute OTA update guide

    • Quick setup for remote firmware updates
    • Step-by-step instructions
    • Troubleshooting tips
  • OTA_GUIDE.md - Complete OTA documentation

    • Detailed OTA setup & workflows
    • Building firmware binaries
    • Best practices & security
    • API reference
  • DEPLOYMENT.md - Complete deployment guide

    • Manual setup instructions
    • Troubleshooting
    • Docker commands
    • Security notes
    • Backup procedures
  • examples/ - ESP32 example sketches

    • OTA version (with remote update support)
    • TLS version
    • Simple version (no TLS)
    • SHT10 sensor integration

Hardware Requirements

Server

  • Any computer with Docker support
  • 2GB RAM minimum
  • Network connectivity

ESP32 Nodes

  • ESP32-S3 or compatible
  • SHT10/SHT11 temperature & humidity sensor
  • WiFi connectivity

Wiring Example (SHT10)

SHT10 DATA β†’ ESP32 GPIO 10
SHT10 SCK  β†’ ESP32 GPIO 11
SHT10 VCC  β†’ 3.3V
SHT10 GND  β†’ GND

Development

Project Structure

BMS-server/
β”œβ”€β”€ api/                      # Node.js API server
β”‚   β”œβ”€β”€ server.js            # Main API with OTA endpoints
β”‚   └── package.json
β”œβ”€β”€ web/                      # Web frontend
β”‚   β”œβ”€β”€ index.html           # Dashboard with Firmware tab
β”‚   β”œβ”€β”€ app.js               # Frontend logic
β”‚   └── styles.css
β”œβ”€β”€ mosquitto/                # MQTT broker config
β”‚   β”œβ”€β”€ config/              # Configuration files
β”‚   β”œβ”€β”€ certs/               # TLS certificates
β”‚   └── data/                # Persistent data
β”œβ”€β”€ firmware/                 # Uploaded firmware storage
β”œβ”€β”€ examples/
β”‚   β”œβ”€β”€ esp32_sht10/         # Standard TLS sketch
β”‚   └── esp32_sht10_ota/     # OTA-capable sketch ⭐
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ setup.sh                  # Automated setup
β”œβ”€β”€ DEPLOYMENT.md             # Deployment guide
β”œβ”€β”€ OTA_GUIDE.md              # Complete OTA documentation
└── QUICKSTART_OTA.md         # 5-minute OTA guide

Building from Source

# Build all containers
docker-compose build

# Start services
docker-compose up -d

# View logs
docker-compose logs -f

Contributing

Contributions welcome! Please feel free to submit pull requests or open issues.

License

See LICENSE file for details.

Features Overview

Feature Status Description
🌑️ Sensor Monitoring βœ… Real-time temperature, humidity, dew point
πŸ“Š Web Dashboard βœ… 3 tabs: Nodes, Monitor, Firmware
πŸ“ˆ Live Charts βœ… Temperature & humidity history graphs
πŸ”’ TLS Encryption βœ… Secure MQTT on port 8883
πŸ”„ OTA Updates βœ… Remote firmware updates via web UI
🌐 Public API βœ… No-auth sensor data endpoint
πŸ” Authentication βœ… JWT-based user authentication
🐳 Docker Deploy βœ… One-command setup script
πŸ“± Auto-Generated Code βœ… ESP32 sketch with credentials
πŸ’Ύ Data Persistence βœ… PostgreSQL with historical data

OTA Update Quick Example

# 1. Build your firmware in Arduino IDE
# 2. Upload via web interface (Firmware tab)
# 3. Click OTA button on node
# 4. Done! Node updates and reboots automatically

No more climbing ladders to update sensors! πŸͺœβŒ

Tested Hardware

  • βœ… ESP32-S3 DevKit
  • βœ… SHT10/SHT11 sensors
  • βœ… Docker on macOS/Linux/Windows
  • βœ… OTA updates over WiFi

Support

  • Check DEPLOYMENT.md for troubleshooting
  • Review OTA_GUIDE.md for OTA issues
  • Docker logs: docker-compose logs
  • ESP32 Serial Monitor: 115200 baud

Troubleshooting Common Issues

OTA not working?

  • Ensure ESP32 is running OTA-capable firmware
  • Check Serial Monitor for "ESP32-S3 BMS Node with OTA"
  • Verify node is subscribed to command topic

Can't upload firmware?

  • Hard refresh browser (Ctrl+Shift+R)
  • Check file is .bin format
  • Max file size: 10MB

Node not connecting?

  • Verify MQTT credentials
  • Check TLS certificate is loaded
  • Ensure WiFi is connected

Made with ❀️ for IoT and Building Automation

Repository: https://github.com/hamedtorky/BMS

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published