Forwarding of serial and USB ports over the network to openHAB

As promised, here comes the tutorial on forwarding serial or USB ports to openHAB. This tutorial is the result of my efforts to use Vlad Kolotov’s Bluetooth binding (kudos to @vkolotov ) for my MiFlora plant sensors.

Problem description
Services such as Zwave or Bluetooth are limited in their transmission range for technical reasons. To improve the range, the corresponding adapters can be connected with extension cables. However, if the cable length is limited or the installation of cables is not possible, this does not lead to the desired success.

In order to solve this problem, there are two solutions, depending on the task, which are briefly presented below. For serial ports the combination of ser2net and socat and for USB ports usbip is a possible solution.

Before we start, here are some definitions. The server on which openHAB runs is always referred to as the client and the server to which the respective adapter is connected is referred to as the server.

I use a first generation Raspberry Pi with DietPi as OS for the server (which comes with the adapter). And openhab runs on a Raspberry Pi 3 with SSD and a manually installed openHabian and Raspbian Stretch (Kudos to @ThomDietrich)

Solution 1: USBIP for non-serial USB ports
In contrast to the ser2net / socat combination, this solution can be used for any USB port. Disadvantage: I got it to run on the server (the one with the adapter), but not on the openHAB site (the client) yet.

The guide is based on the blog entry “Linux, RPi and USB over IP” by Piotr Król and is a little shortened here.

Erste Schritt ist das Aufsetzen des Servers, an dem der USB Adapter angeschlossen ist. Hierzu muss zunächst usbip installiert werden. We omit the check whether the kernel is prepared for it, since this is usually the case in current kernels

sudo apt install usbip

Then the usbip daemon is started and the matching USB adapter is identified and shared.

sudo modprobe usbip-core
sudo modprobe usbip-host
sudo usbipd -D

Now we can display the USB adapters.

user@server:~ $ usbip list -l
 - busid 1-1.1 (0424:ec00)
   Standard Microsystems Corp. : SMSC9512/9514 Fast Ethernet Adapter (0424:ec00)

 - busid 1-1.3 (0a12:0001)
   Cambridge Silicon Radio, Ltd : Bluetooth Dongle (HCI mode) (0a12:0001)

The one we are looking for has the bus id 1-1.-3 and is a bluetooth adapter. With a bind it is bound and shared on the network.

sudo usbip --debug bind -b 1-1.3

And now we come to the client side, the openhab server. Here too, usbip must be installed. After that we can check if our enabled adapter is visible. IP address should be replaced with the IP address of your server.

sudo usbip list -r <IP address>

the result of the list command should be something like this.

Exportable USB devices
======================
 - 10.42.42.205
      1-1.3: Cambridge Silicon Radio, Ltd : Bluetooth Dongle (HCI mode) (0a12:0001)
           : /sys/devices/platform/soc/20980000.usb/usb1/1-1/1-1.3
           : Wireless / Radio Frequency / Bluetooth (e0/01/01)

The Bluetooth adapter is now shared on the network and can be integrated with the following commands. Attention: On a Raspberry I did not succeed in integrating the adapter.

sudo modprobe vhci-hcd
sudo usbip attach -r <IP address> -b 1-1.3

For the removal of the connection refer to the above mentioned blog article “Linux, RPi and USB over IP updated

Solution 2: ser2net and socat for serial USB ports
If you now have a USB adapter that looks like a serial interface, e.g. the Bluetooth adapter from BlueGiga or a Z-Wave adapter like the one from Aeotech, the solution can be the combination of ser2net and socat.

ser2net is installed on the server and shares the serial port on the network and socat is installed on the client and provides the interface there.

The guide is essentially a compilation of various posts and your own research. Therefore kudos to @snoekieboe, @snackboards, 2devnull

As with the usbip solution, we start with the server. My server is a Raspberry 1 with DietPi () and a BlueGiga Bluetooth adapter.

First we check if the adapter works. For this there is a Python script from BlueGiga which queries the adapter.

apt install python-serial
wget https://raw.github.com/jrowberg/bglib/master/Python/Examples/bled112_scanner.py
chmod +x ./bled112_scanner.py
./bled112_scanner.py

If the output somehow looks like this, then the adapter already works.

user@server:~ $ ./bled112_scanner.py -p /dev/ttyACM0
================================================================
BLED112 Scanner for Python v2013-04-07
================================================================
Serial port:    /dev/ttyACM0
Baud rate:      115200
Scan interval:  200 (250.00 ms)
Scan window:    200 (250.00 ms)
Scan type:      Passive
UUID filters:   None
MAC filter(s):  None
RSSI filter:    None
Display fields: - Time
                - RSSI
                - Packet type
                - Sender MAC
                - Address type
                - Bond status
                - Payload data
