You are not logged in.

#1 2019-02-19 22:40:36

d_fajardo
Member
Registered: 2017-07-28
Posts: 1,568

[Solved] Run script when connecting device via bluetooth

I need help to run a script when I connect my wacom bluetooth device. So far I gathered I had to write a udev rule which I tried. First of all from udevadm I gathered that the device shows up as /dev/hidraw3. From bluetooth, I can also pick up it's MAC address. So I wrote this udev rule:

ACTION=="add", KERNEL=="hidraw3", SUBSYSTEM=="hidraw", SUBSYSTEMS=="usb", ATTRS{address}=="dc:2c:26:da:1f:6c", ATTRS{idVendor}=="1d6b", ATTRS{idProduct}=="07dc", OWNER="brightchip", RUN+="/home/datapool/bin/wacom"

However the script doesn't run.
For info here is the output of udevadm info -a -n hidraw3:

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/pci0000:00/0000:00:14.0/usb1/1-9/1-9:1.0/bluetooth/hci0/hci0:256/0005:056A:0377.000B/hidraw/hidraw3':
    KERNEL=="hidraw3"
    SUBSYSTEM=="hidraw"
    DRIVER==""

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-9/1-9:1.0/bluetooth/hci0/hci0:256/0005:056A:0377.000B':
    KERNELS=="0005:056A:0377.000B"
    SUBSYSTEMS=="hid"
    DRIVERS=="wacom"
    ATTRS{speed}=="0"
    ATTRS{country}=="21"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-9/1-9:1.0/bluetooth/hci0/hci0:256':
    KERNELS=="hci0:256"
    SUBSYSTEMS=="bluetooth"
    DRIVERS==""

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-9/1-9:1.0/bluetooth/hci0':
    KERNELS=="hci0"
    SUBSYSTEMS=="bluetooth"
    DRIVERS==""

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-9/1-9:1.0':
    KERNELS=="1-9:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="btusb"
    ATTRS{bInterfaceClass}=="e0"
    ATTRS{bInterfaceProtocol}=="01"
    ATTRS{bInterfaceNumber}=="00"
    ATTRS{supports_autosuspend}=="1"
    ATTRS{bInterfaceSubClass}=="01"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{authorized}=="1"
    ATTRS{bNumEndpoints}=="03"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-9':
    KERNELS=="1-9"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{tx_lanes}=="1"
    ATTRS{authorized}=="1"
    ATTRS{ltm_capable}=="no"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bDeviceSubClass}=="01"
    ATTRS{devnum}=="6"
    ATTRS{urbnum}=="4333"
    ATTRS{rx_lanes}=="1"
    ATTRS{maxchild}=="0"
    ATTRS{idProduct}=="07dc"
    ATTRS{configuration}==""
    ATTRS{bNumConfigurations}=="1"
    ATTRS{idVendor}=="8087"
    ATTRS{bDeviceProtocol}=="01"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{speed}=="12"
    ATTRS{bcdDevice}=="0001"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{removable}=="removable"
    ATTRS{bNumInterfaces}==" 2"
    ATTRS{version}==" 2.00"
    ATTRS{devpath}=="9"
    ATTRS{devspec}=="          (null)"
    ATTRS{bMaxPower}=="100mA"
    ATTRS{busnum}=="1"
    ATTRS{bDeviceClass}=="e0"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1':
    KERNELS=="usb1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{rx_lanes}=="1"
    ATTRS{devspec}=="          (null)"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bDeviceProtocol}=="01"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{removable}=="unknown"
    ATTRS{urbnum}=="151"
    ATTRS{idVendor}=="1d6b"
    ATTRS{interface_authorized_default}=="1"
    ATTRS{quirks}=="0x0"
    ATTRS{authorized}=="1"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{devnum}=="1"
    ATTRS{devpath}=="0"
    ATTRS{authorized_default}=="1"
    ATTRS{configuration}==""
    ATTRS{bConfigurationValue}=="1"
    ATTRS{product}=="xHCI Host Controller"
    ATTRS{version}==" 2.00"
    ATTRS{idProduct}=="0002"
    ATTRS{tx_lanes}=="1"
    ATTRS{bcdDevice}=="0420"
    ATTRS{maxchild}=="16"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bMaxPower}=="0mA"
    ATTRS{ltm_capable}=="no"
    ATTRS{speed}=="480"
    ATTRS{busnum}=="1"
    ATTRS{bDeviceClass}=="09"
    ATTRS{serial}=="0000:00:14.0"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{manufacturer}=="Linux 4.20.10-arch1-1-ARCH xhci-hcd"

  looking at parent device '/devices/pci0000:00/0000:00:14.0':
    KERNELS=="0000:00:14.0"
    SUBSYSTEMS=="pci"
    DRIVERS=="xhci_hcd"
    ATTRS{subsystem_vendor}=="0x1849"
    ATTRS{driver_override}=="(null)"
    ATTRS{local_cpulist}=="0-7"
    ATTRS{class}=="0x0c0330"
    ATTRS{numa_node}=="-1"
    ATTRS{d3cold_allowed}=="1"
    ATTRS{broken_parity_status}=="0"
    ATTRS{enable}=="1"
    ATTRS{dma_mask_bits}=="64"
    ATTRS{device}=="0xa2af"
    ATTRS{vendor}=="0x8086"
    ATTRS{revision}=="0x00"
    ATTRS{local_cpus}=="ff"
    ATTRS{devspec}==""
    ATTRS{subsystem_device}=="0xa2af"
    ATTRS{ari_enabled}=="0"
    ATTRS{irq}=="130"
    ATTRS{consistent_dma_mask_bits}=="64"
    ATTRS{msi_bus}=="1"

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""

