From 7b8934b1d0b5d5b19d85cdc44c3f6d4eb1a37770 Mon Sep 17 00:00:00 2001 From: Naab2k3 Date: Tue, 24 Jun 2025 09:03:10 +0700 Subject: [PATCH] Update configuration and health check response structure in POE project. Modified config.py to replace IP addresses for Modbus hosts, ensuring accurate sensor location mapping. Refactored health_check.py to standardize response formatting for sensor data, enhancing clarity in health and sensor status reporting. Updated README.md to reflect changes in MQTT topic structure, aligning with new data point definitions for temperature, humidity, and CO2 sensors. --- README.md | 30 +++++++++++++++--------------- config.py | 6 +++--- sensor_bridge.py | 10 +++++----- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 66d90d1..21f9de2 100644 --- a/README.md +++ b/README.md @@ -73,26 +73,26 @@ python main.py The service uses a hierarchical topic structure for better organization: ``` -Location/{location_name}/{sensor_type}/Time -Location/{location_name}/{sensor_type}/Status -Location/{location_name}/{sensor_type}/Data/temperature -Location/{location_name}/{sensor_type}/Data/humidity -Location/{location_name}/{sensor_type}/Data/co2 # CO2 sensors only -Location/{location_name}/{sensor_type}/alerts # Alert messages +Location/{location_name}/{sensor_type}/Time # Timestamp +Location/{location_name}/{sensor_type}/Status # "online" or "offline" +Location/{location_name}/{sensor_type}/Temperature # Temperature value +Location/{location_name}/{sensor_type}/Humidity # Humidity value +Location/{location_name}/{sensor_type}/CO2 # CO2 sensors only +Location/{location_name}/{sensor_type}/alerts # Alert messages ``` ### Example Topics ``` -Location/Warehouse-B/temperature-humidity/Time → "2024-01-15 10:30:25" -Location/Warehouse-B/temperature-humidity/Status → "online" -Location/Warehouse-B/temperature-humidity/Data/temperature → "23.5" -Location/Warehouse-B/temperature-humidity/Data/humidity → "65.2" +Location/Warehouse-B/temperature-humidity/Time → "2024-01-15 10:30:25" +Location/Warehouse-B/temperature-humidity/Status → "online" +Location/Warehouse-B/temperature-humidity/Temperature → "23.5" +Location/Warehouse-B/temperature-humidity/Humidity → "65.2" -Location/Office/CO2-gas/Time → "2024-01-15 10:30:25" -Location/Office/CO2-gas/Status → "online" -Location/Office/CO2-gas/Data/temperature → "24.1" -Location/Office/CO2-gas/Data/humidity → "58.3" -Location/Office/CO2-gas/Data/co2 → "420" +Location/Office/CO2-gas/Time → "2024-01-15 10:30:25" +Location/Office/CO2-gas/Status → "online" +Location/Office/CO2-gas/Temperature → "24.1" +Location/Office/CO2-gas/Humidity → "58.3" +Location/Office/CO2-gas/CO2 → "420" ``` ### Alert Format diff --git a/config.py b/config.py index 8be72e5..70098dd 100644 --- a/config.py +++ b/config.py @@ -7,9 +7,9 @@ MODBUS_HOSTS = [ {"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"}, + {"ip": "10.84.48.100", "location": "Warehouse-A", "type": "temperature_humidity"}, + {"ip": "10.84.48.101", "location": "Lab-Room", "type": "temperature_humidity"}, + {"ip": "10.84.48.102", "location": "Office", "type": "cwt_co2"}, ] MODBUS_PORT = 505 UNIT_ID = 1 diff --git a/sensor_bridge.py b/sensor_bridge.py index b5887c8..2fb6a8b 100644 --- a/sensor_bridge.py +++ b/sensor_bridge.py @@ -87,8 +87,8 @@ def read_and_publish_temperature_humidity(mqtt_client, modbus_client, host_info) topics_data = [ (f"{base_topic}/Time", current_time), (f"{base_topic}/Status", "online"), - (f"{base_topic}/Data/temperature", round(temperature, 1)), - (f"{base_topic}/Data/humidity", round(humidity, 1)) + (f"{base_topic}/Temperature", round(temperature, 1)), + (f"{base_topic}/Humidity", round(humidity, 1)) ] all_published = True @@ -149,9 +149,9 @@ def read_and_publish_cwt_co2(mqtt_client, modbus_client, host_info): topics_data = [ (f"{base_topic}/Time", current_time), (f"{base_topic}/Status", "online"), - (f"{base_topic}/Data/temperature", round(temperature, 1)), - (f"{base_topic}/Data/humidity", round(humidity, 1)), - (f"{base_topic}/Data/co2", co2_ppm) + (f"{base_topic}/Temperature", round(temperature, 1)), + (f"{base_topic}/Humidity", round(humidity, 1)), + (f"{base_topic}/CO2", co2_ppm) ] all_published = True