This project is a comprehensive solution for managing smart streetlight systems with integrated features such as user management, device control, energy analytics, alert notifications, and monitoring through embedded Power BI dashboards. The application supports database configurations for MySQL, PostgreSQL, and MongoDB, with a flexible API and service-based structure.
- Features
- Technologies Used
- Project Structure
- Installation
- Configuration
- Endpoint Usage
- Testing
- User and Role Management with authentication
- Device Management for smart streetlights
- Real-time Control of streetlights with MQTT integration
- Energy Consumption Analytics
- Alert Notifications and Logging
- Multi-database configuration (MySQL, PostgreSQL, MongoDB)
- Rate Limiting with Redis support
- Embedded Power BI Dashboard for monitoring and reporting
- Flask: Web framework
- SQLAlchemy: ORM for database interactions
- Flask-RESTful: RESTful API development
- Redis: Session and rate limiting management
- MQTT (with CloudMQTT): Communication protocol for IoT control
- Power BI Embedded: Dashboard visualization
- PostgreSQL, MySQL, MongoDB: Database options
- Gunicorn: Application server
- pytest, pytest-cov, Faker: Testing and data generation
- Docker: Containerization
/smart-streetlight-system
│
├── app/
│ ├── __init__.py # Initializes the Flask app
│ ├── config.py # Application configuration
│ ├── models/ # Database models
│ │ ├── user.py # User model
│ │ ├── role.py # Role and permission model
│ │ ├── device.py # Streetlight device model
│ │ ├── alert.py # Alert model
│ │ ├── energy.py # Energy analysis data model
│ │ ├── log.py # Log model
│ ├── api/ # API modules
│ │ ├── user_api.py # User management API
│ │ ├── role_api.py # Role management API
│ │ ├── device_api.py # Device management API
│ │ ├── alert_api.py # Alert management API
│ │ ├── energy_api.py # Energy analysis API
│ │ ├── control_api.py # Streetlight control API
│ │ ├── map_api.py # Map monitoring API
│ │ ├── meter_api.py # Remote meter reading API
│ │ ├── strategy_api.py # Strategy management API
│ │ ├── db_config_api.py # Database configuration wizard API
│ ├── services/ # Service layer
│ ├── utils/ # Utility functions
│
├── migrations/ # Database migrations
├── tests/ # Unit and integration tests
├── dashboard/ # Power BI Dashboard views
├── requirements.txt # Project dependencies
├── run.py # Application entry point
└── README.md # Project documentation
-
Clone the repository:
git clone https://github.com/yourusername/smart-streetlight-system.git cd smart-streetlight-system -
Install dependencies:
pip install -r requirements.txt
-
Configure environment variables (e.g.,
DATABASE_URL,MQTT_BROKER_URL). -
Run migrations:
flask db upgrade
-
Start the application:
gunicorn -w 4 run:app
- Database: Configure
DATABASE_URLfor PostgreSQL/MySQL andMONGO_URIfor MongoDB inconfig.py. - Redis: Set
REDIS_URLfor session and rate limit storage. - MQTT: Configure
MQTT_BROKER_URLandMQTT_PORT. - Power BI: Embed settings in
dashboard/templates.
POST /api/register- Register a new userPOST /api/login- Login and receive a tokenGET /api/users- Get all users (admin-only)GET /api/users/<id>- Get specific user details
GET /api/roles- Retrieve rolesPOST /api/roles- Create a new role
GET /api/devices- List all devicesPOST /api/devices- Create a new deviceGET /api/devices/<id>- Retrieve device detailsPUT /api/devices/<id>- Update deviceDELETE /api/devices/<id>- Delete device
GET /api/alerts- Get active alertsPOST /api/alerts- Create a new alertDELETE /api/alerts/<id>- Remove an alert
GET /api/energy- Retrieve energy usage dataPOST /api/energy- Upload energy usage data
POST /api/control/on- Turn on streetlightPOST /api/control/off- Turn off streetlight
GET /api/map/devices- Retrieve location data for all devices
GET /api/meter/read- Retrieve meter data for devices
POST /api/strategy- Define new strategyGET /api/strategy- Get current strategies
POST /api/db_config- Configure selected database (MySQL, PostgreSQL, or MongoDB)
This project includes unit and integration tests for comprehensive validation. Testing utilities include pytest with pytest-cov for coverage and Faker for mock data generation.
-
Run tests:
pytest --cov=app tests/
-
Generate test data:
- Use
Fakerintests/fixtures/fake_data_generator.pyto create mock data for testing scenarios.
- Use