Skip to content

Instantly share code, notes, and snippets.

@scarytom
Last active December 21, 2015 17:28
Show Gist options
  • Save scarytom/6340185 to your computer and use it in GitHub Desktop.
Save scarytom/6340185 to your computer and use it in GitHub Desktop.
configuring temper sensor for non-root access

detect the device

  • start with the device unplugged
  • run udevadm monitor --udev
  • plug in the device
  • see output in udevadm_monitor.out
  • the device is recognisable on the third to last line as: /dev/usb/hiddev0

find device details

  • run udevadm info --query=all --name=/dev/usb/hiddev0 --attribute-walk
  • get the content in udevadm_info.out
  • find the lowest level idProduct and idVendor

create udev rule for device

  • Create file /etc/udev/rules.d/60-temper.rules (content attached).
  • Create a new temper group sudo groupadd temper
  • Add user to temper group sudo usermod -a -G temper your-username
  • perform various reboot dances, or maybe run sudo udevadm trigger and get away with it

install temperature code

setup crontab

  • crontab -e
  • add */5 * * * * /home/tom/log-temperature.sh
# TEMPer1 USB thermometer
ATTR{idVendor}=="0c45", ATTR{idProduct}=="7401", OWNER="root", GROUP="temper", MODE="0660"
#!/bin/bash
set -e
set -u
TEMPER_EXE="/home/tom/temper/temper"
LOG_DIR="/home/tom/temperature"
LOG_FILE="${LOG_DIR}/$(date -u +%Y%m%d).csv"
"${TEMPER_EXE}" >> "${LOG_FILE}"
$ udevadm info --query=all --name=/dev/usb/hiddev0 --attribute-walk
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:1d.1/usb3/3-1/3-1:1.1/usb/hiddev0':
KERNEL=="hiddev0"
SUBSYSTEM=="usb"
DRIVER==""
looking at parent device '/devices/pci0000:00/0000:00:1d.1/usb3/3-1/3-1:1.1':
KERNELS=="3-1:1.1"
SUBSYSTEMS=="usb"
DRIVERS=="usbhid"
ATTRS{bInterfaceNumber}=="01"
ATTRS{bAlternateSetting}==" 0"
ATTRS{bNumEndpoints}=="01"
ATTRS{bInterfaceClass}=="03"
ATTRS{bInterfaceSubClass}=="01"
ATTRS{bInterfaceProtocol}=="02"
ATTRS{supports_autosuspend}=="1"
looking at parent device '/devices/pci0000:00/0000:00:1d.1/usb3/3-1':
KERNELS=="3-1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{configuration}==""
ATTRS{bNumInterfaces}==" 2"
ATTRS{bConfigurationValue}=="1"
ATTRS{bmAttributes}=="a0"
ATTRS{bMaxPower}=="100mA"
ATTRS{urbnum}=="15"
ATTRS{idVendor}=="0c45"
ATTRS{idProduct}=="7401"
ATTRS{bcdDevice}=="0001"
ATTRS{bDeviceClass}=="00"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bDeviceProtocol}=="00"
ATTRS{bNumConfigurations}=="1"
ATTRS{bMaxPacketSize0}=="8"
ATTRS{speed}=="1.5"
ATTRS{busnum}=="3"
ATTRS{devnum}=="3"
ATTRS{devpath}=="1"
ATTRS{version}==" 2.00"
ATTRS{maxchild}=="0"
ATTRS{quirks}=="0x0"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{authorized}=="1"
ATTRS{manufacturer}=="RDing"
ATTRS{product}=="TEMPerV1.4"
looking at parent device '/devices/pci0000:00/0000:00:1d.1/usb3':
KERNELS=="usb3"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{configuration}==""
ATTRS{bNumInterfaces}==" 1"
ATTRS{bConfigurationValue}=="1"
ATTRS{bmAttributes}=="e0"
ATTRS{bMaxPower}==" 0mA"
ATTRS{urbnum}=="53"
ATTRS{idVendor}=="1d6b"
ATTRS{idProduct}=="0001"
ATTRS{bcdDevice}=="0302"
ATTRS{bDeviceClass}=="09"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bDeviceProtocol}=="00"
ATTRS{bNumConfigurations}=="1"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{speed}=="12"
ATTRS{busnum}=="3"
ATTRS{devnum}=="1"
ATTRS{devpath}=="0"
ATTRS{version}==" 1.10"
ATTRS{maxchild}=="2"
ATTRS{quirks}=="0x0"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{authorized}=="1"
ATTRS{manufacturer}=="Linux 3.2.0-52-generic uhci_hcd"
ATTRS{product}=="UHCI Host Controller"
ATTRS{serial}=="0000:00:1d.1"
ATTRS{authorized_default}=="1"
looking at parent device '/devices/pci0000:00/0000:00:1d.1':
KERNELS=="0000:00:1d.1"
SUBSYSTEMS=="pci"
DRIVERS=="uhci_hcd"
ATTRS{vendor}=="0x8086"
ATTRS{device}=="0x27c9"
ATTRS{subsystem_vendor}=="0x1043"
ATTRS{subsystem_device}=="0x83e7"
ATTRS{class}=="0x0c0300"
ATTRS{irq}=="19"
ATTRS{local_cpus}=="00000000,00000000,00000000,00000000,00000000,00000000,00000000,0000000f"
ATTRS{local_cpulist}=="0-3"
ATTRS{numa_node}=="-1"
ATTRS{dma_mask_bits}=="32"
ATTRS{consistent_dma_mask_bits}=="32"
ATTRS{broken_parity_status}=="0"
ATTRS{msi_bus}==""
looking at parent device '/devices/pci0000:00':
KERNELS=="pci0000:00"
SUBSYSTEMS==""
DRIVERS==""
UDEV [300150.860816] add /devices/pci0000:00/0000:00:1d.1/usb3/3-1 (usb)
UDEV [300150.863093] add /devices/pci0000:00/0000:00:1d.1/usb3/3-1/3-1:1.0 (usb)
UDEV [300150.863995] add /devices/pci0000:00/0000:00:1d.1/usb3/3-1/3-1:1.0/0003:0C45:7401.0003 (hid)
UDEV [300150.879511] add /devices/pci0000:00/0000:00:1d.1/usb3/3-1/3-1:1.0/0003:0C45:7401.0003/hidraw/hidraw0 (hidraw)
UDEV [300150.880081] add /devices/pci0000:00/0000:00:1d.1/usb3/3-1/3-1:1.1 (usb)
UDEV [300150.882305] add /devices/pci0000:00/0000:00:1d.1/usb3/3-1/3-1:1.1/0003:0C45:7401.0004 (hid)
UDEV [300150.886042] add /devices/pci0000:00/0000:00:1d.1/usb3/3-1/3-1:1.0/input/input6 (input)
UDEV [300150.889023] add /devices/pci0000:00/0000:00:1d.1/usb3/3-1/3-1:1.0/input/input6/event2 (input)
UDEV [300150.893953] add /devices/pci0000:00/0000:00:1d.1/usb3/3-1/3-1:1.1/usb/hiddev0 (usb)
UDEV [300150.894028] add /class/usb (class)
UDEV [300150.894256] add /devices/pci0000:00/0000:00:1d.1/usb3/3-1/3-1:1.1/0003:0C45:7401.0004/hidraw/hidraw1 (hidraw)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment