Tag: udev

Configure the Telldus Service – Part 1

First stop the service and then create a separate user ‘telldus’ with no login or home directory. The group ‘telldus’ which is connected to the ‘telldus’ user is also created.

/etc/init.d/telldusd stop
adduser --no-create-home --disabled-login --gecos "" telldus

Create the config file of the service daemon: ‘/etc/tellstick.conf’ and add the following two rows:

user = "telldus"
group = "telldus"

Now the service daemon will start up and change process owner to ‘telldus’.

Let’s focus on the tellstick device (in my case the tellstick duo). Connect it to the USB host port of the Raspberry Pi. Verify that it is detected and note the vendor id and product id:

> lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. 
Bus 001 Device 004: ID 1781:0c31 Multiple Vendors Telldus TellStick Duo

The tellstick is detected which is shown at the last row, and vendor id: 1781/product id: 0c31.

The service daemon needs a device handle in /dev to be able to communicate with the device.

Newer kernels contains the udev subsystem handling plugindevices, making it possible to write a rule like: each time this device is plugged in, then create this type of device handle.

The tellstick device uses the FTDI HW component to make it easy to communicate using serial usb. The FTDI device driver is included with the kernel as a loadable device driver. A loadable device driver is possible to load dynamically by running the command ‘modprobe’.

Next step is to write a udev rule which matches the device (vendor id/product id) and runs the modprobe command as well as writing to /sys/bus/usb-serial/drivers/ftdi_sio/new_id to make the device handle appear.

Start by creating the file ’99-ftdi.rules’ in ‘/etc/udev/rules.d’:

ACTION==”add”, ATTRS{idVendor}==”1781″, ATTRS{idProduct}==”0c31″, RUN+=”/sbin/modprobe ftdi_sio” OWNER=”telldus” GROUP=”telldus” RUN+=”/bin/sh -c ‘echo 1781 0c31 > /sys/bus/usb-serial/drivers/ftdi_sio/new_id'”

This rule loads the FTDI driver and creates the device handle ‘/dev/ttyusb0’ owned by telldus.
Restart udev subsystem (making it reread all the the rules):

> udevadm control --reload

Verify that ‘/dev/ttyUSB0’ appears when inserting the tellstick device.

Finally we update the config file ‘/etc/tellstick.conf’ with the following line pointing out the device handle:

deviceNode = "/dev/ttyUSB0"