Skip to content

Instantly share code, notes, and snippets.

@cgcostume
Last active November 2, 2023 20:27
Show Gist options
  • Save cgcostume/9ec5d1cac5e654f3250a0be842a7889b to your computer and use it in GitHub Desktop.
Save cgcostume/9ec5d1cac5e654f3250a0be842a7889b to your computer and use it in GitHub Desktop.
Configuration of a Raspbee (with deCONZ/phoscon) and node-RED server using docker and docker-compose on a Raspberry Pi 3

Raspbee on Raspberry Pi 3

Preparations

The following steps describe the prerequisites for the actual raspbee setup (deCONZ/phoscon and node-RED):

  1. Flash (e.g., using Etcher) raspbian-buster-lite onto SD card (e.g., 16GB).

  2. Create an empty ssh file on the SD card's boot partition.

  3. Create a wpa_supplicant.conf file (see template provided with this gist) on the SD card's boot partition (link).

  4. Eject SD card properly and start raspi with it (just provide power).

  5. Use a shell/terminal and connect to the raspi with ssh pi@rasperrypi (username pi, hostname raspberrypi, and default password is raspberry).

If your raspi is not found, check (1) whether your WPA config was correct (note that the file gets deleted whenever the raspi boots), (2) that your router allowed your raspi to enter your WAN/LAN, and (3) that you remove your raspi from previous known hosts (.ssh/known_hosts).

Raspberry Setup

  1. Update the raspi:

    1. sudo apt-get -y update && sudo apt-get -y full-upgrade
  2. Change pi user password:

    1. sudo raspi-config
  3. Install Docker:

    1. curl -sSL https://get.docker.com | sh
    2. sudo usermod -aG docker pi
    3. optional: test docker docker run hello-world
  4. Install docker-compose:

    1. sudo apt-get -y install libffi-dev libssl-dev
    2. sudo apt-get -y install python python-pip
    3. sudo apt-get -y remove python-configparser (some fix I had to apply for correct pip-based install)
    4. sudo pip install docker-compose
  5. Configure raspi:

    1. sudo raspi-config
    2. Set hostname to, e.g., raspbee (needs to be consistent with all upcomming hostnames). Note that for subsequent ssh connects the new hostname needs to be used: e.g., ssh pi@raspbee ...
    3. Goto Interfacing OptionsSerial and adjust as follows:
      • Would you like a login shell accessible over serial?No
      • Would you like the serial port hardware to be enabled?Yes
    4. optional: set timezone, WiFi locale, expand filesystem etc. and reboot sudo reboot.
  6. Create folder structure for deCONZ and node red configs:

    1. cd /opt/
    2. sudo mkdir docker
    3. cd docker/
  7. Create deconz and nodered config, environment, and adjust user access:

    1. sudo usermod -aG dialout pi
    2. sudo nano /boot/config.txt and add the following lines to the end:
      • enable_uart=1
      • dtoverlay=pi3-disable-bt
    3. sudo nano raspbee.yml (and paste raspbee.yml contents)
    4. sudo nano raspbee.env (and paste raspbee.env contents)
  8. Add node-red-contrib-deconz package to node-red container:

    1. install using the PaletteInstall tab within the node-red user settings
  9. optional: Make a backup of your SD card.

  10. If permission issues occur for ~/.local/share/node-red/data use: sudo chown -R 1000:1000 ~/.local/share/node-red

Start / Stop deCONZ

  1. start: docker-compose -f deconz.yml up -d
  2. stop: docker-compose -f deconz.yml stop
  3. recreate: docker-compose -f deconz.yml up -d --force-recreate
  4. clean all: docker system prune
  5. show log while running:
    1. docker container ls (copy CONTAINER ID)
    2. docker container logs -f deconz

Reduce Power Consumption

from How to save Power on your Raspberry Pi, i disabled USB and HDMI (bluetooth beeing already disabled). If the raspi is connected via LAN, also might disable the PI's WiFi:

  • Turn OFF USB chip: echo '1-1' |sudo tee /sys/bus/usb/drivers/usb/unbind
  • Turn ON USB chip: echo '1-1' |sudo tee /sys/bus/usb/drivers/usb/bind
  • Turn OFF HDMI output: sudo /opt/vc/bin/tvservice -o
  • Turn ON HDMI output: sudo /opt/vc/bin/tvservice -p
  • Disable Wi-Fi & Bluetooth: dtoverlay=pi3-disable-wifi and dtoverlay=pi3-disable-bt
  • Disable on-board LEDs: dtparam=act_led_trigger=none and dtparam=act_led_activelow=on

Install/Update Firmware

I bought a Raspbee Premium, but no firmware was installed. The green LED of the Raspbee was continuously blinking and no configuration, be it /dev/ttyAMA0, /dev/ttyS0, or /dev/serial0 has worked. I got the following deconz logs:

...
20:29:26:700 dev /dev/ttyAMA0
20:29:26:700 COM: /dev/ttyAMA0 / serialno:
20:29:26:700 COM: --dev: /dev/ttyAMA0 (RaspBee)
20:29:26:845 Error: invalid command
20:29:27:221 device state timeout ignored in state 2
...

Furthermore, neither the within deconz container firmware update worked as described nor running the gcfflasher directly worked for me, due to missing dependencies. GLIBC_2.28, libgglib-2.0.so, libtQt5Serial, and others where not found for running GCFlasher ... With the following steps i got the latest firmware installed on a blank Raspbee:

  1. sudo apt-get install libc6 libglib2.0-0 libgtk2.0-0 libsm6
  2. docker run -it --rm --entrypoint "/firmware-update.sh" --privileged --cap-add=ALL -v /dev:/dev -v /lib/modules:/lib/modules -v /sys:/sys -v /lib:/lib -v /usr/lib/arm-linux-gnueabihf:/usr/lib/arm-linux-gnueabihf marthoc/deconz
  3. follow the instructions of the flash script ...

Some links for node-RED use

# Change this value to your preferred time zone.
# Example: Europe/Amsterdam
TZ=Europe/Berlin
# deCONZ
DECONZ_DEVICE=/dev/ttyAMA0
DECONZ_WEB_PORT=80
DECONZ_WS_PORT=443
DEBUG_INFO=1
DEBUG_APS=0
DEBUG_ZCL=0
DEBUG_ZDP=0
DEBUG_OTAU=0
# node-RED flows
FLOWS=flows.json
# setting to true starts Node-RED in safe (not running) mode
NODE_RED_ENABLE_SAFE_MODE=false
# setting to true starts Node-RED with the projects feature
NODE_RED_ENABLE_PROJECTS=false
# fix the heap size threshold used by the Node.js garbage collector
# NODE_OPTIONS="--max_old_space_size=128"
version: "3.7"
services:
deconz:
image: marthoc/deconz
env_file: raspbee.env
container_name: deconz
network_mode: host
restart: unless-stopped
volumes:
- ~/.local/share/deconz:/root/.local/share/dresden-elektronik/deCONZ
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
devices:
- /dev/ttyAMA0
node-red:
image: nodered/node-red:latest
depends_on:
- deconz
env_file: raspbee.env
container_name: node-red
restart: unless-stopped
ports:
- "1880:1880"
networks:
- node-red-net
volumes:
- ~/.local/share/node-red:/data
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
networks:
node-red-net:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<Insert country code here>
network={
ssid="<Name of your WiFi>"
psk="<Password for your WiFi>"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment