Update README.md and sensor_bridge.py to reflect changes in MQTT topic structure. Transitioned from a hierarchical to a flat topic structure for improved organization, simplifying the topic format for each location. Adjusted sensor publishing methods in sensor_bridge.py to align with the new topic structure, ensuring accurate data representation for temperature, humidity, and CO2 sensors.

This commit is contained in:
Naab2k3
2025-06-24 10:42:24 +07:00
parent 84e7babf7e
commit e83f614182
2 changed files with 20 additions and 24 deletions

View File

@ -70,29 +70,31 @@ python main.py
## 📈 Data Format & Topics ## 📈 Data Format & Topics
### MQTT Topic Structure ### 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}/Time # Timestamp
Location/{location_name}/{sensor_type}/Status # "online" or "offline" Location/{location}/Status # "online" or "offline"
Location/{location_name}/{sensor_type}/Temperature # Temperature value Location/{location}/Temperature # Temperature value
Location/{location_name}/{sensor_type}/Humidity # Humidity value Location/{location}/Humidity # Humidity value
Location/{location_name}/{sensor_type}/CO2 # CO2 sensors only Location/{location}/CO2 # CO2 sensors only
Location/{location_name}/{sensor_type}/alerts # Alert messages Location/{location}/alerts # Alert messages
``` ```
> **Note:** The `CO2` topic is only published for sensors that support CO2 measurement.
### Example Topics ### Example Topics
``` ```
Location/Warehouse-B/temperature-humidity/Time → "2024-01-15 10:30:25" Location/Warehouse-B/Time → "2024-01-15 10:30:25"
Location/Warehouse-B/temperature-humidity/Status → "online" Location/Warehouse-B/Status → "online"
Location/Warehouse-B/temperature-humidity/Temperature → "23.5" Location/Warehouse-B/Temperature → "23.5"
Location/Warehouse-B/temperature-humidity/Humidity → "65.2" Location/Warehouse-B/Humidity → "65.2"
Location/Office/CO2-gas/Time → "2024-01-15 10:30:25" Location/Office/Time → "2024-01-15 10:30:25"
Location/Office/CO2-gas/Status → "online" Location/Office/Status → "online"
Location/Office/CO2-gas/Temperature → "24.1" Location/Office/Temperature → "24.1"
Location/Office/CO2-gas/Humidity → "58.3" Location/Office/Humidity → "58.3"
Location/Office/CO2-gas/CO2 → "420" Location/Office/CO2 → "420"
``` ```
### Alert Format ### Alert Format

View File

@ -79,11 +79,8 @@ def read_and_publish_temperature_humidity(mqtt_client, modbus_client, host_info)
# Publish data # Publish data
location = host_info["location"] location = host_info["location"]
sensor_type = "temperature-humidity"
current_time = datetime.now(LOCAL_TIMEZONE).strftime("%Y-%m-%d %H:%M:%S") current_time = datetime.now(LOCAL_TIMEZONE).strftime("%Y-%m-%d %H:%M:%S")
base_topic = f"Location/{location}"
base_topic = f"Location/{location}/{sensor_type}"
topics_data = [ topics_data = [
(f"{base_topic}/Time", current_time), (f"{base_topic}/Time", current_time),
(f"{base_topic}/Status", "online"), (f"{base_topic}/Status", "online"),
@ -141,11 +138,8 @@ def read_and_publish_cwt_co2(mqtt_client, modbus_client, host_info):
# Publish data # Publish data
location = host_info["location"] location = host_info["location"]
sensor_type = "CO2-gas"
current_time = datetime.now(LOCAL_TIMEZONE).strftime("%Y-%m-%d %H:%M:%S") current_time = datetime.now(LOCAL_TIMEZONE).strftime("%Y-%m-%d %H:%M:%S")
base_topic = f"Location/{location}"
base_topic = f"Location/{location}/{sensor_type}"
topics_data = [ topics_data = [
(f"{base_topic}/Time", current_time), (f"{base_topic}/Time", current_time),
(f"{base_topic}/Status", "online"), (f"{base_topic}/Status", "online"),