feat: add MQTT support and configuration documentation

This commit is contained in:
Lutz Lang 2025-04-25 21:59:51 +02:00
parent 47f5507f4f
commit 25da1ac04b
3 changed files with 56 additions and 0 deletions

51
MQTT.md Normal file
View File

@ -0,0 +1,51 @@
# MQTT Configuration
This project can publish weather and public transport data to an MQTT broker.
To enable MQTT, follow these steps:
## 1. Install dependencies
Ensure you have Rust and Cargo installed. The MQTT support uses the Paho MQTT client crate.
Run:
```bash
cargo update
```
## 2. Set the MQTT_BROKER environment variable
Before running the client, define `MQTT_BROKER` to your broker address.
- Without URI scheme (defaults to TCP):
```bash
export MQTT_BROKER=localhost:1883
```
- With URI scheme:
```bash
export MQTT_BROKER=tcp://broker.example.com:1883
```
## 3. Run the LED board client
Pass the LED board IP address as the only argument:
```bash
export MQTT_BROKER=localhost:1883
cargo run --bin ledboard_client -- 192.168.1.50
```
## Topics and Payloads
The client publishes two topics:
### weather
JSON payload with fields:
- `dt`: timestamp (Unix seconds)
- `temp`: temperature in °C
- `weather`: object with `main`, `description`, `icon`
- `rain`: rain volume in last 3h (optional)
- `pop`: probability of precipitation
- `wind`: object with `speed`, `deg`, `gust`
### straba
JSON payload with fields:
- `outbound_station`: name of outbound station
- `outbound_diff`: seconds until outbound departure
- `inbound_station`: name of inbound station
- `inbound_diff`: seconds until inbound departure
## Customization
You can adjust MQTT topics, QoS, and message formats in `client/bin/src/main.rs` under the `publish_to_mqtt` function.

View File

@ -21,4 +21,5 @@ serde = "1.0"
serde_derive = "1.0" serde_derive = "1.0"
serde_json = "1.0" serde_json = "1.0"
# end of web stuff # end of web stuff
paho-mqtt = "0.13.2"
ping = "0.4.1" ping = "0.4.1"

View File

@ -414,6 +414,10 @@ fn main() -> ExitCode {
if device_online == true { if device_online == true {
// Render new image // Render new image
send_package(ip.to_string(), &last_data, &straba_res); send_package(ip.to_string(), &last_data, &straba_res);
// Publish data to MQTT
if let Some(ref client) = mqtt_client {
publish_to_mqtt(client, &last_data, &straba_res);
}
} }
} }
} }