WebThingsIO / zigbee-adapter

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

Add support for Zigbee TTL-serial addon boards #7

Closed dhylands closed 3 years ago

dhylands commented 6 years ago

In a similar vein to https://github.com/mozilla-iot/zwave-adapter/issues/8 the zigbee adapter should also have a way to use the TTL-serial port on the gpio header.

frederic34 commented 4 years ago
serialPortMatchesFilter(port) {
  // Under OSX, SerialPort.list returns the /dev/tty.usbXXX instead
  // /dev/cu.usbXXX. tty.usbXXX requires DCD to be asserted which
  // isn't necessarily the case for usb-to-serial dongles.
  // The cu.usbXXX doesn't care about DCD.
  if (port.comName.startsWith('/dev/tty.usb')) {
    port.comName = port.comName.replace('/dev/tty', '/dev/cu');
  }

  if (port.comName.startsWith('/dev/ttyS')) {
    return true;
  }

  for (const filter of this.param.filter) {
    let match = true;
    for (const [key, re] of Object.entries(filter)) {
      if (!Object.prototype.hasOwnProperty.call(port, key)) {
        match = false;
        break;
      }

      if (typeof port[key] !== 'string') {
        match = false;
        break;
      }

      if (!port[key].match(re)) {
        match = false;
        break;
      }
    }

    if (match) {
      return true;
    }
  }

  return false;
}

I made a change in serial prober to allow /dev/ttyS without filter in this way raspbee on raspberry gpio works

mrstegeman commented 4 years ago

I believe we still need to probe the device somehow, otherwise we're just going to match any generic serial device.

frederic34 commented 4 years ago

there is still the probe with probeCmd and probeRSp, but no filter with vendorId and productId

mrstegeman commented 4 years ago

Ah, I see. This seems reasonable then. @dhylands what do you think?

davehylands commented 4 years ago

On the raspberry Pi, I thought that the serial port for the TTL addon boards was /dev/ttyAMA0?

At least on my 3B+ there are no /dev/ttyS ports, just /dev/ttyAMA0 (/dev/ttyS is what is used on x86 desktop linux).

