From 6ab603e419f46a366ac3d0df0c5342dfce12dc44 Mon Sep 17 00:00:00 2001 From: crietzschel <> Date: Sat, 6 Feb 2021 21:10:34 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Using=20.env=20for=20more=20config=20option?= =?UTF-8?q?s=20like=20ports=20and=20devices;=20also=20changed=20zigbee2mqt?= =?UTF-8?q?t=20usb=20detection=20including=20support=20for=20slaesh?= =?UTF-8?q?=E2=80=99s=20CC2652RB=20stick?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- docker-compose.yml | 12 ++--- start.sh | 117 ++++++++++++++++++++++++++++++++++++--------- 3 files changed, 103 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index 07f43b8..9e61a70 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -data/* \ No newline at end of file +data/* +.env diff --git a/docker-compose.yml b/docker-compose.yml index eb6de4b..f263642 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: '3.6' services: nodered: - image: ghcr.io/ct-open-source/ctnodered:latest + image: ghcr.io/ct-open-source/ctnodered:${CONTAINER_TAG:-latest} volumes: - ./data/nodered:/data - /etc/localtime:/etc/localtime @@ -16,8 +16,9 @@ services: mqtt: image: "eclipse-mosquitto" ports: - - "1883:1883" - - "9001:9001" + - "${MQTT_PORT:-1883}:1883" + - "${MQTT_WEBSOCKET_PORT:-9001}:9001" + - "${MQTT_SECURE_PORT:-8883}:8883" volumes: - ./data/mqtt:/mosquitto - /etc/localtime:/etc/localtime @@ -32,11 +33,10 @@ services: - /run/udev:/run/udev:ro - /etc/localtime:/etc/localtime devices: - - "/dev/ttyACM0:/dev/ttyACM0" - - "/dev/ttyACM1:/dev/ttyACM1" + - "${ZIGBEE_DEVICE:-/dev/ttyACM0}:${ZIGBEE_DEVICE:-/dev/ttyACM0}" restart: always privileged: true ports: - - 1881:1881 + - "${ZIGBEE_FRONTEND_PORT:-1881}:1881" environment: - TZ=Europe/Berlin diff --git a/start.sh b/start.sh index 9ca4adf..59f71c2 100755 --- a/start.sh +++ b/start.sh @@ -1,24 +1,33 @@ #!/bin/bash function detect_zigbee_device { - if usb_dev=$(lsusb -d 0451:); then - usb_dev_count=$(ls -1 /dev/ttyACM* 2>/dev/null | wc -l) - if [ "$usb_dev_count" -gt 1 ]; then - >&2 echo "There are multiple devices connected, that could be Zigbee USB adaptors. Please check data/zigbee/configuration.yml, if the device is wrong. /dev/ttyACM0 is used as the default." - - echo "/dev/ttyACM0" + usb_dev_count=0 + usb_dev_found="FALSE" + for device in /dev/ttyUSB* /dev/ttyACM* + do + if [ ! -c $device ]; then + continue fi - - if [ -c /dev/ttyACM0 ]; then - echo "/dev/ttyACM0" - else - >&2 echo "I could not find /dev/ttyACM0. Please check your hardware." + + VENDOR_PRODUCT=$(udevadm info --name=$device | egrep -i "ID_VENDOR_ID|ID_MODEL_ID" | cut -d'=' -f2 | tr '\n' ':') + # Texas Instruments USB device - Vendor: 0451 + # slaeshโ€™s CC2652RB stick - Vendor: 10c4 + if [ "$(echo ${VENDOR_PRODUCT} | egrep '^0451:|^10c4:')" != "" ] + then + ((usb_dev_count=usb_dev_count+1)) + usb_dev_found="$device" + >&2 echo "๐Ÿ“„ Found Device #$usb_dev_count $device (vendor:product=${VENDOR_PRODUCT}) that could be Zigbee USB adaptor" fi - else - >&2 echo No Texas Instruments USB device found. + done - echo "False" + if [ "$usb_dev_count" -gt 1 ]; then + >&2 echo "โš ๏ธ There are multiple devices connected, that could be Zigbee USB adaptors. Please check data/zigbee/configuration.yml, if the device is wrong. $usb_dev_found is used as the default." fi + + if [ "$usb_dev_count" -eq 0 ]; then + >&2 echo "โš ๏ธ No Texas Instruments USB device nor slaeshโ€™s CC2652RB stick found for zigbee2mqtt" + fi + echo "$usb_dev_found" } function create_mosquitto_config { @@ -41,6 +50,9 @@ touch data/mqtt/config/passwd } function create_zigbee2mqtt_config { + # zigbee2mqtt device + device="$1" + cat > data/zigbee/configuration.yaml < .env <> .env <> .env <&2 exit 1 fi + + if ! [ -x "$(command -v udevadm)" ]; then + echo 'โš ๏ธ Error: udevadm is not installed.' >&2 + exit 1 + fi + + } function start { @@ -120,10 +193,9 @@ function start { container="nodered mqtt" fi - if [ ! -d data ]; then - build_data_structure - fi - + # Build data structure with default file if not existing + build_data_structure "$device" + echo '๐Ÿƒ Starting the containers' docker-compose up -d $container echo 'โš ๏ธ After you made yourself familiar with the setup, it'"'"'s strongly suggested to secure the services. Read the "Security" section in the README!' @@ -188,7 +260,8 @@ case "$1" in fix_permissions ;; "data") - build_data_structure + device=$(detect_zigbee_device) + build_data_structure "$device" ;; * ) cat << EOF From cc02da5d26df2fe2e07a19263047c0cec0fc7c51 Mon Sep 17 00:00:00 2001 From: crietzschel <> Date: Sat, 6 Feb 2021 21:14:57 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Using=20.env=20for=20more=20config=20option?= =?UTF-8?q?s=20like=20ports=20and=20devices;=20also=20changed=20zigbee2mqt?= =?UTF-8?q?t=20usb=20detection=20including=20support=20for=20slaesh?= =?UTF-8?q?=E2=80=99s=20CC2652RB=20stick?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- start.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/start.sh b/start.sh index 59f71c2..0953946 100755 --- a/start.sh +++ b/start.sh @@ -114,12 +114,12 @@ ZIGBEE_FRONTEND_PORT=1881 EOF if [ "$device" != "FALSE" ] ; then cat >> .env <> .env <