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:
70
config.py
70
config.py
@ -1,20 +1,78 @@
|
||||
import time
|
||||
|
||||
# Modbus configuration
|
||||
MODBUS_HOST = "10.84.48.153"
|
||||
MODBUS_HOSTS = [
|
||||
{"ip": "10.84.60.31", "location": "Warehouse-B", "type": "temperature_humidity"},
|
||||
{"ip": "10.84.60.32", "location": "Warehouse-C", "type": "temperature_humidity"},
|
||||
{"ip": "10.84.60.33", "location": "Dyeing-Kitchen", "type": "temperature_humidity"},
|
||||
{"ip": "10.84.60.34", "location": "Second-Floor", "type": "temperature_humidity"},
|
||||
{"ip": "10.84.60.35", "location": "Warehouse-A", "type": "temperature_humidity"},
|
||||
{"ip": "10.84.60.36", "location": "Lab-Room", "type": "temperature_humidity"},
|
||||
{"ip": "10.84.60.37", "location": "Office", "type": "cwt_co2"},
|
||||
]
|
||||
MODBUS_PORT = 505
|
||||
UNIT_ID = 1
|
||||
|
||||
# MQTT configuration
|
||||
MQTT_BROKER = "mqtt.service.mesh"
|
||||
MQTT_PORT = 1883
|
||||
MQTT_TOPIC = "Temperature_Humidity"
|
||||
# Legacy topic - now using dynamic topic structure: {location}/{sensor_type}/data
|
||||
MQTT_TOPIC = "Temperature_Humidity" # Keep for backward compatibility
|
||||
MQTT_CLIENT_ID = f"modbus-mqtt-client-{int(time.time())}"
|
||||
MQTT_USERNAME = "relay"
|
||||
MQTT_PASSWORD = "Sey@K9c&Q4^"
|
||||
|
||||
# Location information
|
||||
LOCATION = "Office"
|
||||
|
||||
# Read and publish cycle configuration (seconds)
|
||||
PUBLISH_INTERVAL = 10
|
||||
PUBLISH_INTERVAL = 10
|
||||
|
||||
# Health check and alerting configuration
|
||||
HEALTH_CHECK_PORT = 8080
|
||||
HEALTH_CHECK_ENABLED = True
|
||||
|
||||
# Alerting configuration
|
||||
ALERTING_ENABLED = True
|
||||
SENSOR_TIMEOUT_THRESHOLD = 3 # Number of consecutive failures before alert
|
||||
RECOVERY_CONFIRMATION_COUNT = 2 # Number of consecutive successes to confirm recovery
|
||||
|
||||
# Sensor status tracking - now integrated into data payload
|
||||
# New topic structure: Location/{location_name}/{sensor_type}/{data_type}
|
||||
# Where sensor_type is: "temperature-humidity" or "CO2-gas"
|
||||
# Where data_type is: "data" or "alerts"
|
||||
# Example topics:
|
||||
# - Location/Warehouse-B/temperature-humidity/data (contains temp, humidity, status)
|
||||
# - Location/Office/CO2-gas/data (contains co2, temp, humidity, status)
|
||||
# - Location/Warehouse-B/temperature-humidity/alerts (contains failure/recovery alerts)
|
||||
|
||||
# New MQTT Topic Structure:
|
||||
# Base: Location/{location_name}/{sensor_type}/{data_type}
|
||||
#
|
||||
# Data topics: Location/{location_name}/{sensor_type}/data
|
||||
# Alert topics: Location/{location_name}/{sensor_type}/alerts
|
||||
#
|
||||
# Payload format for data (JSON):
|
||||
# {
|
||||
# "timestamp": "2024-01-01 12:00:00",
|
||||
# "location": "Warehouse-B",
|
||||
# "sensor_type": "temperature-humidity",
|
||||
# "ip": "10.84.60.31",
|
||||
# "status": "online|offline",
|
||||
# "data": {
|
||||
# "temperature": 25.5,
|
||||
# "humidity": 60.2
|
||||
# }
|
||||
# }
|
||||
#
|
||||
# Payload format for alerts (JSON):
|
||||
# {
|
||||
# "alert_type": "sensor_failure|sensor_recovery",
|
||||
# "timestamp": "2024-01-01T12:00:00.000000+00:00",
|
||||
# "sensor_id": "10.84.60.31_Warehouse-B",
|
||||
# "sensor_ip": "10.84.60.31",
|
||||
# "sensor_location": "Warehouse-B",
|
||||
# "sensor_type": "temperature_humidity",
|
||||
# "consecutive_failures": 3,
|
||||
# "last_error": "Failed to read data",
|
||||
# "severity": "critical|info"
|
||||
# }
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user