This is a linux daemon application for Raspberry PI, which receives control commands via MQTT to set GPIO ports of Raspberry.
As MQTT is widely supported within different home automation systems, this daemon application should be quite easily be integrated, for example in [OpenHAB](https://www.openhab.org/)
For further information, how to configure and use OpenHAB MQTT Binding, please see [here](https://www.openhab.org/addons/bindings/mqtt.generic/)
- Again, this command refers to example config as described below. If you have configured different pin names, broker address, or topic prefix, you have of course to adapt the command according to your configuration.
- edit the configuration file `/etc/rpicontrol/rpicontrol.conf` to your needs, see chapter _Configuration_
- reload systemd, enable and start service:
```
sudo systemctl daemon-reload
sudo systemctl enable rpicontrol.service
sudo systemctl start rpicontrol.service
```
## Configuration
### Example Configuration
Configuration file has YAML syntax, and shall have following structure.
Please note that optional values are not needed for configuration, see _Available Parameters_
```
mqtt-config:
broker-address: "tcp://localhost:1883"
connect-timeout-ms: 10000
connect-retry-interval-ms: 10000
max-reconnect-interval-ms: 10000
topic-prefix: "/rpicontrol"
username: "rpicontrol"
password: "my_password"
pin-control-config:
gpio-pins:
- number: 17
name: out1
direction: Output
pull-config: PullOff
send-polling-events: false
send-change-events: true
initial-state: "OFF"
polling-time-ms: 100
```
### Available Parameters
- **mqtt-config**: section for configuring MQTT Broker Connection
- **broker-address**: URL for MQTT Broker. Example Value: "tcp://localhost:1883"
- **connect-timeout-ms**: (optional) timeout in milliseconds for connection
- **connect-retry-interval-ms**: (optional) connection retry interval in milliseconds
- **max-reconnect-interval-ms**: (optional) max connection retry interval time in milliseconds
- **topic-prefix**: (optional) prefix for MQTT topic
- **username**: (optional) username for MQTT connection
- **password**: (optional) password for MQTT connection
- **pin-control-config**: section for configuring GPIO Pins that shall be used
- **gpio-pins**: list of GPIO pins
- **number**: number of GPIO pin, see [Raspberry Pi: GPIO - General Purpose Input Output](https://www.elektronik-kompendium.de/sites/raspberry-pi/2002191.htm)
- **name**: custom name for the pin (used for MQTT topic).
- **direction**: configure GPIO direction. Available Values: Input, Output
- **pull-config**: configure GPIO pull-up/down resistor. Available Values:
- PullDown: pull-down resistor
- PullUp: pull-up resistor
- PullOff: no resistor
- **send-polling-events**: (optional) send pin state via MQTT on every polling event. Available Values:
- true: enable send on polling event
- false (default): disable send on polling event
- **send-change-events**: (optional) send pin state via MQTT on a change event. Available Values:
- true: enable send on change events
- false (default): disable send on change events
- **initial-state**: (optional) set of initial state of output pin at start of application. Available Values:
- ON: initial state set to ON at startup
- OFF: initial state set to OFF at startup
- [not set]: do not set initial state at startup
- **polling-time-ms**: (optional) interval in milliseconds (default: 100), for cyclically polling the current state of all pins.