This is simple bridge between MySensors serial gateway and the MQTT bus.
To use it, connect the serial gateway to the host and then run:
./serial2mqtt.py --device /dev/ttyDevice
where /dev/ttyDevice
is the path to the serial device (e.g. /dev/ttyUSB0
for Arduino Uno serial gateway).
-
Clone this repository to preferred location, for example
/opt
directorycd /opt git clone https://github.com/mikozak/MySensorsSerial2MQTT.git
-
Create python virtual environment for running service (this is optional step, however I recommend it)
cd MySensorsSerial2MQTT/ python3 -m venv .
-
Install dependencies
bin/python3 -m pip install -r requirements.txt
-
Check whether everything works as expected (choose valid serial device, for example
/dev/ttyUSB0
)bin/python3 serial2mqtt.py --device /dev/ttyUSB0 --log-debug
-
Create system user which will be used to run as service process (for the purpose of this instruction user named mysensors will be used)
If you are installing on Raspberry Pi you probably want to add newly created user to dialout group in order to allow access to
/dev/tty*
devices.sudo useradd -r mysensors -Gdialout
-
Edit
[email protected]
and make sure path inWorkingDirectory
andExecStart
are valid (and absolute!) You can add additional command line options. The list of all options is as follows:--broker-host
MQTT server host (default:localhost
) [optional]--broker-port
MQTT server port (default:1883
) [optional]--mqtt-publish-topic
MQTT topic used when publishing messages from serial device (default:mysensors-out
) [optional]--mqtt-subscribe-topic
MQTT topic to subscribe for message that should be written to serial device (default:mysensors-in
) [optional]--baudrate
serial device baudrate (default:38400
) [optional]--log-debug
enable debug logging (disabled by default) [optional]--log-info
enable info logging (disabled by default) [optional]--username
MQTT user [optional]--password
MQTT password [optional]--device
path to serial device [required]
-
Install service
sudo cp [email protected] /etc/systemd/system/
-
Run service for
ttyUSB0
device (remember to replace it to you device)sudo systemctl start myserial2mqtt@ttyUSB0
If you want to start the service automatically after system starts just enable it
sudo systemctl enable myserial2mqtt@ttyUSB0