1

Fixed USB /dev/name for USB Micro Teleinfo device

Today I received a mail from a user who asked me how to fix /dev/ttyUSBx  /dev/ttyACMx name for Micro Teleinfo devices. This make sense because on linux, ordering number can sometime be different if you have multiple USB Serial device connected (whatever chip in it such as FTDI, PL2303, CP2302, CH340, CH341, …)

Linux USB/Serial called ttyUSBx or ttyACMx

The first detected device will be named /dev/ttyUSB0 , the 2nd /dev/ttyUSB1  and so on. But you can’t be sure  that this order will be the same on each boot. The only thing that is sure is that if you have only one, it will be called each boot /dev/ttyUSB0 (or /dev/ttyACM0) which works for majority of you. Here I will present a method to prevent this and more have a named device to be more precise. What about having USB Serial holding teleinfo named /dev/teleinfo  or a Arduino named /dev/arduino  or /dev/nano  ?

How to fix this?

It’s quite simple, in fact, just follow this tutorial based on Linux udev deamon that does all the dirty job. Note that this tutorial is done on a Raspberry PI V2 with debian Wheezy on it. I can see using lsb_release . If it’s not installed use this command to install it

sudo apt-get install lsb_release

If you have another version such latest Jessie and there are some differences, please let me know so I can update this post.

And here is my config:

root@pi01(rw):~# lsb_release -da
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 7.8 (wheezy)
Release: 7.8
Codename: wheezy
root@pi01(rw):~#

Connect Micro Teleinfo USB device

Now I’ve connected 2 Micro Teleinfo devices and I can see the USB device #5 and #6, with ID 0403:005 with /dev/ttyUSB0 and /dev/ttyUSB1

root@pi01(rw):~# lsusb
Bus 001 Device 002: ID 0424:9514 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 006: ID 0403:6015 Future Technology Devices International, Ltd Bridge(I2C/SPI/UART/FIFO)
Bus 001 Device 004: ID 148f:3070 Ralink Technology, Corp. RT2870/RT3070 Wireless Adapter
Bus 001 Device 005: ID 0403:6015 Future Technology Devices International, Ltd Bridge(I2C/SPI/UART/FIFO)
root@pi01(rw):~# ls /dev/ttyU*
/dev/ttyUSB0  /dev/ttyUSB1
root@pi01(rw):~#

Identify device Serial Number

Now let’s go deep into device Serial number identification, each Micro Teleinfo board has it own serial number that I put in when I test the boards.

Let’s look at the serial numbers with udevadm walking and grabbing serial number

root@pi01(rw):~#  udevadm info --attribute-walk -n /dev/ttyUSB0  |grep serial
    SUBSYSTEMS=="usb-serial"
    ATTRS{serial}=="TINFO-144"
    ATTRS{serial}=="3f980000.usb"
root@pi01(rw):~#  udevadm info --attribute-walk -n /dev/ttyUSB1  |grep serial
    SUBSYSTEMS=="usb-serial"
    ATTRS{serial}=="TINFO-142"
    ATTRS{serial}=="3f980000.usb"
root@pi01(rw):~#

Ok, has you can see, /dev/ttyUSB0  has serial number  TINFO-144  and /dev/ttyUSB1  serial number TINFO-142

Let’s imagine you connected the device TINFO-144 to your Teleinfo Solar PV (your production counter) and TINFO-142 connected to your ErDF counter (the one you pay to your provider for your consumption) and want to have the PV production called /dev/teleinfo_pv  and the other /dev/teleinfo_erdf

Use udev rules to the rescue

We just need to create a file for udev deamon in /etc/udev/rules.d  folder. I called this one 88-usb-serial.rules

Here is the complete file  :

# /etc/udev/rules.d/88-usb-serial.rules

# FTDI USB-SERIAL
SUBSYSTEM=="tty", ATTRS{serial}=="TINFO-144", SYMLINK+="teleinfo_pv", MODE="0777"
SUBSYSTEM=="tty", ATTRS{serial}=="TINFO-142", SYMLINK+="teleinfo", MODE="0777"

Don’t forget to change file to reflect your serial numbers. The MODE=”0777″ is not mandatory, it’s just to set all rights to everyone to the devices.

The first time, so now because you just created the file, you need to reboot the Pi and here are the results after reboot :

root@pi01(rw):~# l /dev/tele*
lrwxrwxrwx 1 root root 7 Feb  5 23:14 /dev/teleinfo -> ttyUSB0
lrwxrwxrwx 1 root root 7 Feb  5 23:14 /dev/teleinfo_pv -> ttyUSB1
root@pi01(rw):~#

As you can see, a symbolic link as been added to the correct /dev/ttyUSB  and as the usb number can change, the link will always be mapped to the correct one.

Once rebooted, for the the other time, if you want to add new devices, you just need to change the 88-usb-serial.rules file and issue these two commands :

This one to reload rules

udevadm control –reload-rules 

and the 2nd to enumerate again all devices

udevadm trigger

Note that prolific devices don’t seem to have a serial number so a good way to identify them is to add the DRIVERS in the file as follow :
SUBSYSTEM==”tty”, DRIVERS==”pl2303″, SYMLINK+=”ttyUSBpl”

Hope you like this tip, and don’t forget, you can use this method for any other device.

Charles

You can discuss about this article or other project using the community forum