WebThingsIO / zigbee-adapter

Zigbee adapter add-on for WebThings Gateway
Mozilla Public License 2.0
46 stars 29 forks source link

Still RaspBee II issue - /dev/ttyAMA0 permissions #269

Open mchisari opened 3 years ago

mchisari commented 3 years ago

Hi, I have a RaspBee II with firmware 26610700 I'd like to use with WebThings.

I've just downloaded and installed a fresh gateway, version 1.0.0, and installed it on a Raspberry Pi 3B. I've done everything as described: added "dtoverlay=pi3-miniuart-bt" in config.txt and removed "console=tty1" from cmdline.txt; then enabled plugin with "allowAMASerial". However, it didn't suffice; the adapter was still unrecognized. I noticed messages like this in run-app.log:

ERROR : zigbee-adapter: [Error: Error: Permission denied, cannot open /dev/ttyAMA0]

so I did ls -la /dev/tty* and got:

...
crw--w---- 1 root tty     204, 64 Dec 13 00:13 /dev/ttyAMA0
crw------- 1 root root      5,  3 Dec  2 23:17 /dev/ttyprintk
crw-rw---- 1 root dialout   4, 64 Dec  2 23:17 /dev/ttyS0

As you can see, differently from ttyS0, ttyAMA0' group was tty (which is not among those of pi user which runs gateway); I've tried to fix permissions and give ownership to pi; nothing didn't help as the new permissions were reverted immediately.

After googling a bit, I've come to the right solution: issuing "sudo systemctl mask serial-getty@ttyAMA0" and rebooting made it.

Apparently, a login console was spawned at ttyAMA0, which is connected to the RaspBee; I guess the latter kept sending characters to login prompt, making it restart and reverting permissions (not that it would work that way anyway...).

For reference, here is the failing log:

2020-12-12 23:30:04.057 INFO   : Loading add-on: zigbee-adapter
2020-12-12 23:30:05.911 INFO   : zigbee-adapter: Opening database: /home/pi/.webthings/config/db.sqlite3
2020-12-12 23:30:05.965 INFO   : zigbee-adapter: Ignoring https://raw.githubusercontent.com/WebThingsIO/gateway-addon-ipc-schema/master/schema.json because it has no messageType
2020-12-12 23:30:07.613 INFO   : zigbee-adapter: Ignoring https://raw.githubusercontent.com/WebThingsIO/gateway-addon-ipc-schema/master/messages/definitions.json because it has no messageType
2020-12-12 23:30:10.392 INFO   : zigbee-adapter: Loading add-on zigbee-adapter from /home/pi/.webthings/addons/zigbee-adapter
2020-12-12 23:30:10.497 INFO   : zigbee-adapter: DEBUG config = ''
2020-12-12 23:30:10.861 ERROR  : zigbee-adapter: [Error: Error: Permission denied, cannot open /dev/ttyAMA0]
2020-12-12 23:30:10.864 INFO   : zigbee-adapter: Serial ports that were found:
2020-12-12 23:30:11.066 INFO   : zigbee-adapter: Serial Device found @ /dev/ttyAMA0
2020-12-12 23:30:11.069 INFO   : zigbee-adapter: Serial Device found @ /dev/ttyS0
2020-12-12 23:30:11.072 ERROR  : zigbee-adapter: Failed to start add-on zigbee-adapter: No Zigbee dongle found

And this the working one:

