This multi-platform Python tool connects USB gateway to the MQTT. USB gateway is communicating over virtual USB serial port with JSONs.
Gateway can be run in command line or by pm2
service manager.
sudo pip3 install --upgrade --no-cache-dir bcg
Usually the bcg
is run with pm2
process manager. This direct command line command is more for testing purporses if the service does not run correctly.
Start
bcg --device /dev/ttyUSB0
Start with debug
bcg --device /dev/ttyUSB0 --debug
hub@hpnix:~$ bcg --help
usage: bcg [-h] [-c CONFIG] [-d DEVICE] [-H MQTT_HOST] [-P MQTT_PORT]
[--no-wait] [--mqtt-username MQTT_USERNAME]
[--mqtt-password MQTT_PASSWORD] [--mqtt-cafile MQTT_CAFILE]
[--mqtt-certfile MQTT_CERTFILE] [--mqtt-keyfile MQTT_KEYFILE] [-D]
[-v]
COMMAND ...
BigClown gateway between USB serial port and MQTT broker
positional arguments:
COMMAND
devices show devices
help show help
optional arguments:
-h, --help show this help message and exit
-c CONFIG, --config CONFIG
path to configuration file (YAML format)
-d DEVICE, --device DEVICE
device
-H MQTT_HOST, --mqtt-host MQTT_HOST
MQTT host to connect to (default is localhost)
-P MQTT_PORT, --mqtt-port MQTT_PORT
MQTT port to connect to (default is 1883)
--no-wait no wait on connect or reconnect serial port
--mqtt-username MQTT_USERNAME
MQTT username
--mqtt-password MQTT_PASSWORD
MQTT password
--mqtt-cafile MQTT_CAFILE
MQTT cafile
--mqtt-certfile MQTT_CERTFILE
MQTT certfile
--mqtt-keyfile MQTT_KEYFILE
MQTT keyfile
-D, --debug print debug messages
-v, --version show program's version number and exit
If you would like permanent alias in /dev/
, then apply these rules.
echo 'SUBSYSTEMS=="usb", ACTION=="add", KERNEL=="ttyUSB*", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6015", ATTRS{serial}=="bc-usb-dongle*", SYMLINK+="bcUD%n", TAG+="systemd", ENV{SYSTEMD_ALIAS}="/dev/bcUD%n"' | sudo tee --append /etc/udev/rules.d/58-bigclown-usb-dongle.rules
echo 'SUBSYSTEMS=="usb", ACTION=="add", KERNEL=="ttyACM*", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", SYMLINK+="bcCM%n", TAG+="systemd", ENV{SYSTEMD_ALIAS}="/dev/bcCM%n"' | sudo tee --append /etc/udev/rules.d/59-bigclown-core-module.rules
In case you would like have configuration of bcg
separate and not permanent in the pm2
, create a config file and pass the file with -c
parameter to bcg
.
sudo mkdir -p /etc/bigclown
sudo nano /etc/bigclown/bcg-ud.yml
device: /dev/bcUD0
name: "usb-dongle"
mqtt:
host: localhost
port: 1883
pm2 start /usr/bin/python3 --name "bcg-ud" -- /usr/local/bin/bcg -c /etc/bigclown/bcg-ud.yml
pm2 save
sudo nano /etc/bigclown/bcg-cm.yml
device: /dev/bcCM0
name: "core-module"
mqtt:
host: localhost
port: 1883
pm2 start /usr/bin/python3 --name "bcg-cm" -- /usr/local/bin/bcg -c /etc/bigclown/bcg-cm.yml
pm2 save
register-python-argcomplete bcf >> ~/.bashrc
source ~/.bashrc