Friendly mode:  Disabled
----------------------------------------------------------------
Starting scan for BLE advertisements...
1529261718.724 -90 2 11880C3159C7 1 255 1EFF0600010920029D1D359B9D58E977F053975C0B48A5A2756C7CD8B470DB
1529261718.837 -87 2 11880C3159C7 1 255 1EFF0600010920029D1D359B9D58E977F053975C0B48A5A2756C7CD8B470DB
1529261719.129 -90 2 11880C3159C7 1 255 1EFF0600010920029D1D359B9D58E977F053975C0B48A5A2756C7CD8B470DB
1529261719.185 -87 0 DCD93522D048 1 255 0201060302AFFE06094E30305558
1529261719.244 -87 2 11880C3159C7 1 255 1EFF0600010920029D1D359B9D58E977F053975C0B48A5A2756C7CD8B470DB
1529261719.290 -62 0 FB45E00C3C13 1 255 0201060302AFFE06094E30343130
1529261719.554 -87 2 11880C3159C7 1 255 1EFF0600010920029D1D359B9D58E977F053975C0B48A5A2756C7CD8B470DB
1529261719.622 -85 0 C47C8D65B8A1 0 255 020106030295FE141695FE71209800BEA1B8658D7CC40D0910026208

No output or an error message? By default, /dev/ttyACM0 is used as the port. If this is not the correct one, it can be specified on the command line.

./bled112_scanner.py -p /dev/ttyACM0

The desired serial port is then made available on the network using the ser2net tool. To do this, ser2net must first be installed.

sudo apt install ser2net

Then edit the configuration file.

sudo nano /etc/ser2net.conf

and then add the linet as follows.

3001:raw:600:/dev/ttyACM0:115200 8DATABITS NONE 1STOPBIT

All other lines are commented out. This line is then used to make our serial port available on the network on port 3001. If you like you can also try a higher speed than 115200 baud. After saving, restart the service.

service ser2net restart

With netstat you can see if ser2net on port 3001 listens for a connection.

netstat -antp

And now we come to the client side, the openhab server. The client is not set up quite as quickly as the server. First, the socat package must be installed.

sudo apt install socat

Now the configuration follows, so that we can easily integrate several shared ports. The serial port should be accessible under /dev/ttyNET0. First we create the service file

sudo nano /etc/systemd/system/socat@.service

The content should look like this.

[Unit]
Description=Multipurpose relay (SOcket CAT)
After=network.target
StartLimitIntervalSec=0
StartLimitBurst=3000

[Service]
Restart=always
RestartSec=3
EnvironmentFile=/etc/default/socat-%i.conf
Type=simple
PIDFile=/var/run/socat-%i.pid
ExecStart=/usr/bin/socat -L/var/run/socat-%i.pid $SOCAT_DEFAULTS $SOCAT_CONNECTION
ExecStop=/bin/kill -SIGKILL $MAINPID

[Install]
WantedBy=multi-user.target

After saving the configuration is reloaded

systemctl daemon-reload

Now comes the configuration file for the serial device /dev/ttyNET0

sudo nano /etc/default/socat-ttyNET0.conf

The content should look like this.

SOCAT_DEFAULTS=-d -d -s -lf /var/log/socat.log

SOCAT_CONNECTION=pty,link=/dev/ttyNET0,raw,user=openhab,group=dialout,mode=777 tcp:<ip-address>:<port>

You should replace IP address and port with the IP of the server and the corresponding port and enable and start it after saving for system startup.

systemctl enable socat@ttyNET0
systemctl start socat@ttyNET0

The same can now be repeated with wide configurations until all remote interfaces are connected. With the script of BlueGiga you can check on the client whether data arrive on the new interface now.

Now the new serial interface is available on the openHAB server, but two steps are still missing to use it in openHAB. In the first step, the serial port must be built into the openhab service options so that Java can access it.

sudo nano /etc/default/openhab2

Adjust the EXTRA_JAVA_OPTS accordingly

EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB0:/dev/ttyS0:/dev/ttyS2:/dev/ttyACM0:/dev/ttyAMA0:/dev/ttyNET0"

Then you have to log into the Karaf console (see also the openHAB Documentation) and install the serial transport. Simply enter the following.

feature:install openhab-transport-serial
logout

And finally, the openHAb should be restarted. Now there are some tricks with udev rules left, but I haven’t implemented them yet.

Questions, feedback, additions, corrections etc. are always welcome and I hope the tutorial will help.

Thomas

18 Likes

What exactly is the benefit of this solution over the Ser2net/socat solution?
Are there any differences?

You are saying USBIP is for USB devices but that also works just fine with Ser2Net/socat

Thanks

1 Like

The difference is that not all devices could accesses using a serial connection.

Example: The Bluegiga Blutooth Adapter is seriell, so both solutions may work, but a Logilink Bluetooth adapter ist not a serial adapter so the ser2net/socat solution will not work.

Another example ist that with the usbip solution you may link a USB Memory stick over the net or other usb devices like USb Soundcards etc.

If the ser2net/socat solution ist fine for you do not heasitate to use it.

Hope this helps

Corrected above some minor errors while rebuilding my own system :slight_smile:

Which DietPI OS should I install on a PI Zero?

Did you got usbip working on openhabian?

I’m stuck on:

sudo usbip --debug attach -r 10.0.1.1 -b 3-2.4.1
usbip: debug: usbip.c:141:[run_command] running command: `attach'
libusbip: error: udev_device_new_from_subsystem_sysname failed
usbip: error: open vhci_driver
usbip: error: query

UPDATE: I found a solution. Default usbip on openHABian is way too old (2.0+4.9.82-1+deb9u3+rpi1).

When you install the latest version (2.0+4.18.6-1) it works perfect. You can find it here.

2 Likes

Really great!! i was looking for a solution a long time. It works perfect the binding immidiately found the adapter

Thanks

Hi Team

can someone assist? as soon as ser2net is restarted, socat exits and then openhab fails on zwave

As this thread suggests, its not binding related and that a restart is the only way to fix. So what happens when you restart the host that serves the USB? You must also restart Oh2?! surely not


06:44:40.562 [ERROR] [ding.zwave.handler.ZWaveSerialHandler] - Got I/O exception                                                        Input/output error in writeArray during sending. exiting thread.
06:44:42.571 [ERROR] [ding.zwave.handler.ZWaveSerialHandler] - Got I/O exception                                                        Input/output error in writeArray during sending. exiting thread.
06:44:54.572 [ERROR] [ding.zwave.handler.ZWaveSerialHandler] - Got I/O exception                                                        Input/output error in writeArray during sending. exiting thread.
06:44:56.579 [ERROR] [ding.zwave.handler.ZWaveSerialHandler] - Got I/O exception                                                        Input/output error in writeArray during sending. exiting thread.
06:45:08.580 [ERROR] [ding.zwave.handler.ZWaveSerialHandler] - Got I/O exception                                                        Input/output error in writeArray during sending. exiting thread.
06:45:10.490 [INFO ] [smarthome.event.ItemStateChangedEvent] - OpenHAB_Cpu_Load1                                                        changed from 0.1 to 0.3
06:45:10.497 [INFO ] [smarthome.event.ItemStateChangedEvent] - OpenHAB_Cpu_Load5                                                        changed from 0.2 to 0.3
06:45:10.502 [INFO ] [smarthome.event.ItemStateChangedEvent] - OpenHAB_Sensors_C                                                       puTemperature changed from 30.0 to 29.0
06:45:10.507 [INFO ] [smarthome.event.ItemStateChangedEvent] - OpenHAB_Cpu_Load                                                        changed from 2.6 to 2.4
06:45:10.589 [ERROR] [ding.zwave.handler.ZWaveSerialHandler] - Got I/O exception                                                        Input/output error in writeArray during sending. exiting thread.

kris@openhab2:/etc/systemd/system$ systemctl restart socat
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to restart 'socat.service'.
Authenticating as: kris
Password:
==== AUTHENTICATION COMPLETE ===
kris@openhab2:/etc/systemd/system$ tail -f /var/log/socat.log
2018/10/03 06:44:50 socat[20383] I openpty({6}, {7}, {"/dev/pts/1"},,) -> 0
2018/10/03 06:44:50 socat[20383] N PTY is /dev/pts/1
2018/10/03 06:44:50 socat[20383] N opening connection to AF=2 192.168.0.12:3333
2018/10/03 06:44:50 socat[20383] I starting connect loop
2018/10/03 06:44:50 socat[20383] I socket(2, 1, 6) -> 8
2018/10/03 06:44:50 socat[20383] N successfully connected from local address AF=2 192.168.0.3:36958
2018/10/03 06:44:50 socat[20383] I resolved and opened all sock addresses
2018/10/03 06:44:50 socat[20383] N starting data transfer loop with FDs [6,6] and [8,8]
2018/10/03 06:44:51 socat[20383] I transferred 63 bytes from 8 to 6
2018/10/03 06:44:51 socat[20383] I transferred 110 bytes from 6 to 8

The only way to fix it is to restart openhab2

Surely this isnt right.

Maybe the problem is that you do not start ser2net as root try it with

sudo service xxx restart

Thanks Thomas, is there a way I can determine if its been started as root?

typicalls on systemstartup it should be started as root. Have you checked all your config files if the restart option is there?

is the USB IP confirmed working with Aeotec z wave Gen 5 stick?
Would it also work with OH installed as as docker?

I am asking as ser2net and socat does not work with OH as a docker

usbip has several problems. I didn’t work on my raspi 3 with openhabian (Stretch), i tried it in a VM with debian (Buster) and i sometimes work.

Try it. If it is working fine, but then do not change anything.

Thats my experience

I kept getting an error when I typed in this command
“sudo systemctl enable usbipd.service”
Does it have something to do with the usbip being old? how do I install a newer one?

Hi, is there an easy way to forward 2 USB ports at the same time? I have a ZigBee and Zwave adapter and want to forward both to OpenHABian. The only solution I found was to have two insances of socat running which is quite a little awkward i.m.h.o.
Any ideas?

How I automated some usbip restarts after the connection between host and client was broken and re-established.

On the host (Pi 0 in my case):

sudo -s

#Identify your USB device. 0a12:0001 in my case.
lsusb

# Install usbip and setup the kernel module to load at startup
apt-get install usbip
modprobe usbip_host
echo 'usbip_host' >> /etc/modules

# Create a systemd service
nano /lib/systemd/system/usbipd.service

[Unit]
Description=usbip host daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/sbin/usbipd -D
ExecStartPost=/bin/sh -c "/usr/sbin/usbip bind --$(/usr/sbin/usbip list -p -l | grep '#usbid=0a12:0001#' | cut '-d#' -f1)"
ExecStop=/bin/sh -c "/usr/sbin/usbip unbind --$(/usr/sbin/usbip list -p -l | grep '#usbid=0a12:0001#' | cut '-d#' -f1); killall usbipd"

[Install]
WantedBy=multi-user.target

Enable and start it.

On the client (openHAB server):

# Create a separate service file for every shared USB device. Adjust IP. And if you have more then 2 clients: port=00, the Before= and After=.
sudo nano /lib/systemd/system/usbip.service

[Unit]
Description=USBIP Pi 0 Slaapkamer client
After=network.target
Before=usbip1.service
StartLimitIntervalSec=0

[Service]
Restart=always
RestartSec=30
#Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/sh -c "/usr/sbin/usbip attach -r 10.0.2.106 -b $(/usr/sbin/usbip list -r 10.0.2.106 | grep '0a12:0001' | cut -d: -f1)"
#ExecStop=/bin/sh -c "/usr/sbin/usbip detach --port=$(/usr/sbin/usbip port | grep '<Port in Use>' | sed -E 's/^Port ([0-9][0-9]).*/\1/')"
ExecStop=/bin/sh -c "/usr/sbin/usbip detach --port=00"

[Install]
WantedBy=multi-user.target

For reference, my second service file:

[Unit]
Description=USBIP Spin client
After=network.target usbip.service
StartLimitIntervalSec=0

[Service]
Restart=always
RestartSec=30
#Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/sh -c "/usr/sbin/usbip attach -r 10.0.1.1 -b $(/usr/sbin/usbip list -r 10.0.1.1 | grep '0a12:0001' | cut -d: -f1)"
#ExecStop=/bin/sh -c "/usr/sbin/usbip detach --port=$(/usr/sbin/usbip port | grep '<Port in Use>' | sed -E 's/^Port ([0-9][0-9]).*/\1/')"
ExecStop=/bin/sh -c "/usr/sbin/usbip detach --port=01"

[Install]
WantedBy=multi-user.target

Enable and start it.

items:

Switch Restart_BT_Pi0Slaapkamer "BT Pi Zero Slaapkamer opnieuw opstarten"   <network>                         { channel="exec:command:7b7959d5:run" }
Switch Restart_BT_Spin "BT Spin opnieuw opstarten"                          <network>                         { channel="exec:command:9c9a59d6:run" }
Switch Pi0slaapkamer "Pi Zero Slaapkamer"                                   <network> (gslaapkamer, gPis)     { channel="network:pingdevice:ca0875b9:online" }

rules:

var Timer SpinBTtimer = null
var Timer Pi0BTtimer = null

rule "Reboot local Spin BT service"
when
    Item Spin changed to ON
then
    logInfo("Spin BT restart Function", "1. Spin = " + Spin.state.toString)
    logInfo("Spin BT restart Function", "1. Restart_BT_Spin = " + Restart_BT_Spin.state.toString)
    if (SpinBTtimer === null) {
        SpinBTtimer = createTimer(now.plusSeconds(20), [ |
            logInfo("Spin BT restart Function", "2. Spin = " + Spin.state.toString)
            logInfo("Spin BT restart Function", "2. Restart_BT_Spin = " + Restart_BT_Spin.state.toString)
            Restart_BT_Spin.sendCommand(ON)
            logInfo("Spin BT restart Function", "3. Spin = " + Spin.state.toString)
            logInfo("Spin BT restart Function", "3. Restart_BT_Spin = " + Restart_BT_Spin.state.toString)
            SpinBTtimer = null // cancel the timer
        ])
    }
end

rule "Reboot local Pi 0 BT service"
when
    Item Pi0slaapkamer changed to ON
then
    logInfo("Pi 0 sk BT restart Function", "1. Pi 0 sk = " + Pi0slaapkamer.state.toString)
    logInfo("Pi 0 sk BT restart Function", "1. Restart_BT_Pi 0 sk = " + Restart_BT_Pi0Slaapkamer.state.toString)
    if (Pi0BTtimer === null) {
        Pi0BTtimer = createTimer(now.plusSeconds(20), [ |
            logInfo("Pi 0 sk BT restart Function", "2. Pi 0 sk = " + Pi0slaapkamer.state.toString)
            logInfo("Pi 0 sk BT restart Function", "2. Restart_BT_Pi 0 sk = " + Restart_BT_Pi0Slaapkamer.state.toString)
            Restart_BT_Pi0Slaapkamer.sendCommand(ON)
            logInfo("Pi 0 sk BT restart Function", "3. Pi 0 sk = " + Pi0slaapkamer.state.toString)
            logInfo("Pi 0 sk BT restart Function", "3. Restart_BT_Pi 0 sk = " + Restart_BT_Pi0Slaapkamer.state.toString)
            Pi0BTtimer = null // cancel the timer
        ])
    }
end

Furthermore you need the exec binding installed. Create a thing for every USB device with the command:

sudo /bin/systemctl restart usbip.service

I did this in paperUI, but you can also do it in .things file. Make sure your openHAB user has permission to execute sudo. See this topic.

Maybe a little complex, but it works. Only issue with this approach is that when the host stays online, but for some reason the USB device gets disconnected and reconnected, it will not be detected, thus rebooted. But this rarely happens in my use case (wifi signal lost, or host turned off/on).

Feedback is welcome! Especially if I can simplify this process!

2 Likes

Fixed:

rule "Monitor Pi 0 tuin BT adapter status"
when
    Thing "bluetooth:adapter:001A7DDA7115" changed or
    Time cron "0 0/5 * 1/1 * ? *"
then
    var statusBTAPi0tuin = getThingStatusInfo("bluetooth:adapter:001A7DDA7115").getStatus()
    logInfo("Pi 0 tuin BT adapter status", "1. Pi 0 tuin BT Adapter = " + statusBTAPi0tuin)
    logInfo("Pi 0 tuin BT adapter status", "1. Pi 0 tuin = " + Pi0tuin.state.toString)
    logInfo("Pi 0 tuin BT adapter status", "1. Restart_BT_Pi0Tuin = " + Restart_BT_Pi0Tuin.state.toString)
    if (statusBTAPi0tuin.toString() != 'ONLINE' && Pi0BTadaptertuintimer === null) {
        Pi0BTadaptertuintimer = createTimer(now.plusSeconds(20), [ |
            var statusBTAPi0tuin1 = getThingStatusInfo("bluetooth:adapter:001A7DDA7115").getStatus()
            logInfo("Pi 0 tuin BT adapter status", "1. Pi 0 tuin BT Adapter = " + statusBTAPi0tuin1)
            logInfo("Pi 0 tuin BT adapter status", "2. Pi 0 tuin = " + Pi0tuin.state.toString)
            logInfo("Pi 0 tuin BT adapter status", "2. Restart_BT_Pi0Tuin = " + Restart_BT_Pi0Tuin.state.toString)
            Restart_BT_Pi0Tuin.sendCommand(ON)
            logInfo("Pi 0 tuin BT adapter status", "3. Pi 0 tuin = " + Pi0tuin.state.toString)
            logInfo("Pi 0 tuin BT adapter status", "3. Restart_BT_Pi0Tuin = " + Restart_BT_Pi0Tuin.state.toString)
            Pi0BTadaptertuintimer = null // cancel the timer
        ])
    }
end
1 Like

I’ve got this setup running on Kubernetes. I used an init.d script for socat, but I used the systemd version posted here to improve my system :slight_smile:

As an improvement, I suggest running monit as a monitoring solution for the ser2net server.

As i have multiple serial devices, which i need to monitor seperately, i’ve created a systemd template:

root@domotica-06:~# cat /lib/systemd/system/ser2net@.service
[Unit]
Description=ser2net for %i
Wants=network-online.target
After=network-online.target
AssertPathExists=/etc/ser2net/ser2net-%i.conf

[Service]
ExecStart=/usr/local/sbin/ser2net -n -c /etc/ser2net/ser2net-%i.conf -P /var/run/ser2net-%i.pid
PIDFile=/var/run/ser2net-%i.pid

[Install]
WantedBy=multi-user.target

Then i’ve created several config files:

root@domotica-06:~# ls /etc/ser2net -la
total 28
drwxr-xr-x  3 root root 4096 Aug 13 12:43 .
drwxr-xr-x 84 root root 4096 Aug 13 13:25 ..
-rw-r--r--  1 root root   72 Aug 13 12:41 ser2net-conbee2.conf
-rw-r--r--  1 root root   85 Jul  8 12:39 ser2net-p1.conf
-rw-r--r--  1 root root   89 Aug 13 12:41 ser2net-rfxcom.conf
-rw-r--r--  1 root root   92 Aug 13 12:43 ser2net-zwave.conf

A config file looks like:

root@domotica-06:~# cat /etc/ser2net/ser2net-p1.conf
ipv4,tcp,4002:raw:0:/dev/ttyUSB-P1:115200 NONE 1STOPBIT 8DATABITS max-connections=10

Then i installed Monit:

root@domotica-06:~# apt install monit
Reading package lists… Done
Building dependency tree
Reading state information… Done
monit is already the newest version (1:5.20.0-6).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Configured a config file for each connection:

root@domotica-06:~# ls /etc/monit/conf-enabled -la
total 8
drwxr-xr-x 2 root root 4096 Aug 13 13:31 .
drwxr-xr-x 7 root root 4096 Jul  9 14:52 ..
lrwxrwxrwx 1 root root   34 Jul  9 14:45 cpu-temp -> /etc/monit/conf-available/cpu-temp
lrwxrwxrwx 1 root root   41 Jul  9 13:37 ser2net-conbee2 -> /etc/monit/conf-available/ser2net-conbee2
lrwxrwxrwx 1 root root   36 Jul  9 13:37 ser2net-p1 -> /etc/monit/conf-available/ser2net-p1
lrwxrwxrwx 1 root root   40 Aug 13 13:21 ser2net-rfxcom -> /etc/monit/conf-available/ser2net-rfxcom
lrwxrwxrwx 1 root root   39 Aug 13 13:21 ser2net-zwave -> /etc/monit/conf-available/ser2net-zwave

Contents of one config file (they all look the same, i need more monitoring on the connection side, but for now it’s ok):

root@domotica-06:~# cat /etc/monit/conf-enabled/ser2net-p1
check process ser2net[4002]-p1 with pidfile /var/run/ser2net-p1.pid
    start program = "/bin/systemctl start ser2net@p1" with timeout 30 seconds
    stop program  = "/bin/systemctl stop ser2net@p1"
#    if cpu usage > 80% for 5 cycles then alert
#    if failed port 80 protocol http then restart
    if 5 restarts within 10 cycles then timeout

Then configured Monit to not use authentication, and not limiting to a specific subnet (totally insecure ;-)):

Snippet from /etc/monit/monitrc:

 set httpd port 80 #and
     use address 0.0.0.0  # only accept connection from localhost
     allow 0.0.0.0/0.0.0.0        # allow localhost to connect to the server and
#     allow admin:monit      # require user 'admin' with password 'monit'

If the ser2net connection stops, it’s automatically restarted by Monit. You can also view a web page, which looks like:

1 Like

RUDY wraps USB/IP in a Docker container, maybe interesting here.