Skip to content

Conversation

@mirkoCrobu
Copy link
Contributor

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

  • PR addresses a single concern.
  • PR title and description are properly filled.
  • Changes will be merged in main.
  • Changes are covered by tests.
  • Logging is meaningful in case of troubleshooting.

@mirkoCrobu mirkoCrobu requested review from a team and lucarin91 November 5, 2025 16:14
@mirkoCrobu mirkoCrobu self-assigned this Nov 6, 2025
Copy link
Contributor

@lucarin91 lucarin91 left a 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
Copy link
Contributor Author

How to test it

  1. Create the .deb and push it into the board
    On the board
  2. Be sure that /etc/avahi/services/arduino.service doesn't contain the serial number
  3. Reboot the board
  4. Check /etc/avahi/services/arduino.service: now you should see the serial number
  5. Check that the .flag file exists: ls -l /var/lib/arduino/avahi_serial_configured.flag
  6. Check the service status (should be active (exited)): systemctl status arduino-avahi-serial.service
  7. Enable network mode: arduino-app-cli system network-mode enable
    From your PC
  8. Check the board list configs(you should the network information with serial number:
    ): arduino-cli board list --json

@mirkoCrobu mirkoCrobu requested a review from lucarin91 November 7, 2025 14:27
@@ -0,0 +1,17 @@
[Unit]
Description=Configure Avahi with board serial number
After=avahi-daemon.service
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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


systemctl enable arduino-app-cli
systemctl enable arduino-burn-bootloader
systemctl enable arduino-avahi-serial.service
Copy link
Contributor

@dido18 dido18 Nov 7, 2025

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 ?

Suggested change
systemctl enable arduino-avahi-serial.service
systemctl enable arduino-avahi-serial

Copy link
Contributor

@lucarin91 lucarin91 left a 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

Comment on lines +3 to +6
# 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.
Copy link
Contributor

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

Comment on lines +16 to +17
echo "Warning: Serial number path not found at $SERIAL_NUMBER_PATH. Skipping." >&2
exit 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "Warning: Serial number path not found at $SERIAL_NUMBER_PATH. Skipping." >&2
exit 0
echo "Warning: Serial number path not found at $SERIAL_NUMBER_PATH" >&2
exit 1

Comment on lines +22 to +23
echo "Warning: Target file $TARGET_FILE not found or not writable. Skipping." >&2
exit 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "Warning: Target file $TARGET_FILE not found or not writable. Skipping." >&2
exit 0
echo "Warning: Target file $TARGET_FILE not found or not writable." >&2
exit 1

Comment on lines +29 to +30
echo "Warning: Serial number file is empty. Skipping." >&2
exit 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "Warning: Serial number file is empty. Skipping." >&2
exit 0
echo "Warning: Serial number file is empty." >&2
exit 1

Comment on lines +34 to +35
echo "Serial number ($SERIAL_NUMBER) already configured. Skipping."
exit 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "Serial number ($SERIAL_NUMBER) already configured. Skipping."
exit 0
echo "Serial number ($SERIAL_NUMBER) already configured."
exit 1

exit 0
fi

SERIAL_NUMBER_ESCAPED=$(echo "$SERIAL_NUMBER" | sed -e 's/\\/\\\\/g' -e 's/\//\\\//g' -e 's/\&/\\\&/g')
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
exit 0


systemctl enable arduino-app-cli
systemctl enable arduino-burn-bootloader
systemctl enable arduino-avahi-serial.service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
systemctl enable arduino-avahi-serial.service
systemctl enable arduino-avahi-serial

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants