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.)