Ser2net: is there a simple go/nogo test for configured serial proxies?

I have now installed ser2net on a Sercomm NA502 under Openwrt 22.03.6 and would now like to perform a simple go/nogo test of the exposed serial ports.

Any ideas or suggestions?

OPENWRT (22.03.6):

root@OpenWrt:~# ubus call system board
{
	"kernel": "5.10.201",
	"hostname": "OpenWrt",
	"system": "MediaTek MT7621 ver:1 eco:3",
	"model": "SERCOMM NA502",
	"board_name": "sercomm,na502",
	"rootfs_type": "squashfs",
	"release": {
		"distribution": "OpenWrt",
		"version": "22.03.6",
		"revision": "r20265-f85a79bcb4",
		"target": "ramips/mt7621",
		"description": "OpenWrt 22.03.6 r20265-f85a79bcb4"
	}
}

SER2NET configuration (ser2net version 3.5.1)

root@OpenWrt:~# cat /etc/config/ser2net
config ser2net global
	option enabled 1

config controlport
	option enabled 1
	option host localhost
	option port 2000

config default
	option speed 115200
	option databits 8
	option parity 'none'
	option stopbits 1
	option rtscts false
	option local false
	option remctl true

#config led rx
#	option driver sysfs
#	option device 'duckbill:green:rs485'
#	option duration 20
#	option state 1

#config led tx
#	option driver sysfs
#	option device 'duckbill:red:rs485'
#	option duration 20
#	option state 1

config proxy
	option enabled 1
	option port 5000
	option protocol raw
	option timeout 0
	option device '/dev/ttyS1'
	option baudrate 115200
	option databits 8
	option parity 'none'
	option stopbits 1
#	option led_tx 'tx'
#	option led_rx 'rx'
	option rtscts false
	option local false
	option xonxoff false
	list options ''

config proxy
	option enabled 1
	option port 5001
	option protocol raw
	option timeout 0
	option device '/dev/ttyS2'
	option baudrate 57600
	option databits 8
	option parity 'none'
	option stopbits 1

config proxy
	option enabled 0
	option port 5002
	option protocol raw
	option timeout 0
	option device '/dev/ttyUSB1'
	option baudrate 9600
	option databits 8
	option parity 'none'
	option stopbits 1
root@OpenWrt:~# 

tried netcat ?

1 Like

Not yet, but I will read up on it.

Do you run Home Assistant somewhere? You can easily add the ZigBee / Z-Wave integrations, both support TCP directly. This is how I tested the serial ports a few years ago.

This is not what you asked for, but these are my two cents: do not refer to devices as "/dev/ttyS1" or "/dev/ttyUSB1", because the actual name of each device may depend on the order when they are detected. Use a "hotplug.d" script to give them a proper link, using the USB identifier.

1 Like

I'll probably find an old RasPi :wink:

Thanks for the hint. However, for the Sercomm NA502 hardware, the paths should be permanent according to https://openwrt.org/toh/sercomm/na502#tftp_installation_instructions.

@andyboeh Even though I had hoped that it would still be as simple today as it used to be and as you described, I had to realize that the "Serial over IP" variant - at least for Z-Wave - is obviously no longer supported by Home Assistant.

see also https://github.com/home-assistant/core/issues/46417

It is still supported, but you need a Z-Wave JS server for it providing the driver. The integration connects to this driver, it cannot directly connect to a Z-Wave dongle, not even a USB one. The server is either available as an add-on (Zwave-js) or as a docker container. See the HA documentation at https://www.home-assistant.io/integrations/zwave_js/

That wasn't obvious when I only mentioned the integrations, sorry.

@andyboeh I have installed the server as an add-on (Zwave-js). As expected, no existing device is displayed in the UI of the configuration.

However, when trying to change the entry for "Device" in the YAML file in accordance with the ser2net interface, an error message appears.

 Device 'tcp://192.168.40.117:5000' does not exist in Z-Wave JS (core_zwave_js)

If you install the integration first, the add-on (Zwave-js) is installed automatically if it is not found. But even with this "flow" there is no chance to enter the network path of the interface provided by ser2net.

Hopefully I haven't taken a wrong turn somewhere, or have I? :wink:

I use the Z-Wave JS UI (formerly Z-Wave JS 2 MQTT) and it's working perfectly fine. Looks like you're right and that the Z-Wave JS add-on doesn't support it. However, you can easily replace it by the Z-Wave JS UI add-on yourself.

It looks like this for me:

@andyboeh Many thanks for the tip. In the end, the replacement was successful, albeit still with an error message.

Driver: Failed to open the serial port: connect ECONNREFUSED 192.168.40.117:5000 (ZW0100)

This is how the configuration looks for me:

What do you think, is the problem with the ser2net on the NA502 gateway or on the part of the Z-Wave JS UI configuration?

ser2net, it can't event connect. What happens if you telnet to this IP/port? If you also get a connection refused error, something is wrong with ser2net, i.e. it's not running at all.

1 Like

unfortunately does not look good ...

I hope that the manual start with "ser2net" via "ssh" and then the control with "ps" is enough, or not?

Which then leads me to the question of the easiest way to include ser2net in the autostart ... if it works in principle ... :wink:

root@OpenWrt:~# ps
  PID USER       VSZ STAT COMMAND
    1 root      1692 S    /sbin/procd
...
 2981 root      1316 S    -ash
 2991 root      1088 S    ser2net             <===
 3016 root         0 RW   [kworker/u4:0-ev]
 3018 root      1320 R    ps

Telnet

[Befehl nicht gefunden: 192.168.40.117:5000]
[Konnte keinen neuen Prozess erstellen und ein Pseudo-TTY öffnen.]

netcat

nc -v -n 192.168.40.117 5000-5001
nc: connectx to 192.168.40.117 port 5000 (tcp) failed: Connection refused
nc: connectx to 192.168.40.117 port 5001 (tcp) failed: Connection refused

Use netstat -lpn on the router running ser2net to see if ser2net has opened the port. Also I think ser2net only allows one active connection per port, an attempted second connection will be refused.
Try nc and/or telnet on the same router that is running ser2net. If the remote machine is not on the same LAN you will need to be sure that the firewall(s) are opened to route between the networks.

You need to start ser2net via the init script, otherwise, the configuration is not applied!

So for a manual start:

/etc/init.d/ser2net start

But it should be started automatically on boot.

here's the result ... (filter: ser2net entries only)

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:2000          0.0.0.0:*               LISTEN      3214/ser2net
tcp        0      0 :::5000                 :::*                    LISTEN      3214/ser2net
tcp        0      0 :::5001                 :::*                    LISTEN      3214/ser2net
tcp        0      0 ::1:2000                :::*                    LISTEN      3214/ser2net

For whatever reason, a Telnet session to port 2000 still fails.

looks much better now ... :pray:

cipo@Cipo-MacBookPro ~ % nc -v -n 192.168.40.117 5000-5001
Connection to 192.168.40.117 port 5000 [tcp/*] succeeded!
Port already in use
Connection to 192.168.40.117 port 5001 [tcp/*] succeeded!

This is still the open question ... :thinking:

Should I delete and re-install ser2net?

Or should I just copy this script?

https://github.com/NicolasBernaerts/openwrt-scripts/blob/master/init.d/ser2net

#!/bin/sh /etc/rc.common
# Ser2Net startup script
# Copyright (C) 2016 Nicolas Bernaerts

# start and stop order
START=95
STOP=50
USE_PROCD=1

start_service() {
  echo "start ser2net service"

  # commands to launch service
  ser2net -c /etc/ser2net.conf
}

stop_service() {
  echo "stop ser2net service"

  # read device from /etc/ser2net.conf
  DEVICE=$(cat /etc/ser2net.conf | grep ttyUSB | cut -d':' -f4 | cut -d'/' -f3)

  # remove device lock file
  echo " - remove lock for $DEVICE"
  rm "/var/lock/LCK..$DEVICE"

  # get ser2net process ID
  PID=$(ps | grep -v "grep" | grep "ser2net" | xargs | cut -d' ' -f1)

  # kill ser2net process
  echo " - kill process $PID"
  kill $PID
}

An init script is supplied with the ser2net package.
Have you run /etc/init.d/ser2net enable
Though I think services are enabled upon installation, running enable once should enable automatic startup on boot.

2 Likes