mercenaruss / zigbee-stick-v4

Zigbee Stick based on RF-BM-2652P1/P2 Module from RF-STAR,with CC2652P on board
https://zig-star.com
Other
85 stars 29 forks source link

[SUGGESTIOn] Switch to USB-to-UART bridge chip with programmable EEPROM so can add custom "Product Description String" string as unique identifier? #7

Closed Hedda closed 2 years ago

Hedda commented 2 years ago

Re-post idea from HA community -> https://community.home-assistant.io/t/zigstar-zigbee-coordinators-and-routers/338586/6

Please consider switching the design to an other USB-to-Serial converter chip with its own writable EEPROM as a hardware feature.

This would allow you to add your own custom "Product Description String" as a unique identifier for it via the USB interface, and the reason for wanting a unique identifier via the USB interface is in order to enable the possibility for it to support automatic USB discovery of Zigbee USB adapters.

The whole point of this is to make it possible for developers to make the initial installation of Zigbee solution plug-and-play friendly and easier for different home automation software to automatically USB discover and initiate a setup without end-user interactions.

Support for USB discovery was recently added to Home Assistant OS (formerly HASSIO) and the ZHA integration for it, see here:

https://community.home-assistant.io/t/unique-friendly-name-description-for-automatic-zigbee-usb-adapter-discovery-in-home-assistant-zha-using-dongle-vendor-product-ids/337077

and also see pull request example for whilelisting USB devices for ZHA https://github.com/home-assistant/core/pull/56201

That unique customized USB description string could be something like ex.; "ZigStar USB Stick version 4 hardware revision 2.0.0".

The unique "description" string for each USB adapter can then be added to HA via a PR like this -> https://github.com/home-assistant/core/pull/56201

As I understand it, cheaper CH340 series (example CH340C and CH340E) by WCH which unfortunately does not support this feature.

UPDATE! It has now been confirmed that the CH340B variant does have an EEPROM that support "Product Description String", etc.

http://www.wch-ic.com/products/CH340.html

I understand that more expensive chips like FT231 chips by FTDI and CP210x chips by Silicon Labs / Silabs do support this feature:

https://ftdichip.com/products/ft231xs/ https://ftdichip.com/products/ft231xq/

FT231X/FT231XS: "Key Hardware Features" "Fully integrated 2048 byte EEPROM for storing device descriptors and CBUS I/O configuration."

https://www.silabs.com/interface/usb-bridges/classic/device.cp2102 https://www.silabs.com/interface/usb-bridges/classic/device.cp2104 https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers https://www.silabs.com/documents/public/data-sheets/cp2102n-datasheet.pdf https://www.silabs.com/documents/public/application-notes/an197.pdf https://www.silabs.com/documents/public/application-notes/an978-cp210x-usb-to-uart-api-specification.pdf https://www.silabs.com/documents/public/application-notes/AN571.pdf

"The CP2102N devices have the following features" "Internal 960-byte programmable ROM for vendor ID, product ID, serial number, power descriptor, release number, and product description strings"

"The CP2102N includes an internal electrically erasable programmable read-only memory (EEPROM). This memory may be used to customize the USB Vendor ID (VID), Product ID (PID), Product Description String, Power Descriptor, Device Release Number and Device Serial Number as desired for OEM applications. If the EEPROM is not programmed with OEM data, the default configuration data shown in the table below is used."

"Product String The Product String is an optional string that describes the product. It is limited to 126 characters."

PS: I understand that a bonus feature in of chips like FT231 and CP210x is to add the ability to allow users to auto-reset and put the device in bootloader mode via the DTR/RTS pins exposed will enable much easier firmware upgrades for the end-users as they will no longer need to press any buttons to enter bootloader mode, and then bootloader mode could be activated via software from the firmware flasher program software which could make the OTW (Over-The-Wire) firmware upgrade procedure more user-friendly.

Hedda commented 2 years ago

@mercenaruss I noticed this PR to Home Assistant Core which indicates that tube0013 must have managed have added USB discovery in Home Assistant and ZHA for tubeszb ch340B based serial devices by configuring a unique "Product Description String":

