Unique USB identifier for more stable (solved)

Cool Javelin
Posts: 24
Joined: Wed Oct 20, 2021 3:58 am

Unique USB identifier for more stable (solved)

Postby Cool Javelin » Sat Dec 06, 2025 11:31 pm

Hello:

I need a way to give my ESP8266's (and 32's also I assume) unique names in my /dev folder when I attach them to my USB hub.

PlatformIO wants to upload code to the ESP8266 using the moniker /dev/ttyUSB0 (or /dev/ttyUSBn.) I'm pretty sure if I created a SYMLINK called ESP8266_HomeStat PlatformIO would be happy with that.

Currently, when I attach one esp8266 I see ttyUSB0 show up in the /dev dir, then when I attach a second esp, I get ttyUSB1. This is as expected.

However, when I attach them in a different order the names get reversed, also, as expected.

I am attempting to use /etc/udev/rules.d to make a SYMLINK such that when I attach a device I get a second moniker /dev/ESP8266_HomeStat for example

I tried the following in a file called /etc/udev/rules.d/10-my_8266_homestat.rules ...

Code: Select all

ACTION=="add", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", SYMLINK+="ESP8266_HomeStat"
but the idProduct and idVendor are not enough to differentiate between the 2 devices.

Is there another ATTRS{something or other} I can use?

Failing that, I see in https://www.reactivated.net/writing_udev_rules.html I can launch a script when a device is attached. Is there a way I can use a shell script to get the MAC address from the device and create a unique moniker in my /dev dir?

Thanks, Mark.
Last edited by Cool Javelin on Sat Apr 04, 2026 9:21 pm, edited 1 time in total.

Sprite
Espressif staff
Espressif staff
Posts: 10593
Joined: Thu Nov 26, 2015 4:08 am

Re: Unique USB identifier for more stable

Postby Sprite » Mon Dec 08, 2025 12:38 am

If you're using ESP32 via the built-in USB-serial-JTAG converter, you can distinguish them using their serial. That may or may not work for boards with an external (to the ESP) usb-serial-converter as well, it depends on the chip used. Untested, but something like this should work:

Code: Select all

(plug device in)
sudo dmesg
[82499.953260] usb 3-1: new full-speed USB device number 17 using xhci_hcd
[82500.095042] usb 3-1: New USB device found, idVendor=303a, idProduct=1001, bcdDevice= 1.01
[82500.095053] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[82500.095056] usb 3-1: Product: USB JTAG/serial debug unit
[82500.095059] usb 3-1: Manufacturer: Espressif
[82500.095061] usb 3-1: SerialNumber: 24:EC:4A:09:7B:24 <- pay attention to this line
[82500.100525] cdc_acm 3-1:1.0: ttyACM1: USB ACM device

Add this to your udev rules:
ACTION=="add", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", ATTRS{serial}=="24:EC:4A:09:7B:24", SYMLINK+="ESP8266_HomeStat"

Cool Javelin
Posts: 24
Joined: Wed Oct 20, 2021 3:58 am

Re: Unique USB identifier for more stable (solved)

Postby Cool Javelin » Fri Mar 06, 2026 10:10 pm

To answer my own question...

I have decided there is no way to divine the particular board that is plugged into a USB port. There is simply not enough unique info in the FTDI (or other) chip.

Also, Trying to use the udev rules won't work as calling PROGRAM the USB port hasn't been attached to the kernel yet, so program cant access it, and while RUN can access the USB port, I need some custom software in the IoT device to "query".

Rather, in udev, I can set a symlink to the port based on it's physical location in the hub.

Here is my a file I made called /etc/udev/rules.d/15-my_IOT.rules.

ACTION=="add", SUBSYSTEMS=="usb", KERNELS=="3-4.4.2:1.0", SYMLINK+="ttyUSB_IoT_1"
ACTION=="add", SUBSYSTEMS=="usb", KERNELS=="3-4.4.1:1.0", SYMLINK+="ttyUSB_IoT_2"
ACTION=="add", SUBSYSTEMS=="usb", KERNELS=="3-4.3:1.0", SYMLINK+="ttyUSB_IoT_3"
ACTION=="add", SUBSYSTEMS=="usb", KERNELS=="3-4.2:1.0", SYMLINK+="ttyUSB_IoT_4"
ACTION=="add", SUBSYSTEMS=="usb", KERNELS=="3-4.1:1.0", SYMLINK+="ttyUSB_IoT_5"

By using KERNELS I can uniquely identity which port the cable is plugged into, then I can make a symlink.

Mark

Cool Javelin
Posts: 24
Joined: Wed Oct 20, 2021 3:58 am

Re: Unique USB identifier for more stable (Solved)

Postby Cool Javelin » Fri Mar 06, 2026 10:12 pm

To answer my own question...

I have decided there is no way to divine the particular board that is plugged into a USB port. There is simply not enough unique info in the FTDI (or other) chip.

Also, Trying to use the udev rules won't work as calling PROGRAM the USB port hasn't been attached to the kernel yet, so program cant access it, and while RUN can access the USB port, I need some custom software in the IoT device to "query".

Rather, in udev, I can set a symlink to the port based on it's physical location in the hub.

Here is my a file I made called /etc/udev/rules.d/15-my_IOT.rules.

ACTION=="add", SUBSYSTEMS=="usb", KERNELS=="3-4.4.2:1.0", SYMLINK+="ttyUSB_IoT_1"
ACTION=="add", SUBSYSTEMS=="usb", KERNELS=="3-4.4.1:1.0", SYMLINK+="ttyUSB_IoT_2"
ACTION=="add", SUBSYSTEMS=="usb", KERNELS=="3-4.3:1.0", SYMLINK+="ttyUSB_IoT_3"
ACTION=="add", SUBSYSTEMS=="usb", KERNELS=="3-4.2:1.0", SYMLINK+="ttyUSB_IoT_4"
ACTION=="add", SUBSYSTEMS=="usb", KERNELS=="3-4.1:1.0", SYMLINK+="ttyUSB_IoT_5"

By using KERNELS I can uniquely identity which port the cable is plugged into, then I can make a symlink.

Mark

Who is online

Users browsing this forum: Qwantbot, YisouSpider and 12 guests