Otherwise I think it would be fine (of course the change needs to go in the https://github.com/mozilla-iot/serial-prober-node/ repository).

I think that the caller should have to set a boolean or something to allow this. You might have something else connected to the serial port pins and you don't necessarily even want to probe.

The zigbee adapter would then expose a checkbox to allow probing of the serial port and that would get passed into the serial-prober (this boolean is essentially taking the place of the the VID/PID portion of the filter).

frederic34 commented 4 years ago

I read this article https://www.abelectronics.co.uk/kb/article/1035/raspberry-pi-3--4-and-zero-w-serial-port-usage and my serial is now /dev/ttyAMA0

davidhitchins commented 4 years ago

I have been trying for weeks to get my Raspbee II working and feel that I am coming close with the help of the comments on this topic. I thought that by adding these lines to serial-prober as @frederic34 has indicated - not /dev/ttyS - it might work. if (port.comName.startsWith('/dev/ttyAMA0')) { return true; } After adding the Zigbee adapter addon on the WebThings gateway page, I then inserted the above code snippet into serial-prober in the correct place in the serialPortMatchesFilter function (just after if (port.comName.startsWith('/dev/tty.usb')) { port.comName = port.comName.replace('/dev/tty', '/dev/cu'); } Upon rebooting the Pi and navigating to the addons page I find that the Zigbee Adapter addon has disappeared! Any idea what is going on please?

frederic34 commented 4 years ago

@davidhitchins serial prober has been updated, see https://github.com/mozilla-iot/serial-prober-node/commit/5dc4cd88371ebc8601f8fe0d1b3beed84f9d8984 perhaps you have to replace port.comName with port.path

davehylands commented 4 years ago

I have been trying for weeks to get my Raspbee II working and feel that I am coming close with the help of the comments on this topic. I thought that by adding these lines to serial-prober as @frederic34 has indicated - not /dev/ttyS - it might work. if (port.comName.startsWith('/dev/ttyAMA0')) { return true; } After adding the Zigbee adapter addon on the WebThings gateway page, I then inserted the above code snippet into serial-prober in the correct place in the serialPortMatchesFilter function (just after if (port.comName.startsWith('/dev/tty.usb')) { port.comName = port.comName.replace('/dev/tty', '/dev/cu'); } Upon rebooting the Pi and navigating to the addons page I find that the Zigbee Adapter addon has disappeared! Any idea what is going on please?

This probably means that an error occurred in the changes you made. You should be able to see the error in the gateway logs.

Keep in mind that you probably need to make a bunch of other changes to your system, like turning off the getty on /dev/ttyAMA, and also turning off the kernel logging so that it no longer goes to /dev/ttyAMA0.

davidhitchins commented 4 years ago

Thanks @davehylands . Yes, I had made the changes you mentioned in the last sentence above. I checked the gateway logs and all is fine up till the following lines (below). Seems it's some sort of checksum problem that prevents the modified Zigbee adapter addon from loading. Could you please indicate how to fix this? I really am NOT a coder but can work things out with a bit of guidance.

2020-07-31 08:26:57.125 ERROR  : Failed to load add-on zigbee-adapter: Error: Checksum failed for file /home/pi/.mozilla-iot/addons/zigbee-adapter/node_modules/serial-prober/serial-prober.js in add-on zigbee-adapter
    at find.fileSync.forEach (/home/pi/mozilla-iot/gateway/build/webpack:/src/addon-utils.js:215:1)
    at Array.forEach (<anonymous>)
    at loadManifestJson (/home/pi/mozilla-iot/gateway/build/webpack:/src/addon-utils.js:197:1)
    at Object.loadManifest (/home/pi/mozilla-iot/gateway/build/webpack:/src/addon-utils.js:303:1)
    at AddonManager.loadAddon (/home/pi/mozilla-iot/gateway/build/webpack:/src/addon-manager.js:614:1)
    at fs.readdir (/home/pi/mozilla-iot/gateway/build/webpack:/src/addon-manager.js:737:1)
    at FSReqWrap.args [as oncomplete] (fs.js:140:20)
2020-07-31 08:26:59.292 INFO   : PageKite connected!
2020-07-31 08:26:59.295 INFO   : Starting certificate renewal.
2020-07-31 08:26:59.313 INFO   : Certificate not yet due for renewal.
2020-07-31 08:27:19.841 INFO   : Checking for add-on updates...
2020-07-31 08:27:21.102 INFO   : Finished updating add-ons
mrstegeman commented 4 years ago
mkdir ~/.mozilla-iot/addons/zigbee-adapter/.git

Create that directory and restart the add-on (or the gateway). The checksums will be ignored.

davidhitchins commented 4 years ago

Thanks @mrstegeman; the addon seems to be loaded now but the logs say XBee dongle not detected on /dev/ttyAMA0 Can you suggest anything else please?

2020-07-31 09:39:26.017 INFO   : zigbee-adapter: Loading add-on zigbee-adapter from /home/pi/.mozilla-iot/addons/zigbee-adapter
2020-07-31 09:39:26.071 INFO   : zigbee-adapter: DEBUG config = ''
2020-07-31 09:39:26.801 ERROR  : zigbee-adapter: SerialProber: timeout: XBee dongle not detected on /dev/ttyAMA0
2020-07-31 09:39:27.048 INFO   : zigbee-adapter: this.driver = DeconzDriver {}
2020-07-31 09:39:27.051 INFO   : zigbee-adapter: DeconzDriver: Using serial port /dev/ttyAMA0
2020-07-31 09:39:27.066 INFO   : zigbee-adapter: DeConz Firmware version: 26520700
mrstegeman commented 4 years ago

Seems like it may need a longer timeout.

davidhitchins commented 3 years ago

Yes, I wondered about that and changed this line in serial-prober.js https://github.com/mozilla-iot/serial-prober-node/blob/5dc4cd88371ebc8601f8fe0d1b3beed84f9d8984/serial-prober.js#L96 to }, 10000); //originally 500

It made no difference. In case someone can suggest what might be wrong, please see attached details logs from the WebThings Gateway. It's worth noting that I no longer get the popup message, "NO ZIGBEE DONGLE FOUND" when loading the zigbee-adapter ADD-ON as I used to get. So it is half working? Also if I run serial-test.js there are two long pauses before the following is returned: pi@***:~/.mozilla-iot/addons/zigbee-adapter/node_modules/serial-prober $ node serial-test.js [Error: Error Resource temporarily unavailable Cannot lock port] [Error: Error Resource temporarily unavailable Cannot lock port] Nothing found Boy! Is this a tricky one! log of problem with Raspbee II not found.txt

mrstegeman commented 3 years ago

I'm going to lump this in with #110, since the same fix will solve both.