LED-BOARD/client/MQTT.md
2025-04-26 00:09:40 +02:00

51 lines
1.5 KiB
Markdown

# 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.