2020-12-13 01:02:53.685 INFO   : Loading add-on: zigbee-adapter
2020-12-13 01:02:55.975 INFO   : zigbee-adapter: Opening database: /home/pi/.webthings/config/db.sqlite3
2020-12-13 01:02:56.045 INFO   : zigbee-adapter: Ignoring https://raw.githubusercontent.com/WebThingsIO/gateway-addon-ipc-schema/master/schema.json because it has no messageType
2020-12-13 01:02:58.807 INFO   : zigbee-adapter: Ignoring https://raw.githubusercontent.com/WebThingsIO/gateway-addon-ipc-schema/master/messages/definitions.json because it has no messageType
2020-12-13 01:03:03.269 INFO   : zigbee-adapter: Loading add-on zigbee-adapter from /home/pi/.webthings/addons/zigbee-adapter
2020-12-13 01:03:03.388 INFO   : zigbee-adapter: DEBUG config = ''
2020-12-13 01:03:04.351 INFO   : zigbee-adapter: this.driver = DeconzDriver {}
2020-12-13 01:03:04.356 INFO   : zigbee-adapter: DeconzDriver: Using serial port /dev/ttyAMA0
2020-12-13 01:03:04.369 ERROR  : zigbee-adapter: packet = <Buffer 61 26 5b ff>
2020-12-13 01:03:04.372 ERROR  : zigbee-adapter: deConz error: Error: Invalid packet (too small)
2020-12-13 01:03:04.374 ERROR  : zigbee-adapter:     at DeconzAPI.onPacket (/home/pi/.webthings/addons/zigbee-adapter/node_modules/deconz-api/lib/deconz-api.js:101:19)
2020-12-13 01:03:04.375 ERROR  : zigbee-adapter:     at Parser.emit (events.js:198:13)
2020-12-13 01:03:04.377 ERROR  : zigbee-adapter:     at Parser.parseChunk (/home/pi/.webthings/addons/zigbee-adapter/node_modules/deconz-api/lib/slip.js:60:16)
2020-12-13 01:03:04.379 ERROR  : zigbee-adapter:     at DeconzAPI.parseRaw (/home/pi/.webthings/addons/zigbee-adapter/node_modules/deconz-api/lib/deconz-api.js:170:21)
2020-12-13 01:03:04.380 ERROR  : zigbee-adapter:     at SerialPort.DeconzDriver.serialPort.on (/home/pi/.webthings/addons/zigbee-adapter/deconz-driver.js:133:15)
2020-12-13 01:03:04.382 ERROR  : zigbee-adapter:     at SerialPort.emit (events.js:198:13)
2020-12-13 01:03:04.384 ERROR  : zigbee-adapter:     at addChunk (_stream_readable.js:288:12)
2020-12-13 01:03:04.385 ERROR  : zigbee-adapter:     at readableAddChunk (_stream_readable.js:269:11)
2020-12-13 01:03:04.387 ERROR  : zigbee-adapter:     at SerialPort.Readable.push (_stream_readable.js:224:10)
2020-12-13 01:03:04.389 ERROR  : zigbee-adapter:     at binding.read.then (/home/pi/.webthings/addons/zigbee-adapter/node_modules/@serialport/stream/lib/index.js:385:12)
2020-12-13 01:03:04.392 INFO   : zigbee-adapter: DeConz Firmware version: 26610700
2020-12-13 01:03:04.544 INFO   : zigbee-adapter: Kicking WatchDog for 3600 seconds
2020-12-13 01:03:04.643 INFO   : zigbee-adapter: Node: undefined d50f not found
2020-12-13 01:03:04.663 INFO   : zigbee-adapter: Node: undefined d50f not found
2020-12-13 01:03:04.694 INFO   : zigbee-adapter: Node: undefined 4b93 not found
2020-12-13 01:03:04.715 INFO   : zigbee-adapter:          MAC Address: 00212effff0621e3
2020-12-13 01:03:04.717 INFO   : zigbee-adapter:      Network PANID16: 8f67
2020-12-13 01:03:04.719 INFO   : zigbee-adapter:       Network Addr16: 0000
2020-12-13 01:03:04.721 INFO   : zigbee-adapter:      Network PANID64: 00212effff0621e3
2020-12-13 01:03:04.722 INFO   : zigbee-adapter: APS Designated Coordinator: 1
2020-12-13 01:03:04.724 INFO   : zigbee-adapter:        Scan Channels: 00008000
2020-12-13 01:03:04.726 INFO   : zigbee-adapter:          APS PANID64: 0000000000000000
2020-12-13 01:03:04.727 INFO   : zigbee-adapter:  Trust Center Addr64: <hidden>
2020-12-13 01:03:04.729 INFO   : zigbee-adapter:        Security Mode: 3
2020-12-13 01:03:04.731 INFO   : zigbee-adapter:          Network Key: <hidden>
2020-12-13 01:03:04.733 INFO   : zigbee-adapter:    Operating Channel: 15
2020-12-13 01:03:04.734 INFO   : zigbee-adapter:     Protocol Version: 267
2020-12-13 01:03:04.736 INFO   : zigbee-adapter:    Network Update ID: 0
2020-12-13 01:03:04.738 INFO   : zigbee-adapter:          Permit Join: 0
2020-12-13 01:03:04.739 INFO   : zigbee-adapter:         WatchDog TTL: 3600
2020-12-13 01:03:04.741 INFO   : zigbee-adapter:              Version: 26610700

I don't know if "invalid packet" hurts, however I see it only happened once.

davehylands commented 3 years ago

The fact that /dev/ttyAMA0 has a group owner of tty typically means that there is a getty running on that port, and you need to disable that.

frederic34 commented 3 years ago

Conbee is USB and is not on /dev/ttyAMA0 ? Did you look here https://github.com/WebThingsIO/serial-prober-node/issues/11

mchisari commented 3 years ago

Sorry - my mistake. It's a Raspbee II...

frederic34 commented 3 years ago

@mchisari can you edit title and first message ?