LowPowerLab Forum

Hardware support => Moteino => Topic started by: billchurch on March 10, 2014, 10:03:08 PM

Title: Moteino USB - How to make the /dev path more deterministic in Linux
Post by: billchurch on March 10, 2014, 10:03:08 PM
I'm using the Moteino USB and a Raspberry Pi running Raspbian Linux as my gateway device for some home automation projects.

I plan on having at least one more USB-to-Serial device connected to the Pi and I was worried about being able to determine which /dev/ttyUSB? was the Moteino and which was the other USB Serial device.

Long story short.

udevadm will tell you what you need to make a udev.rules file which will allow you to identify a particular device and create a symlink specifically for it.

Run udevadm on /dev/ttyUSB0 (or whatever device you want to make sticky).

udevadm info -a -p `udevadm info -q path -n /dev/ttyUSB0`
(I'm concatenating two commands here, "udevadm info -q path -n /dev/ttyUSB0" gives me the long path that "udevadm info -a -p" needs.)

It'll report back a BUNCH of information. I'm looking for the details and serial number of my Moteino USB/Serial interface (FT231X USB UART):


...
looking at parent device '/devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3.6':
  KERNELS=="1-1.3.6"
  SUBSYSTEMS=="usb"
  DRIVERS=="usb"
...
  ATTRS{idVendor}=="0403"
...
  ATTRS{serial}=="ABC123"
...
  ATTRS{idProduct}=="6015"
  ATTRS{bDeviceClass}=="00"
  ATTRS{product}=="FT231X USB UART"
...


That data will allow me to make a file (as root) in /etc/udev/rules.d that will contain the criteria I need to make a symbolic link in /dev that will allow me to call out to my specific Moteino reliably every time. The serial number is key here, in theory if I had multiple Moteino's I could make rules for them all, calling out each one by serial number.

I created /etc/udev/rules.d/45-moteino.rules with the following for my specific case:

SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6015", ATTRS{serial}=="ABC123", SYMLINK+="MoteinoGW"

Modified my moteino.js to now reference /dev/MoteinoGW instead of /dev/ttyUSB0 and then did a reboot to make sure everything was working as it should.

Hopefully this helps someone out and thanks again to Felix for some great code and hardware!

(UPDATE: Had a typo in the /etc/udev/rules.d/45-moteino.rules, replaced "UBSYSTEM" with "SUBSYSTEM". Was rebuilding my gateway and realized this typo.)
Title: Re: Moteino USB - How to make the /dev path more deterministic in Linux
Post by: Felix on March 10, 2014, 10:12:04 PM
This is really great stuff, thanks bill!
Title: Re: Moteino USB - How to make the /dev path more deterministic in Linux
Post by: KanyonKris on March 11, 2014, 01:06:08 AM
Nice work, Bill. I'll be sure to use that technique.
Title: Re: Moteino USB - How to make the /dev path more deterministic in Linux
Post by: cootcraig on March 11, 2014, 01:10:14 PM
Quote from: billchurch on March 10, 2014, 10:03:08 PM
I created /etc/udev/rules.d/45-moteino.rules with the following for my specific case:

UBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6015", ATTRS{serial}=="ABC123", SYMLINK+="MoteinoGW"

Modified my moteino.js to now reference /dev/MoteinoGW instead of /dev/ttyUSB0 and then did a reboot to make sure everything was working as it should.

Very nice.  I will use this technique as well.  A question. I don't have my MoteinoUSB
yet. I'm getting experience with a Diavolino Arduino connected with an external
FTDI.  Is the serial attribute tied to the FTDI? Does this make it different for each
MoteinoUSB?

In my case I have an Edimax USB wifi and the FTDI-Arduino plugged in and I'm
digging through the udevadm output.
Title: Re: Moteino USB - How to make the /dev path more deterministic in Linux
Post by: cootcraig on March 11, 2014, 07:21:27 PM
This worked for me.  Thanks again for the tip.

/etc/udev/rules.d/50-usb-serial.rules


SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="AH01PAVO", SYMLINK+="Diavolino"