Arduino-cli monitor failing with operation not permitted

Running $ arduino-cli monitor -p /dev/ttyUSB0 --config baudrate=74880

fails with this output:

Monitor port settings:
baudrate=74880
Port monitor error: listen tcp 127.0.0.1:0: listen: operation not permitted

I'm not sure how to debug this, can anyone help me out?

Hi @juchemz. Arduino CLI has a flexible "pluggable monitor" system that allows possibility for the arduino-cli monitor command to be used with any arbitrary communication channel and protocol between the computer and an Arduino board (e.g., BLE, CAN bus) rather than making the command specific to communication over serial ports.

The way that is done is by putting all protocol-specific implementation in a separate "pluggable monitor tool" which is controlled by Arduino CLI using a set of standardized commands.

The monitor data must be transferred between Arduino CLI and the monitor tools efficiently. This is done via an internal TCP/IP port in your computer on "localhost". For some reason, your computer is not allowing that communication between the tools through localhost.

These failures are usually found to be caused by "external" interference or misconfiguration. By "external", I mean that it is something separate from Arduino CLI and pluggable monitor tools and their configuration. Examples would be your antivirus software, firewall, network configuration including the use of a proxy or VPN.

Is there anything notable about your system that might be relevant?

@ptillisch No, I can't think of anything notable, I am on a standard Ubuntu 20.04 installation.

I do find it strange that the cli seems to be trying to connect on port 0. Do you know if that is correct?

If you don't have any other ideas, maybe you could provide instructions for running and interacting with the pluggable monitor tool standalone?

The "operation not permitted" error when using the arduino-cli monitor command typically indicates a permission issue, and it usually occurs when trying to access a serial port on your computer. To resolve this issue, you can take the following steps:

  1. Run Command as Administrator/Superuser (Windows/Linux):
  • If you're using a Windows or Linux machine, try running the arduino-cli monitor command with administrator or superuser privileges. On Windows, right-click on the command prompt and choose "Run as administrator." On Linux, use the sudo command.
  1. Add User to Dialout (Linux):
  • On Linux, you might need to add your user to the "dialout" group to access serial ports. You can do this using the following command:
sudo usermod -a -G dialout yourusername

Replace "yourusername" with your actual username. After adding your user to the "dialout" group, you might need to log out and log back in for the changes to take effect.
3. Install Drivers (Windows):

  • For some Arduino-compatible boards on Windows, you may need to install drivers to enable access to the COM port. Check the manufacturer's website for driver downloads and installation instructions for your specific board.
  1. Check Serial Port and Board Selection:
  • Ensure that you've selected the correct serial port and board type when running the arduino-cli monitor command. Use the arduino-cli board list command to list the available boards and their associated serial ports.
  1. Close Other Serial Monitor Programs:
  • Make sure no other programs or terminals are using the serial port you are trying to monitor with the arduino-cli. Some other programs, like the Arduino IDE's built-in Serial Monitor, may have the port open and prevent arduino-cli from accessing it.
  1. Reboot Your Computer:
  • Sometimes, a reboot can resolve serial port access issues by releasing any locked resources.
  1. Check Port Permissions (Linux):
  • If you are using a Linux-based system, you can check the permissions of the serial port device files in the /dev/ directory. You may need to adjust the permissions or ownership of the serial port you are trying to access.
  1. Verify Proper Installation of Arduino CLI:
  • Ensure that you have correctly installed the Arduino CLI and that it's up to date. If not, consider reinstalling it from the official Arduino website or repository.
  1. Check for udev Rules (Linux):
  • On Linux, it's common to set up udev rules to manage permissions for serial devices. Ensure that your udev rules are correctly configured to grant your user access to the serial port.

If you've tried these steps and are still experiencing the "operation not permitted" error when using arduino-cli monitor, it might be helpful to provide additional details about your setup, such as your operating system and the specific Arduino-compatible board you are using, to receive more targeted assistance.