- Notifications
You must be signed in to change notification settings - Fork2
Add Serial Number to Avahi Service for Board Deduplication#48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Conversation
lucarin91 left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I didn't figure out that we needed to add another sudoers file for this feature, which I would avoid to do it. So I think we should change the approach here, and we could instead do that in a systemd unit that is triggered only on the first boot, e.g.,https://github.com/arduino/arduino-app-cli/blob/main/debian/arduino-app-cli/etc/systemd/system/arduino-burn-bootloader.service.
The Serial number of the board should not change, so we can do it just the first time you flash the board, and in there, you have all the permission to patch the Avahi service.
mirkoCrobu commentedNov 7, 2025
How to test it
|
| @@ -0,0 +1,17 @@ | |||
| [Unit] | |||
| Description=Configure Avahi with board serial number | |||
| After=avahi-daemon.service | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I would do it before not after
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I put it "after" to ensure I could find the file "/etc/avahi/services/arduino.service".
Also, we don't need to restart Avahi after modifying the file.
(Btw I change it in "Before")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I put it "after" to ensure I could find the file "/etc/avahi/services/arduino.service".
The file should be always there
Also, we don't need to restart Avahi after modifying the file.
Not sure about that I think it need a restart
| systemctlenable arduino-app-cli | ||
| systemctlenable arduino-burn-bootloader | ||
| systemctlenable arduino-avahi-serial.service |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Is the .service suffix needed ?
| systemctl enable arduino-avahi-serial.service | |
| systemctl enable arduino-avahi-serial |
lucarin91 left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I would also add the disable command in postrm as for the other services
| # Configure Avahi with the serial number. | ||
| # This operation is non-blocking: if it fails, | ||
| # the script will exit with success in order to | ||
| # not to interrupt the post-install process. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think this script should and could fail. If there is an issue, I would prefer that it start the next time instead of never
| echo"Warning: Serial number path not found at$SERIAL_NUMBER_PATH. Skipping.">&2 | ||
| exit 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
| echo"Warning: Serial number path not found at$SERIAL_NUMBER_PATH. Skipping.">&2 | |
| exit0 | |
| echo"Warning: Serial number path not found at$SERIAL_NUMBER_PATH">&2 | |
| exit1 |
| echo"Warning: Target file$TARGET_FILE not found or not writable. Skipping.">&2 | ||
| exit 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
| echo"Warning: Target file$TARGET_FILE not found or not writable. Skipping.">&2 | |
| exit0 | |
| echo"Warning: Target file$TARGET_FILE not found or not writable.">&2 | |
| exit1 |
| echo"Warning: Serial number file is empty. Skipping.">&2 | ||
| exit 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
| echo"Warning: Serial number file is empty. Skipping.">&2 | |
| exit0 | |
| echo"Warning: Serial number file is empty.">&2 | |
| exit1 |
| echo"Serial number ($SERIAL_NUMBER) already configured. Skipping." | ||
| exit 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
| echo"Serial number ($SERIAL_NUMBER) already configured. Skipping." | |
| exit0 | |
| echo"Serial number ($SERIAL_NUMBER) already configured." | |
| exit1 |
| exit 0 | ||
| fi | ||
| SERIAL_NUMBER_ESCAPED=$(echo"$SERIAL_NUMBER"| sed -e's/\\/\\\\/g' -e's/\//\\\//g' -e's/\&/\\\&/g') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
The serial number on the unoq is just a number I don't think you need to escape anything
| sed -i"\#${MARKER_LINE}#i${NEW_LINE}""$TARGET_FILE" | ||
| echo"Avahi configuration attempt finished." | ||
| exit 0 No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
| exit 0 |
| systemctlenable arduino-app-cli | ||
| systemctlenable arduino-burn-bootloader | ||
| systemctlenable arduino-avahi-serial.service |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
nit
| systemctl enable arduino-avahi-serial.service | |
| systemctl enable arduino-avahi-serial |
Motivation
A board connected via both USB and Network currently shows up as two separate devices in the board list. This makes it difficult for a client application to know it is the same physical board.
We need a way to "deduplicate" these entries by providing a common identifier, allowing the client to show just one entry for that board.
Change description
A simple approach is to add the board's serial number to its Avahi service file. This change will be made at runtime when the EnableNetworkMode function is executed.
Specifically, we will add a new containing the serial number (e.g., serial_number=YOUR_SERIAL) to the board's .service file.
Additional Notes
Reviewer checklist
main.