https://github.com/home-assistant/core/pull/56719

So the CH340B is another USB to serial bridge chip that integrates EEPROM used to configure the "Product Description String", etc.

http://www.wch-ic.com/products/CH340.html

mercenaruss commented 2 years ago

@Hedda I used CH340B in last 2 batches, but i didn't configure PID and VID. Will take a look at it and revert. Thank you for you're close interest in this.

tube0013 commented 2 years ago

The tool to program the eeprom is hard to find. Google "ch340cfg-produce"

It's in Chinese and windows only, but pretty straight forward.

mercenaruss commented 2 years ago

@Hedda First of all ,i should get a VID and PID

tube0013 commented 2 years ago

@Hedda First of all ,i should get a VID and PID

I didn't want to mess with the VID and PID as it may affect the serial drivers.

HA can match solely on the descriptor or serial which is what I customized

mercenaruss commented 2 years ago

@Hedda so descriptor is enough,hmm okay,will try this.

Hedda commented 2 years ago

@Hedda so descriptor is enough,hmm okay,will try this.

Yes, Home Assistant and ZHA uses the descriptor in combination with VID and PID to auto detect and identify unique devices.

You do not want to change VID and PID as the operating system uses those two to select which device driver to use.

This way multiple devices from different manufacturers can have same VID and PID while still being detected by app as unique.

Note! If you do change the VID or PID you must provide the customer with your own custom driver for your specific device.

Hedda commented 2 years ago

@mercenaruss Noticed that you already found zigpy discussion https://github.com/zigpy/zigpy/discussions/808 which indirectly describe how to submit support to upstream Home Assistant core for ZHA integration detection of your custom USB stick once you configured the USB-to-serial bridge chip with a unique identifier.

mercenaruss commented 2 years ago

@Hedda I'm on my waiting submitting PR. Thank you very much for your assistance. Will try soon to find time for LAN Zeroconf.

Hedda commented 2 years ago

Very nice! For reference, others can find the pull request for ZigStar USB Discovery here -> https://github.com/home-assistant/core/pull/59559

@mercenaruss You might also want to link a document update for home-assistant.io from that parent PR 😄

As noted for that, just make sure that target their "next" branch and that no other commits are in that patch:

https://github.com/home-assistant/home-assistant.io/blob/next/source/_integrations/zha.markdown

Soon you will be able to market your ZigStar USB Stick as "plug and play" compatible with Home Assistant OS! 👍

mercenaruss commented 2 years ago

@Hedda i did a mistake on the way, now what i should do? make a new PR, because something is going wrong with rebase. https://github.com/home-assistant/home-assistant.io/pull/20275

Will more simple to make a new PR i know,but want to understand how i mess up this.

Hedda commented 2 years ago

@Hedda i did a mistake on the way, now what i should do? make a new PR, because something is going wrong with rebase. home-assistant/home-assistant.io#20275

Yes probably easiest to just close https://github.com/home-assistant/home-assistant.io/pull/20275 and create a new PR. New patch for the "next" branch:

https://github.com/home-assistant/home-assistant.io/blob/next/source/_integrations/zha.markdown

mercenaruss commented 2 years ago

@Hedda i did a mistake on the way, now what i should do? make a new PR, because something is going wrong with rebase. home-assistant/home-assistant.io#20275

Yes probably easiest to just close home-assistant/home-assistant.io#20275 and create a new PR. New patch for the "next" branch:

https://github.com/home-assistant/home-assistant.io/blob/next/source/_integrations/zha.markdown

Can you help me with a PR on this, I messed up and really cant understand how to fix this.

Hedda commented 2 years ago

Can you help me with a PR on this, I messed up and really cant understand how to fix this.

No problem. PR submitted as you know -> https://github.com/home-assistant/home-assistant.io/pull/20320

Recommend leaving it like that and then submit a change later once your new name is established.

New issue here for name discussion so that you can close https://github.com/mercenaruss/zigbee-stick-v4/issues/7 ;) Please see -> https://github.com/mercenaruss/zigbee-stick-v4/issues/9

mercenaruss commented 2 years ago

@Hedda Done