Anything I'm missing?
Also how do you use logger in the script I'm running to see if it's being executed properly?

Last edited by d_fajardo (2019-02-21 09:45:54)

Offline

#2 2019-02-19 22:53:59

loqs
Member
Registered: 2014-03-06
Posts: 17,373

Re: [Solved] Run script when connecting device via bluetooth

ATTRS{address}=="dc:2c:26:da:1f:6c" is not listed in the udevadm output so I do not believe it will match.
ATTRS{idVendor}=="1d6b and ATTRS{idProduct}=="07dc" are not from the same parent I think that breaks the single parent requirement.

Offline

#3 2019-02-20 00:08:28

d_fajardo
Member
Registered: 2017-07-28
Posts: 1,568

Re: [Solved] Run script when connecting device via bluetooth

Thanks loqs. I'll do some tests again.

Offline

#4 2019-02-20 09:33:49

d_fajardo
Member
Registered: 2017-07-28
Posts: 1,568

Re: [Solved] Run script when connecting device via bluetooth

Still no luck. I tried:

ACTION=="add", KERNEL=="hidraw3", SUBSYSTEM=="hidraw", KERNELS=="1-9", SUBSYSTEMS=="usb", DRIVERS=="usb", ATTRS{idProduct}=="07dc", ATTRS{idVendor}=="8087", OWNER="brightchip", RUN+="/home/datapool/bin/wacom"

and the script still won't execute. I've tested that the script works when I execute it as a standalone program.
udevadm test $(udevadm info -q path -n hidraw3) 2>&1 gives me thiese at the end:

...
Rules contain 393216 bytes tokens (32768 * 12 bytes), 36100 bytes strings
30635 strings (244002 bytes), 26923 de-duplicated (211615 bytes), 3713 trie nodes used
Invalid inotify descriptor.
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-9/1-9:1.0/bluetooth/hci0/hci0:256/0005:056A:0377.000C/hidraw/hidraw3
DEVNAME=/dev/hidraw3
MAJOR=237
MINOR=3
ACTION=add
SUBSYSTEM=hidraw
USEC_INITIALIZED=6646943445
run: '/home/datapool/bin/wacom'
Unload module index
Unloaded link configuration context.

Is there anything here that might be a clue?

Offline

#5 2019-02-20 10:14:00

d_fajardo
Member
Registered: 2017-07-28
Posts: 1,568

Re: [Solved] Run script when connecting device via bluetooth

I checked jounalctl and I get this error:

systemd-udevd[27741]: Process '/home/datapool/bin/wacom' failed with exit code 255

It does seem that the rule is triggered but fails to run the script. Is this permission problem?

Offline

#6 2019-02-20 13:28:27

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,531
Website

Re: [Solved] Run script when connecting device via bluetooth

