|
35 | 35 | MQTT_PASSWORD = None
|
36 | 36 | MQTT_TLS = False
|
37 | 37 | MQTT_PREFIX = "sensor/rtl_433"
|
| 38 | +MQTT_INDIVIDUAL_TOPICS = True |
| 39 | +MQTT_JSON_TOPIC = True |
38 | 40 |
|
39 | 41 | def mqtt_connect(client, userdata, flags, rc):
|
40 | 42 | """Handle MQTT connection callback."""
|
@@ -76,22 +78,23 @@ def publish_sensor_to_mqtt(mqttc, data, line):
|
76 | 78 | elif "id" in data:
|
77 | 79 | path += "/" + str(data["id"])
|
78 | 80 |
|
79 |
| - # Publish some specific items on subtopics. |
80 |
| - if "battery_ok" in data: |
81 |
| - mqttc.publish(path + "/battery", data["battery_ok"]) |
| 81 | + if MQTT_INDIVIDUAL_TOPICS: |
| 82 | + # Publish some specific items on subtopics. |
| 83 | + if "battery_ok" in data: |
| 84 | + mqttc.publish(path + "/battery", data["battery_ok"]) |
82 | 85 |
|
83 |
| - if "humidity" in data: |
84 |
| - mqttc.publish(path + "/humidity", data["humidity"]) |
| 86 | + if "humidity" in data: |
| 87 | + mqttc.publish(path + "/humidity", data["humidity"]) |
85 | 88 |
|
86 |
| - if "temperature_C" in data: |
87 |
| - mqttc.publish(path + "/temperature", data["temperature_C"]) |
| 89 | + if "temperature_C" in data: |
| 90 | + mqttc.publish(path + "/temperature", data["temperature_C"]) |
88 | 91 |
|
89 |
| - if "depth_cm" in data: |
90 |
| - mqttc.publish(path + "/depth", data["depth_cm"]) |
91 |
| - |
92 |
| - # Publish the entire json string on the main topic. |
93 |
| - mqttc.publish(path, line) |
| 92 | + if "depth_cm" in data: |
| 93 | + mqttc.publish(path + "/depth", data["depth_cm"]) |
94 | 94 |
|
| 95 | + if MQTT_JSON_TOPIC: |
| 96 | + # Publish the entire json string on the main topic. |
| 97 | + mqttc.publish(path, line) |
95 | 98 |
|
96 | 99 | def parse_syslog(line):
|
97 | 100 | """Try to extract the payload from a syslog line."""
|
|
0 commit comments