HARDWARIO Gateway

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.

Install & Upgrade

sudo pip3 install --upgrade --no-cache-dir bcg

Usage examples

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

bcg –help

 1$ bcg --help
 2Usage: bcg [OPTIONS] COMMAND [ARGS]...
 3
 4HARDWARIO gateway between USB serial port and MQTT broker
 5
 6Options:
 7-c, --config FILENAME  configuration file (YAML format).
 8-d, --device TEXT      device
 9-H, --mqtt-host TEXT   MQTT host to connect to (default is 127.0.0.1)
10-P, --mqtt-port TEXT   MQTT port to connect to (default is 1883)
11--no-wait              no wait on connect or reconnect serial port
12--mqtt-username TEXT   MQTT username
13--mqtt-password TEXT   MQTT password
14--mqtt-cafile TEXT     MQTT cafile
15--mqtt-certfile TEXT   MQTT certfile
16--mqtt-keyfile TEXT    MQTT keyfile
17-v, --verbosity LVL    Either CRITICAL, ERROR, WARNING, INFO or DEBUG
18-D, --debug            Print debug messages, same as --verbosity DEBUG.
19--version              Show the version and exit.
20--help                 Show this message and exit.
21
22Commands:
23devices  Print available devices.
24help     Show help.

Udev rules

If you would like permanent alias in /dev/, then apply these rules.

For Radio Dongle

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-hio-usb-dongle.rules

For Gateway with Core Module

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-hio-core-module.rules

Config files

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.

Step 1: Create folder for configuration file

sudo mkdir -p /etc/hardwario

Step 2: Configuration file for Gateway Radio Dongle

Open file

sudo nano /etc/hardwario/bcg-ud.yml

Insert this

1device: /dev/bcUD0
2name: "usb-dongle"
3mqtt:
4    host: localhost
5    port: 1883

Step 3: Run service for Gateway Radio Dongle

pm2 start /usr/bin/python3 --name "bcg-ud" -- /usr/local/bin/bcg -c /etc/hardwario/bcg-ud.yml
pm2 save

Configuration file for Gateway Core module

Open file

sudo nano /etc/hardwario/bcg-cm.yml

Insert this

1device: /dev/bcCM0
2name: "core-module"
3mqtt:
4    host: localhost
5    port: 1883

Run service for Gateway Core module

pm2 start /usr/bin/python3 --name "bcg-cm" -- /usr/local/bin/bcg -c /etc/hardwario/bcg-cm.yml
pm2 save

Bash autocomplete for bcf

register-python-argcomplete bcf >> ~/.bashrc
source ~/.bashrc