Enhance POE project with health check server, sensor tracking, and dynamic MQTT topic structure. Updated configuration for multiple Modbus hosts and added alerting system for sensor failures and recoveries. Improved logging and error handling throughout the application.

This commit is contained in:
Naab2k3
2025-06-23 09:14:40 +07:00
parent ad87c01f34
commit 81ab6191da
15 changed files with 752 additions and 222 deletions

View File

@ -46,6 +46,10 @@ python main.py
- **Data Processing**: Converts raw sensor values to calibrated readings
- **Error Handling**: Robust error handling and retry mechanisms
- **Logging**: Comprehensive logging for monitoring and debugging
- **Health Check API**: HTTP endpoints for system health monitoring
- **Sensor Status Tracking**: Real-time tracking of individual sensor health
- **Alerting System**: Automatic alerts for sensor failures and recovery
- **Recovery Detection**: Detects when failed sensors come back online
## 📈 Data Format
@ -77,6 +81,51 @@ All configuration is centralized in `config.py`:
- **Register 0**: Temperature (raw value × 0.1 - 40)
- **Register 1**: Humidity (raw value × 0.1)
## 🏥 Health Check & Monitoring
### Health Check Endpoints
The service provides HTTP endpoints for monitoring:
- **http://localhost:8080/health** - Basic service health check
- **http://localhost:8080/sensors** - Detailed sensor status information
### Alerting System
The system automatically sends MQTT alerts for:
- **Sensor Failures**: When a sensor fails 3 consecutive times
- **Sensor Recovery**: When a failed sensor comes back online
Alert topics:
- `sensor-alerts` - Failure and recovery alerts
- `sensor-status/{location}/status` - Individual sensor status updates
### Demo Monitoring Script
Use the demo script to test monitoring features:
```bash
# Check health endpoint
python demo_monitoring.py health
# Check sensors status
python demo_monitoring.py sensors
# Monitor system for 5 minutes
python demo_monitoring.py monitor 300
```
### Configuration Options
| Parameter | Description | Default |
|-----------|-------------|---------|
| `HEALTH_CHECK_ENABLED` | Enable/disable health check server | True |
| `HEALTH_CHECK_PORT` | HTTP server port | 8080 |
| `ALERTING_ENABLED` | Enable/disable MQTT alerts | True |
| `SENSOR_TIMEOUT_THRESHOLD` | Failures before alert | 3 |
| `RECOVERY_CONFIRMATION_COUNT` | Successes to confirm recovery | 2 |
## 🛠️ Maintenance
### Running as a Service
@ -118,4 +167,4 @@ The service provides comprehensive logging. Monitor the logs for:
## 📝 License
This project is licensed under the MIT License.
This project is licensed under the MIT License.