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..0953946 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