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
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$ bcg --help
Usage: bcg [OPTIONS] COMMAND [ARGS]...

HARDWARIO gateway between USB serial port and MQTT broker

Options:
-c, --config FILENAME  configuration file (YAML format).
-d, --device TEXT      device
-H, --mqtt-host TEXT   MQTT host to connect to (default is 127.0.0.1)
-P, --mqtt-port TEXT   MQTT port to connect to (default is 1883)
--no-wait              no wait on connect or reconnect serial port
--mqtt-username TEXT   MQTT username
--mqtt-password TEXT   MQTT password
--mqtt-cafile TEXT     MQTT cafile
--mqtt-certfile TEXT   MQTT certfile
--mqtt-keyfile TEXT    MQTT keyfile
-v, --verbosity LVL    Either CRITICAL, ERROR, WARNING, INFO or DEBUG
-D, --debug            Print debug messages, same as --verbosity DEBUG.
--version              Show the version and exit.
--help                 Show this message and exit.

Commands:
devices  Print available devices.
help     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

1
2
3
4
5
device: /dev/bcUD0
name: "usb-dongle"
mqtt:
    host: localhost
    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

1
2
3
4
5
device: /dev/bcCM0
name: "core-module"
mqtt:
    host: localhost
    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