gcgarner / IOTstack

docker stack for getting started on IOT on the Raspberry PI
GNU General Public License v3.0
1.5k stars 578 forks source link

Zigbee2MQTT:error Error while opening serialport #221

Open jabss opened 3 years ago

jabss commented 3 years ago

Hello,

Not sure if this is an issue from IoTStack or zigbee2mqtt, but here it goes:

I'm trying to use a CC2652RB development stick - but the zigbee2mqtt keeps restarting every minute or so. It isn't able to access the stick, which is recognized by the OS as /dev/ttyUSB0. (BTW, modemmanager isn't installed on this system)

Initially, I changed the the /home/pi/IOTstack/volumes/zigbee2mqtt/data/configuration.yaml to:

#Serial settings
serial:
  #Location of CC2531 USB sniffer
  #port: /dev/ttyACM0
  port: /dev/ttyUSB0

But this didn't work, so after further reading and troubleshooting I understood that, when on a stack, the docker container isn't able to access directly the /dev/ttyUSB0 so a special procedure is required to make it available to it. So I followed the procedure described in zigbee2mqtt.io.

After this, I had a new link to the original device, that would be supposed to be accessible to the zigbee2mqtt docker container, called /dev/cc2652:

pi@raspberrypi:~/ $ ls -larth /dev/cc2652
lrwxrwxrwx 1 root root 7 Dec 25 02:02 /dev/cc2652 -> ttyUSB0

After some restarts and reboots, the log shown exactly the same error: not possible to read the stick.

 zigbee2mqtt@1.16.2 start /app
 node index.js
Zigbee2MQTT:info  2020-12-25 03:06:31: Logging to console and directory: '/app/data/log/2020-12-25.03-06-30' filename: log.txt
Zigbee2MQTT:info  2020-12-25 03:06:31: Starting Zigbee2MQTT version 1.16.2 (commit #04c15f7)
Zigbee2MQTT:info  2020-12-25 03:06:31: Starting zigbee-herdsman (0.13.37)
Zigbee2MQTT:error 2020-12-25 03:06:31: Error while starting zigbee-herdsman
Zigbee2MQTT:error 2020-12-25 03:06:31: Failed to start zigbee
Zigbee2MQTT:error 2020-12-25 03:06:31: Exiting...
Zigbee2MQTT:error 2020-12-25 03:06:31: Error: Error while opening serialport 'Error: Error: No such file or directory, cannot open /dev/cc2652'
    at Znp.<anonymous> (/app/node_modules/zigbee-herdsman/dist/adapter/z-stack/znp/znp.js:136:32)
    at Generator.next (<anonymous>)
    at /app/node_modules/zigbee-herdsman/dist/adapter/z-stack/znp/znp.js:27:71
    at new Promise (<anonymous>)
    at __awaiter (/app/node_modules/zigbee-herdsman/dist/adapter/z-stack/znp/znp.js:23:12)
    at SerialPort.<anonymous> (/app/node_modules/zigbee-herdsman/dist/adapter/z-stack/znp/znp.js:134:49)
    at SerialPort._error (/app/node_modules/zigbee-herdsman/node_modules/@serialport/stream/lib/index.js:198:14)
    at /app/node_modules/zigbee-herdsman/node_modules/@serialport/stream/lib/index.js:242:12
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! zigbee2mqtt@1.16.2 start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the zigbee2mqtt@1.16.2 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-12-25T03_06_32_013Z-debug.log

I troubleshooted the procedure scripts that supposedly will make the new device available to the docker container and realized there is something that isn't right:

The script is:

#!/bin/bash
 USBDEV=`readlink -f /dev/cc2652`
 read minor major < <(stat -c '%T %t' $USBDEV)
 if [[ -z $minor || -z $major ]]; then
     echo 'Device not found'
     exit
 fi
 dminor=$((0x${minor}))
 dmajor=$((0x${major}))
 CID=`docker ps -a --no-trunc | grep koenkk/zigbee2mqtt | head -1 |  awk '{print $1}'`
 if [[ -z $CID ]]; then
     echo 'CID not found'
     exit
 fi
 echo 'Setting permissions'
 echo "c $dmajor:$dminor rwm" > /sys/fs/cgroup/devices/docker/$CID/devices.allow

And it fails because firstly, it starts by getting the zigbee2mqtt docker container identifier:

docker ps -a --no-trunc | grep koenkk/zigbee2mqtt | head -1 | awk '{print $1}'

Then, the script is supposed to add the permissions to that container:

echo "c $dmajor:$dminor rwm" > /sys/fs/cgroup/devices/docker/$CID/devices.allow

But, the contained ID found previously never exists in /sys/fs/cgroup/devices/docker/, so the permissions aren't added.

So, is it expected that the CID of a docker container, obtained by the docker ps -a --no-trunc command isn't available in the /sys/fs/cgroup/devices/docker/ directory?

How to make this work?

Cheers, Joaoabs

Paraphraser commented 3 years ago

Please see This project is dormant.

I'm not saying your problem will necessarily be solved by switching to SensorsIot/IOTstack but zigbee2mqtt has had more recent work done on that repo.

A word to the wise, however. The new repo is in the middle of switching to a new menu structure and there are a lot of problems being reported. To minimise the risk of confusing a zigbee2mqtt issue with an artefact of the new menu, I'd recommend

$ cd ~/IOTstack
$ git remote set-url origin https://github.com/SensorsIot/IOTstack.git
$ git pull origin master
$ git checkout old-menu

then I'd nose around ~/IOTstack/.templates/zigbee2mqtt and compare/contrast the service.yml definition with what you have in ~/IOTstack/services/zigbee2mqtt and, therefore, implied in docker-compose.yml.

There was also at least one issue in the new repo on this so maybe search the issues for zigbee2mqtt.

Hope this helps.

Paraphraser commented 3 years ago

Please see This project is dormant.

I'm not saying your problem will necessarily be solved by switching to SensorsIot/IOTstack but zigbee2mqtt has had more recent work done on that repo.

A word to the wise, however. The new repo is in the middle of switching to a new menu structure and there are a lot of problems being reported. To minimise the risk of confusing a zigbee2mqtt issue with an artefact of the new menu, I'd recommend

$ cd ~/IOTstack
$ git remote set-url origin https://github.com/SensorsIot/IOTstack.git
$ git pull origin master
$ git checkout old-menu

then I'd nose around ~/IOTstack/.templates/zigbee2mqtt and compare/contrast the service.yml definition with what you have in ~/IOTstack/services/zigbee2mqtt and, therefore, implied in docker-compose.yml.

There was also at least one issue in the new repo on this so maybe search the issues for zigbee2mqtt.

Hope this helps.

Paraphraser commented 3 years ago

See if Issue 167 helps.