Share CC2652RB (slae.sh) stick to zigbee2mqtt via ser2net

This is quick how-to share CC2652RB over network to zigbee2mqtt (Home Assistant) via ser2net. This tutorial is for RaspberryPi.

In this tutorial ser2net will be named as ser2net2. To not have collision in case you will install older version from repository via apt install ser2net. Also it will listen on port 3452 in configuration below.

Clone ser2net and gensio. We will use master branch because contains some changes which were not in past versions (compatibility issue with bootloader of CC2652RB DTR/RTS…)

cd /opt
git clone [email protected]:cminyard/ser2net.git
git clone [email protected]:cminyard/gensio.git
cd gensio
apt-install python3-dev libtool automake
./reconf
./configure
./make
./make install
cd ../ser2net
apt install libyaml-dev
./reconf
./configure
./make
./make install

Create sh control service:

vim /opt/ser2net_service.sh

#! /bin/bash
#
# ser2net       init script for ser2net
#
#               Written by Miquel van Smoorenburg <[email protected]>.
#               Modified for Debian GNU/Linux
#               by Ian Murdock <[email protected]>.
#               Modified for ser2net by Marc Haber <[email protected]>

### BEGIN INIT INFO
# Provides:          ser2net
# Required-Start:    $network $remote_fs
# Required-Stop:     $network $remote_fs
# Should-Start:
# Should-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Allows network connections to serial ports
# Description:       This daemon allows telnet and tcp sessions to be established with a unit's serial ports.
### END INIT INFO

set -e

if [ -r "/lib/lsb/init-functions" ]; then
  . /lib/lsb/init-functions
else
  echo "E: /lib/lsb/init-functions not found, lsb-base (>= 3.0-6) needed"
  exit 1
fi

if [ -n "$SER2NETDEBUG" ]; then
  echo "now debugging $0 $@"
  set -x
fi

LANG=C
export LANG

PATH=/usr/local/sbin
DAEMON=/usr/local/sbin/ser2net
NAME=ser2net2
DESC="Serial port to network proxy"
PIDFILE=/run/$NAME.pid

test -f $DAEMON || exit 0


# Defaults
CONFFILE="/etc/ser2net/ser2net.yaml"
OPTIONS=""
CONTROLPORT=""

# Read config file (will override defaults above)
#[ -r /etc/default/ser2net ] && . /etc/default/ser2net

# this is from madduck on IRC, 2006-07-06
# There should be a better possibility to give daemon error messages
# and/or to log things
log()
{
  case "$1" in
    [[:digit:]]*) success=$1; shift;;
    *) :;;
  esac
  log_action_begin_msg "$1"; shift
  log_action_end_msg ${success:-0} "$*"
}

start () {
  if ! pidofproc -p "$PIDFILE" "$DAEMON" >/dev/null; then
      start_daemon -p $PIDFILE $DAEMON ${CONTROLPORT:+-p} $CONTROLPORT -c $CONFFILE -P $PIDFILE $OPTIONS
      ret=$?
  else
    log_failure_msg "already running!"
    log_end_msg 1
    exit 1
  fi
  return $ret
}

stop () {
  # this is a workaround for #451529 as ser2net 2.5 does not delete its pidfile
  SIG="${1:--TERM}"
  killproc -p "$PIDFILE" "$DAEMON" "$SIG"
  # this is a workaround for killproc -TERM not zapping the pidfile
  if ! pidofproc -p "$PIDFILE" "$DAEMON" >/dev/null; then
    rm -f $PIDFILE
  fi
}

status()
{
  log_action_begin_msg "checking $DESC"
  if pidofproc -p "$PIDFILE" "$DAEMON" >/dev/null; then
    log_action_end_msg 0 "$NAME running"
  else
    if [ -e "$PIDFILE" ]; then
      log_action_end_msg 1 "$NAME failed"
      exit 1
    else
      log_action_end_msg 0 "$NAME not running"
      exit 3
    fi
  fi
}

if ! [ -e "$CONFFILE" ]; then
  log_failure_msg "Not starting ser2net: Conffile $CONFFILE missing"
  log_end_msg 1
  exit 1
fi

case "$1" in
  start)
        log_daemon_msg "Starting $DESC" "$NAME"
        start
        log_end_msg 0
        ;;
  stop)
        log_daemon_msg "Stopping $DESC" "$NAME"
if ! [ -e "$CONFFILE" ]; then
  log_failure_msg "Not starting ser2net: Conffile $CONFFILE missing"
  log_end_msg 1
  exit 1
fi

case "$1" in
  start)
        log_daemon_msg "Starting $DESC" "$NAME"
        start
        log_end_msg 0
        ;;
  stop)
        log_daemon_msg "Stopping $DESC" "$NAME"
        stop
        log_end_msg 0
        ;;
  reload|force-reload)
        log_daemon_msg "Reloading $DESC" "$NAME"
        stop "-HUP"
        log_end_msg 0
        ;;
  restart)
        log_daemon_msg "Restarting $DESC" "$NAME"
        stop
        sleep 1
        start
        log_end_msg 0
        ;;
  status)
        status
        ;;
  *)
        N=/etc/init.d/$NAME
        echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
        exit 1
        ;;
esac

exit 0

Create ser2net config file: vim /etc/ser2net/ser2net.yaml (replace XX_XX_XX_XX_XX_XX values with your serial number by listing ls -lah /dev/serial/by-id/)

%YAML 1.1
---
define: &confver 1.0

connection: &con01
accepter: tcp,3452
connector: serialdev,
/dev/serial/by-id/usb-Silicon_Labs_slae.sh_cc2652rb_stick_-_slaesh_s_iot_stuff_XX_XX_XX_XX_XX_XX-if00-port0,115200n81,
local,
dtr=off,
rts=off
options:
    kickolduser: true

Startup ser2net

ln -s /opt/ser2net2_service.sh /etc/init.d/ser2net2
update-rc.d ser2net2 defaults
systemctl enable ser2net2
systemctl start ser2net2

Verify ser2net is running and listening on desired port:

netstat -tupln | grep ser2net
tcp6       0      0 :::3452                 :::*                    LISTEN      583/ser2net

Configure zigbee2mqtt to use configured serial via ser2net (replace according your IP):

…
serial:
  port: tcp://192.168.1.XX:3452
  disable_led: false
…
socat:
  enabled: false
  master: pty,raw,echo=0,link=/dev/ttyZ2M,mode=777
  slave: tcp-listen:8485,keepalive,nodelay,reuseaddr,keepidle=1,keepintvl=1,keepcnt=5
  options: '-d -d'
  log: false
  restartdelay: 1
  initialdelay: 1

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.