And what's in that script?  That journal line looks like it did run the script.  But the script itself exited with a non-zero return value.  Most likely the script tried to return -1, but this is interpreted as 255 by the shell.

Last edited by Trilby (2019-02-20 13:29:31)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#7 2019-02-20 13:51:06

d_fajardo
Member
Registered: 2017-07-28
Posts: 1,568

Re: [Solved] Run script when connecting device via bluetooth

It is a script to map the buttons of the wacom tablet to certain keyboard combinations. At the moment, there is only one line of code:

xsetwacom set "Wacom Intuos BT S Pad" Button 8 "key +ctrl s -ctrl"

the idea taken from here. I am hoping to implement the rest of the buttons and implement other xsetwacom configurations once I'm sure the script will run in udev.
Currently the script works. If I connect the device via bluetooth and execute the script, then the functionality works. I am hoping to have this executed automatically upon connection of the device.

Last edited by d_fajardo (2019-02-20 13:54:17)

Offline

#8 2019-02-20 14:09:21

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,531
Website

Re: [Solved] Run script when connecting device via bluetooth

d_fajardo wrote:

If I connect the device via bluetooth and execute the script, then the functionality works.

Is that as a normal user or root, and is it from within and X session or from a tty?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#9 2019-02-20 15:43:55

d_fajardo
Member
Registered: 2017-07-28
Posts: 1,568

Re: [Solved] Run script when connecting device via bluetooth

I execute the script as a normal user in X session. I can see that udev probably requires root but I have OWNER="brightchip" in the rule and udevadm doesn't flag any errors when I test.

Offline

#10 2019-02-20 21:24:31

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,531
Website

Re: [Solved] Run script when connecting device via bluetooth

And do you run udevadm from your logged in user under X?

xsetwacom requires an X11 connection.  At very least, you will need to export the proper DISPLAY value into the environment that runs xsetwacom - either in the udev rule, or from within your script.  Depending on your xauthority settings, there may be other requirements as well.

Last edited by Trilby (2019-02-20 21:25:03)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#11 2019-02-20 21:56:23

d_fajardo
Member
Registered: 2017-07-28
Posts: 1,568

Re: [Solved] Run script when connecting device via bluetooth

Yes I do run the script as logged in user under X. Now I don't know how to export the DISPLAY value to either udev or my script. I checked my env and it says DISPLAY=:0 and that's all I know. And regarding xauthority, I don't have any idea what settings I have.

Offline

#12 2019-02-20 22:24:06

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,531
Website

Re: [Solved] Run script when connecting device via bluetooth

d_fajardo wrote:

I don't know how to export the DISPLAY value to ... my script.

You just add it to the script, before any commands requiring it run:

export DISPLAY=:0

Or even better, read the udev wiki page which covers issues just like this discussing DISPLAY, xauthority, and other relevant issues.

Last edited by Trilby (2019-02-20 22:25:35)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#13 2019-02-21 09:45:28

d_fajardo
Member
Registered: 2017-07-28
Posts: 1,568

Re: [Solved] Run script when connecting device via bluetooth

Thanks Trilby. Your leads was really helpful. I also found this quite helpful. I couldn't find much info about udev and Xauthority. In the end what makes things work are just two changes:

Changing my shebang in my script from #!/bin/bash to #!/usr/bin/env bash
Adding export XAUTHORITY=/home/brightchip/.Xauthority

Those two things added and functionality works. No changes to the udev rule.

Thanks again. Now I have a better understanding on how X works.

Edit: Forgot I added export DISPLAY=:0 as well

Last edited by d_fajardo (2019-02-21 11:10:39)

Offline

#14 2019-02-21 09:47:34

d_fajardo
Member
Registered: 2017-07-28
Posts: 1,568

Re: [Solved] Run script when connecting device via bluetooth

If I may add, I would recommend updating the Wacom WiKi to reflect this issue for us not very well versed in X.

Offline

#15 2019-02-21 10:50:24

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [Solved] Run script when connecting device via bluetooth

Go on then. It is a wiki after all...


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#16 2019-02-21 11:18:51

d_fajardo
Member
Registered: 2017-07-28
Posts: 1,568

Re: [Solved] Run script when connecting device via bluetooth

OK I'll have a go...

Offline

Board footer

Powered by FluxBB