LibGuardian is an intelligent Wireless Sensor Network (WSN) designed to monitor noise levels and occupancy in library environments. The system provides real-time insights into library conditions, helping staff maintain optimal study environments and enabling students to find quieter spaces.
Libraries are meant to be quiet, focused spaces for learning and research. However, managing noise levels and occupancy across different areas can be challenging for library staff. LibGuardian addresses this by:
- Real-time Monitoring: Continuous tracking of noise levels and people count
- Data-Driven Insights: Historical analysis to identify patterns and peak usage times
- Staff Alerts: Automated notifications when areas become too noisy or crowded
- Student Benefits: Live data access to help students find optimal study spots
- Scalable Design: Easily expandable to monitor multiple rooms and floors
- π Noise Level Monitoring: Real-time sound measurement with decibel conversion
- π₯ Occupancy Tracking: Smart entry/exit detection using ultrasonic sensors
- π Interactive Dashboard: Beautiful Grafana visualizations with live data updates
- π Wireless Communication: Multiple protocols (Wi-Fi, MQTT, NullNet)
- πΎ Data Storage: MySQL database for historical analysis
- π Real-time Processing: Node-RED for seamless data flow management
LibGuardian consists of several interconnected components:
- Grove Sound Sensor: Measures ambient noise levels
- HC-SR04 Ultrasonic Sensors: Detect people entering/exiting (2 sensors per door)
- Arduino Board: Main processing unit for sound sensor
- ESP32-S2: Wireless data transmission for proximity sensors
- OpenMote: Wireless bridge for Arduino sensor data
- Zolertia Board: Central receiver and data aggregator
- Node-RED: Data flow orchestration and processing
- MySQL: Persistent data storage and analytics
- HiveMQ: MQTT broker for real-time communication
- Grafana: Interactive dashboards and data visualization
- Contiki-ng: Operating system for IoT devices and wireless sensor networks
- Sensors collect noise and proximity data
- Data transmitted wirelessly via MQTT/NullNet protocols
- Node-RED processes and stores data in MySQL
- Grafana displays real-time dashboards
- System calculates occupancy and noise trends
Before starting the deployment, ensure you have:
- Hardware: All sensor components and microcontrollers listed above
- Software:
- Node.js (v14+)
- MySQL Server (v8.0+)
- Arduino IDE
- Grafana (v9.0+)
- Git
git clone https://github.com/yourusername/LibGuardian.git
cd LibGuardian
-
Install MySQL (if not already installed):
# Ubuntu/Debian sudo apt update sudo apt install mysql-server # macOS brew install mysql # Windows # Download from https://dev.mysql.com/downloads/mysql/
-
Create the database:
mysql -u root -p
CREATE DATABASE libguardian; USE libguardian;
-
Import the schema:
mysql -u root -p libguardian < database/schema.sql
Alternatively, you can open the database/schema.sql file, copy its contents, and execute them manually in your MySQL client.
To work with Contiki-NG, you need a compatible environment with a supported toolchain.
-
macOS: Follow the official installation guide for macOS:
π Toolchain Installation on macOS -
Linux: Follow the official installation guide for Linux:
π Toolchain Installation on Linux -
Windows: Itβs recommended to create a Linux-based virtual machine (e.g., using VirtualBox or WSL2), then follow the Linux guide above.
Official Contiki-NG documentation:
π https://docs.contiki-ng.org
- Open Arduino IDE
- Load
noise-arduino-code/noise-arduino-code.ino
- Install required libraries:
- Grove Sound Sensor library
- Connect the Grove Sound Sensor to your Arduino
- Upload the code to your Arduino board
- In Arduino IDE, add ESP32 board support:
- File β Preferences β Additional Board Manager URLs
- Add:
https://dl.espressif.com/dl/package_esp32_index.json
- Install ESP32 boards via Board Manager
- Load
proximity-esp32-code/proximity-esp32-code.ino
- Update WiFi credentials in the code:
const char* ssid = "YOUR_WIFI_SSID"; const char* password = "YOUR_WIFI_PASSWORD";
- Connect HC-SR04 sensor to ESP32
- Upload the code
- Navigate to the openmote-sender directory:
cd openmote-sender
- Compile and flash:
make TARGET=openmote BOARD=openmote-b savetarget make distclean make sender.upload PORT=YOUR_PORT make login PORT=YOUR_PORT
- Navigate to the zolertia-receiver directory:
cd zolertia-reciver
- Compile and flash:
make TARGET=zoul BOARD=remote-reva reciver make distclean make reciver.upload PORT=YOUR_PORT make login PORT=YOUR_PORT
-
Install Node-RED
Follow the official tutorial to install and set up Node-RED locally:
π https://nodered.org/docs/getting-started/local -
Install required nodes:
npm install -g node-red-node-mysql npm install -g node-red-contrib-mqtt-broker npm install -g node-red-node-serialport
-
Start Node-RED:
node-red
-
Import flows:
- Open http://localhost:1880
- Go to Menu β Import
- Copy and paste the content from
node-red/flows.json
- Click Import
-
Configure MySQL connection:
- Double-click any MySQL node in the flow
- Enter your database credentials:
- Host: localhost
- Port: 3306
- Database: libguardian
- Username: your_mysql_username
- Password: your_mysql_password
-
Configure MQTT nodes:
- Update MQTT broker settings in all MQTT nodes
- Enter your HiveMQ or local broker credentials
-
Deploy the flows:
- Click the red "Deploy" button in the top-right corner
- Install Grafana:
# Ubuntu/Debian sudo apt-get install -y software-properties-common sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main" wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add - sudo apt-get update sudo apt-get install grafana # macOS brew install grafana # Start Grafana sudo systemctl start grafana-server # Linux brew services start grafana # macOS
If you have any doubts or problems follow the official tutorial to install Grafana locally:
π https://grafana.com/docs/grafana/latest/setup-grafana/installation/
Note
You could also try using Grafana Cloud instead of hosting Grafana locally.
-
Access Grafana:
- Open http://localhost:3000
- Default login: admin/admin
- Change password when prompted
-
Add MySQL data source:
- Go to Configuration β Data Sources
- Click "Add data source"
- Select MySQL
- Configure connection:
- Host: localhost:3306
- Database: libguardian
- User: your_mysql_username
- Password: your_mysql_password
- Test connection and save
-
Import dashboard:
- Go to Create β Import
- Copy the content from
grafana/dashboards.json
- Paste and import
- Select your MySQL data source when prompted
-
Sensor Placement:
- Install sound sensor in a central location of each room
- Mount two HC-SR04 sensors on door frames (one for entry, one for exit)
- Ensure sensors have clear line of sight and proper power supply
-
Power Setup:
- Connect power banks or USB power supplies to all devices
- Ensure continuous power for 24/7 operation
-
Network Configuration:
- Verify all wireless devices can connect to your network
- Test MQTT connectivity from ESP32 devices
-
Test individual components:
# Check Node-RED logs # View in browser at http://localhost:1880 # Check Grafana dashboard # View at http://localhost:3000 # Verify database data mysql -u root -p libguardian -e "SELECT * FROM sensor_events ORDER BY timestamp DESC LIMIT 10;"
-
Test sensor functionality:
- Walk through monitored doors to test occupancy detection
- Generate noise to test sound level monitoring
- Verify data appears in Grafana dashboard within 2-3 seconds
-
Validate data accuracy:
- Compare sensor readings with manual measurements
- Check timestamp accuracy
- Verify occupancy counting logic
Once deployed, you can access your LibGuardian dashboard at http://localhost:3000
. The dashboard provides:
- Current Occupancy: Live count of people in each monitored room
- Noise Level Gauge: Current decibel readings with color-coded alerts
- Historical Trends: Time-series graphs showing patterns over time
- Comparative Analysis: Side-by-side comparison of multiple rooms
- People count with entry/exit tracking
- Noise levels in decibels (dB SPL)
- Peak usage times and quiet periods
- Historical data for trend analysis
Sensors not reporting data:
- Check power connections
- Verify WiFi/network connectivity
- Review Node-RED debug messages
- Ensure MQTT broker is accessible
Database connection errors:
- Verify MySQL service is running
- Check database credentials in Node-RED
- Confirm firewall settings allow connections
Grafana dashboard not updating:
- Check data source configuration
- Verify MySQL queries in panel settings
- Review Grafana logs for errors
Inaccurate occupancy counting:
- Calibrate ultrasonic sensor positioning
- Adjust detection thresholds in code
- Verify sensor triggering sequence
# Check Node-RED status
sudo systemctl status node-red
# View MySQL logs
sudo tail -f /var/log/mysql/error.log
# Check Grafana logs
sudo tail -f /var/log/grafana/grafana.log
# Test MQTT connectivity
mosquitto_pub -h your-broker-host -t test/topic -m "test message"
mosquitto_sub -h your-broker-host -t libguardian/sensors/+
- Monitor sensor battery levels (if using battery power)
- Clean ultrasonic sensors for accurate readings
- Review and archive old database records
- Update dashboard queries as needed
- Backup database regularly
- Index database tables for faster queries
- Adjust sensor reading intervals based on requirements
- Optimize Node-RED flows for better performance
- Monitor system resource usage
We welcome contributions to LibGuardian! Please feel free to:
- Report bugs and issues
- Suggest new features
- Submit pull requests
- Improve documentation
For questions, issues, or support:
- Open an issue on GitHub
- Check the troubleshooting section above
- Review Node-RED and Grafana documentation
- Contact the development team