diff --git a/README.md b/README.md index d153f3e..c66845c 100644 --- a/README.md +++ b/README.md @@ -70,29 +70,31 @@ python main.py ## 📈 Data Format & Topics ### MQTT Topic Structure -The service uses a hierarchical topic structure for better organization: +The service uses a flat topic structure for each location: ``` -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 +Location/{location}/Time # Timestamp +Location/{location}/Status # "online" or "offline" +Location/{location}/Temperature # Temperature value +Location/{location}/Humidity # Humidity value +Location/{location}/CO2 # CO2 sensors only +Location/{location}/alerts # Alert messages ``` +> **Note:** The `CO2` topic is only published for sensors that support CO2 measurement. + ### 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/Temperature → "23.5" -Location/Warehouse-B/temperature-humidity/Humidity → "65.2" +Location/Warehouse-B/Time → "2024-01-15 10:30:25" +Location/Warehouse-B/Status → "online" +Location/Warehouse-B/Temperature → "23.5" +Location/Warehouse-B/Humidity → "65.2" -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" +Location/Office/Time → "2024-01-15 10:30:25" +Location/Office/Status → "online" +Location/Office/Temperature → "24.1" +Location/Office/Humidity → "58.3" +Location/Office/CO2 → "420" ``` ### Alert Format diff --git a/sensor_bridge.py b/sensor_bridge.py index 955d767..5cc2e80 100644 --- a/sensor_bridge.py +++ b/sensor_bridge.py @@ -79,11 +79,8 @@ def read_and_publish_temperature_humidity(mqtt_client, modbus_client, host_info) # Publish data location = host_info["location"] - sensor_type = "temperature-humidity" current_time = datetime.now(LOCAL_TIMEZONE).strftime("%Y-%m-%d %H:%M:%S") - - base_topic = f"Location/{location}/{sensor_type}" - + base_topic = f"Location/{location}" topics_data = [ (f"{base_topic}/Time", current_time), (f"{base_topic}/Status", "online"), @@ -141,11 +138,8 @@ def read_and_publish_cwt_co2(mqtt_client, modbus_client, host_info): # Publish data location = host_info["location"] - sensor_type = "CO2-gas" current_time = datetime.now(LOCAL_TIMEZONE).strftime("%Y-%m-%d %H:%M:%S") - - base_topic = f"Location/{location}/{sensor_type}" - + base_topic = f"Location/{location}" topics_data = [ (f"{base_topic}/Time", current_time), (f"{base_topic}/Status", "online"),