# USB COM port number assignment

**URL:** https://discourse.nodered.org/t/usb-com-port-number-assignment/92192
**Category:** General
**Created:** [6 October 2024 09:31 UTC](https://discourse.nodered.org/t/usb-com-port-number-assignment/92192 "2024-10-06T09:31:42Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![MichaelBreytenbach](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@MichaelBreytenbach](https://discourse.nodered.org/u/MichaelBreytenbach)
#### Post date: [6 October 2024 09:31 UTC](https://discourse.nodered.org/t/usb-com-port-number-assignment/92192/1 "2024-10-06T09:31:42Z")

</div>

I have several arduinos connected via USB COM ports to a Pi running node-red.  
The arduinos send and receive JSON strings to node-red.  
The assigned com port numbers are not guaranteed to remain the same on reboot.  
I know there are ways to use PID and VID to identiy devices, but this does not help if arduinos are identical, and especially if arduinos are replaced/ swopped out in the field.  
The only way i can think of is to use a tag in the JSON strings to “memorise” which arduino is on which port. Am i missing something?

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [6 October 2024 10:03 UTC](https://discourse.nodered.org/t/usb-com-port-number-assignment/92192/2 "2024-10-06T10:03:06Z")

</div>

Welcome to the forums @MichaelBreytenbach

I don't do arduino, but is this a true serial connection?  
if so - rules state `serial-by-id` should be using the devices serial number, to represent the serial port.

Example, I use `serial-by-id` to make sure im connecting to the correct device.  
and this make no difference if the "normal" port name (dev/tty\*) changes - `serial-by-id` doesnt

```auto
/dev/serial/by-id/usb-0658_0200_E4051402-4A02-010A-1834-041400A6BE70-if00

```

You can then, match the arduino by its Serial ID

This becomes untrue however, when the devices are a cheap clone, and the manufacturer not creating a unique serial number.

---

<div class="post-metadata">

### Author: ![MichaelBreytenbach](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@MichaelBreytenbach](https://discourse.nodered.org/u/MichaelBreytenbach)
#### Post date: [6 October 2024 17:36 UTC](https://discourse.nodered.org/t/usb-com-port-number-assignment/92192/3 "2024-10-06T17:36:25Z")

</div>

Marcus, that requires updating the unique serial number every time a faulty arduino in the field is replaced.  
I guess i am anwering my own question. The only way to keep system tolerent of changes to harware is in the software.  
Has anyone out there ever made a flow that “remembers” which serial node belongs to which port?

---

<div class="post-metadata">

### Author: ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)
#### Post date: [6 October 2024 18:27 UTC](https://discourse.nodered.org/t/usb-com-port-number-assignment/92192/4 "2024-10-06T18:27:40Z")

</div>

> [@MichaelBreytenbach](#):
>
> Marcus, that requires updating the unique serial number every time a faulty arduino in the field is replaced.

Surely you only need the serial port ID of the PI that the Arduinos are connecting to?

> [@MichaelBreytenbach](#):
>
> I have several arduinos connected via USB COM ports to a Pi running node-red.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [6 October 2024 19:26 UTC](https://discourse.nodered.org/t/usb-com-port-number-assignment/92192/5 "2024-10-06T19:26:46Z")

</div>

> [@ghayne](#):
>
> Surely you only need the serial port ID of the PI that the Arduinos are connecting to?

Unfortunately, with USB, the serial ports are not intrinsically identifiable. The same device may connect as usbTTY0 one time and usbTTY1 the next time.

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [6 October 2024 19:34 UTC](https://discourse.nodered.org/t/usb-com-port-number-assignment/92192/6 "2024-10-06T19:34:10Z")

</div>

Yup,

It’s why I use serial-by-id.

Providing the manufacturer of the device being connected plays nicely and is reputable, will usually be unique and constant every time.

---

<div class="post-metadata">

### Author: ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)
#### Post date: [6 October 2024 19:45 UTC](https://discourse.nodered.org/t/usb-com-port-number-assignment/92192/7 "2024-10-06T19:45:15Z")

</div>

But you can write udev rules that will add a symlink for a serial device based on which physical port it is connected to.

So as long as you always plug the replacement device into the same socket it will get the right simlink.

> <https://unix.stackexchange.com/questions/443250/udev-rule-to-alias-device-depending-on-usb-port-number>

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [6 October 2024 20:39 UTC](https://discourse.nodered.org/t/usb-com-port-number-assignment/92192/8 "2024-10-06T20:39:00Z")

</div>

> [@hardillb](#):
>
> But you can write udev rules that will add a symlink for a serial device based on which physical port it is connected to.

Yes, but usually that is not required. by-id will do it without messing with rules. Also udev rules do not solve the OP's problem that he wants to be able to swap the Arduino out with a new one in the case of failure, without changing the server.

---

<div class="post-metadata">

### Author: ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)
#### Post date: [6 October 2024 20:57 UTC](https://discourse.nodered.org/t/usb-com-port-number-assignment/92192/9 "2024-10-06T20:57:25Z")

</div>

But it would solve the OPs problem, as long as they plugged the replacement device in the same physical socket.

I've used this to identify really **cheap** USB Serial adaptors that all had a same id,

---

<div class="post-metadata">

### Author: ![MichaelBreytenbach](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@MichaelBreytenbach](https://discourse.nodered.org/u/MichaelBreytenbach)
#### Post date: [7 October 2024 05:39 UTC](https://discourse.nodered.org/t/usb-com-port-number-assignment/92192/10 "2024-10-07T05:39:39Z")

</div>

Hardillb, i will defintely try your suggestion of using the same physical sockets for each arduino.  
I was not aware that the 4 usb sockets on the Pi can be distinguished from one another.  
Thanks everyone.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [7 October 2024 08:55 UTC](https://discourse.nodered.org/t/usb-com-port-number-assignment/92192/11 "2024-10-07T08:55:38Z")

</div>

> [@hardillb](#):
>
> But it would solve the OPs problem, as long as they plugged the replacement device in the same physical socket.

Oh yes, I had forgotten that you could identify the socket.  
@MichaelBreytenbach this link may be helpful. [How To Write Udev Rules | Hackaday](https://hackaday.com/2009/09/18/how-to-write-udev-rules/)  
If you plug them both in then, assuming they are /dev/ttyUSB0 and 1 then run  
`udevadm info -a -p $(udevadm info -q path -n /dev/ttyUSB0)`  
and the same for ttyUSB1, then you can look for the differences to see what you can use in the rule to identify them.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [21 October 2024 08:56 UTC](https://discourse.nodered.org/t/usb-com-port-number-assignment/92192/12 "2024-10-21T08:56:00Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
