USB aliases – Multiple USB to UART devices on OpenWRT

dev
If you want to add multiple Arduino or other USB to UART devices to your Openwrt router you will need to symlink them so that the devices don’t mix up while the router reboots.

Our objective is to symlink /dev/ttyUSB0, /dev/ttyUSB1 … to /dev/device0, /dev/device1… In our example we will use a setup with an USB 2.0 hub, and an Arduino. USB 2.0 hub solves a bug in the usb 1.0 connection between the arduino and OpenWRT.
First we need to find out idVendor,idProduct and bcdDevice for each connected device, we can do that with “lsusb -v”:

idVendor 0x0403 Future Technology Devices International, Ltd
idProduct 0x6001 FT232 USB-Serial (UART) IC
bcdDevice 6.00

The first zeros are ignored and we use:

PRODID=”403/6001/600″

And this is the whole script:

PRODID=”403/6001/600″
SYMLINK=”arduino”

if [ “${PRODUCT}” = “${PRODID}” ];
then if [ “${ACTION}” = “add” ];
then
DEVICE_NAME=$(ls /sys/$DEVPATH | grep tty)
if [ -z ${DEVICE_NAME} ];
then logger -t Hotplug Warning DEVICE_NAME is empty
exit

fi
logger -t Hotplug Device name of cp210 is $DEVICE_NAME
ln -s /dev/$DEVICE_NAME /dev/${SYMLINK}
logger -t Hotplug Symlink from /dev/$DEVICE_NAME to /dev/${SYMLINK} created
fi

fi
if [ “${PRODUCT}” = “${PRODID}” ];
then if [ “${ACTION}” = “remove” ];
then rm /dev/${SYMLINK}
logger -t Hotplug Symlink /dev/${SYMLINK} removed
fi

fi

You need to save the scripts under /etc/hotplug.d/usb/. Script names dictate the execution order so name them in this way: 20-arduino1 30-digitemp…

there is one more thing you need to enable executing the scripts: In /etc/hotplug2.rules, remove ‘^’ before ^usb$ and restart the router:

vi /etc/hotplug2.rules

$include /etc/hotplug2-common.rules

SUBSYSTEM ~~ (^net$|^input$|^button$|usb$|^ieee1394$|^block$|^atm$|^zaptel$|^tty$) {
exec /sbin/hotplug-call %SUBSYSTEM%
}

DEVICENAME == watchdog {
exec /sbin/watchdog -t 5 /dev/watchdog
next-event
}

reboot&exit

And now you should have /dev/arduino ready for use!

4 thoughts on “USB aliases – Multiple USB to UART devices on OpenWRT

  1. Hi i am new to openwrt i dont know anything about it even after getting surfed in net please some one teach me ….i am a embedded c developer bt fresher….

    helipng minds always appriciated.

    • Hey, You have list of supported devices on https://wiki.openwrt.org/toh/start.
      We like to use OpenWrt with tplink tl-wr 703n, the router GL.inet is a chinese version of the same router but with easy to use gpio and serial pins on the PCB. Check out the project you can do with 703n somewhere on this page https://wiki.openwrt.org/toh/tp-link/tl-wr703n?s%5B%5D=703n.

      Also you’l need a USB-TTL uart adapter: ebay.to/1Ld8hWN this one will do.

      So If you buy a 703n from China it will arive with chinese firmware language but the hyperlinks are in English. Download the latest firmware from downloads.openwrt.org by searching for your router and upload it as if it were a original firmware. Now you can connect over ethernet, set your ip to static, 192.168.1.2 and you’ll have access to telnet on 192.168.1.1 or luci interface on same address via browser. There are many details to it, so follow the wiki and feel free to ask on OpenWrt forum or brna@@tkdwn.org.

  2. Hey! I am trying to do this same exact thing but am not having any luck. Before I started there was no file /etc/hotplug2.rules but I made one and removed the ‘^’. Still not having any luck. Do you happen to know where the ‘logger’ command logs it outputs? I am not seeing anything from the logger command in the system or kernel log. It seems like hotplug is not even using my scripts.

Leave a Reply

Your email address will not be published. Required fields are marked *