dvmarinoff / Auuki

Indoor Cycling App for Structured Training
https://auuki.com
GNU Affero General Public License v3.0
551 stars 93 forks source link

add support for ANT+ on the web #12

Closed dvmarinoff closed 2 years ago

dvmarinoff commented 3 years ago

Supporting Ant+ on the web.

dvmarinoff commented 3 years ago

Research WebUSB as possible way to implement.

The native driver is taking over the ant+ usb device, and it requires a manual unbind. Does not appear to be a long term solution.

Useful links and tools

0fcf  Dynastream Innovations, Inc.
    1003  ANT Development Board
    1004  ANTUSB Stick
    1006  ANT Development Board
    1008  ANTUSB2 Stick
    1009  ANTUSB-m Stick
$ lsusb
Bus 002 Device 016: ID 0fcf:1008 Dynastream Innovations, Inc. ANTUSB2 Stick
$ lsusb -t
/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/9p, 480M
    |__ Port 1: Dev 16, If 0, Class=Vendor Specific Class, Driver=usb_serial_simple, 12M
$ grep 0fcf /sys/bus/usb/devices/*/idVendor
/sys/bus/usb/devices/2-1/idVendor:0fcf

In Logs:

usb 2-1: suunto converter now attached to ttyUSB0
usb_serial_simple 2-1:1.0: suunto converter detected

Something of the sort is needed to unbind the ant+ usb device:

$ echo -n "2-1:1.0" | tee -a /sys/bus/usb/drivers/usb_serial_simple/unbind

dvmarinoff commented 3 years ago

Research Web Serial API

Connects to the ant+ usb device.

dvmarinoff commented 3 years ago

How to give permission to ANT+ USB stick on Ubuntu:

Create a rule file:

$ touch 50-move-stick-mini.rules

$ vim 50-move-stick-mini.rules
SUBSYSTEM=="usb", ATTRS{idVendor}=="0fcf", ATTRS{idProduct}=="1008", MODE="0664", GROUP="plugdev"

$ mv 50-move-stick-mini.rules /etc/udev/rules.d/

unplug and plug device for the rule to take effect

Check permissions and groups:

$ ls -l /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 0 Jan 25 17:00 /dev/ttyUSB0

Check user membership:

$ groups <username>
$ id -Gn <username>

Add user to a group if needed: $ sudo usermod -a -G <groupname> <username>

Logout and Login for changes to take effect.

dvmarinoff commented 3 years ago

WebSerial is not available on Mobile devices, but WebUSB is and it appears to be usable.

Moreover it is possible to connect the device to a USB-C monitor, switch to desktop mode (marketed as DeX on Samsung) and gain access to the USB ports on the monitor. This way ANT+ usb stick can be used from a web page on a mobile device.

A simpler way is to use USB-A to to USB-C adapter and plug it in the charging port of the phone, but that would make using the port for charging, screen mirroring, or desktop mode not possible.

Prereq. is to have ANT+ USB Service plugin installed from Play Store.

dvmarinoff commented 3 years ago

On Windows 10 WebUSB and WebSerial are available, but WebSerial does not recognize the device and WebUSB can't open it. Here and on Ubuntu device.open() on WebUSB throws the error: 'Uncaught DOMException: Access denied.' WebUSB issue

On Windows 10 the default driver needs to be replaced with another one with the Zadig utillity tool (download, docs).

On Windows 10 with the libusb-win32 (default) driver:

With the WinUSB driver:

With the USB Serial (CDC) driver:

dvmarinoff commented 2 years ago

Summary:

This effort is getting way too big and is moving to another project.