Need help with the board list watch functionality via gRPC

Hi :wave:

I need help with the board list watch functionality via gRPC.

If I set the interrupt to true, my client does not receive list watch responses from the daemon, which is good, but the daemon still tracks the board changes. Is this correct? Am I using the preferred way to interrupt the watch?

Board list watch starts, Uno (replica) board is attached/removed/attached/.etc:

3 CALLED: /cc.arduino.cli.commands.v1.ArduinoCoreService/BoardListWatch STREAM_REQ STREAM_RESP
3 |  REQ:  {
3 |    "instance": {
3 |      "id": 1
3 |    }
3 |  }
{"level":"info","msg":"starting discovery builtin:mdns-discovery process","time":"2022-11-12T13:42:36+01:00"}
{"level":"info","msg":"starting discovery builtin:serial-discovery process","time":"2022-11-12T13:42:36+01:00"}
{"level":"info","msg":"started discovery builtin:serial-discovery process","time":"2022-11-12T13:42:36+01:00"}
{"level":"info","msg":"sending command HELLO 1 \"arduino-cli 0.28.0\" to discovery builtin:serial-discovery","time":"2022-11-12T13:42:36+01:00"}
{"level":"info","msg":"started discovery builtin:mdns-discovery process","time":"2022-11-12T13:42:36+01:00"}
{"level":"info","msg":"sending command HELLO 1 \"arduino-cli 0.28.0\" to discovery builtin:mdns-discovery","time":"2022-11-12T13:42:36+01:00"}
{"level":"info","msg":"from discovery builtin:serial-discovery received message type: hello, message: OK, protocol version: 1","time":"2022-11-12T13:42:36+01:00"}
{"level":"info","msg":"sending command START_SYNC to discovery builtin:serial-discovery","time":"2022-11-12T13:42:36+01:00"}
{"level":"info","msg":"from discovery builtin:serial-discovery received message type: start_sync, message: OK","time":"2022-11-12T13:42:36+01:00"}
{"level":"info","msg":"from discovery builtin:serial-discovery received message type: add, port: /dev/cu.Bluetooth-Incoming-Port","time":"2022-11-12T13:42:36+01:00"}
{"level":"info","msg":"from discovery builtin:mdns-discovery received message type: hello, message: OK, protocol version: 1","time":"2022-11-12T13:42:36+01:00"}
{"level":"info","msg":"sending command START_SYNC to discovery builtin:mdns-discovery","time":"2022-11-12T13:42:36+01:00"}
{"level":"info","msg":"from discovery builtin:mdns-discovery received message type: start_sync, message: OK","time":"2022-11-12T13:42:36+01:00"}
3 |  RESP: {
3 |    "event_type": "add",
3 |    "port": {
3 |      "port": {
3 |        "address": "/dev/cu.Bluetooth-Incoming-Port",
3 |        "label": "/dev/cu.Bluetooth-Incoming-Port",
3 |        "protocol": "serial",
3 |        "protocol_label": "Serial Port"
3 |      }
3 |    }
3 |  }
{"level":"info","msg":"from discovery builtin:serial-discovery received message type: add, port: /dev/cu.usbmodem14101","time":"2022-11-12T13:42:42+01:00"}
3 |  RESP: {
3 |    "event_type": "add",
3 |    "port": {
3 |      "matching_boards": [
3 |        {
3 |          "name": "Arduino Uno",
3 |          "fqbn": "arduino:avr:uno"
3 |        }
3 |      ],
3 |      "port": {
3 |        "address": "/dev/cu.usbmodem14101",
3 |        "label": "/dev/cu.usbmodem14101",
3 |        "protocol": "serial",
3 |        "protocol_label": "Serial Port (USB)",
3 |        "properties": {
3 |          "pid": "0x0043",
3 |          "serialNumber": "75830303934351618212",
3 |          "vid": "0x2341"
3 |        }
3 |      }
3 |    }
3 |  }
{"level":"info","msg":"from discovery builtin:serial-discovery received message type: remove, port: /dev/cu.usbmodem14101","time":"2022-11-12T13:42:44+01:00"}
3 |  RESP: {
3 |    "event_type": "remove",
3 |    "port": {
3 |      "port": {
3 |        "address": "/dev/cu.usbmodem14101",
3 |        "protocol": "serial"
3 |      }
3 |    }
3 |  }
{"level":"info","msg":"from discovery builtin:serial-discovery received message type: add, port: /dev/cu.usbmodem14101","time":"2022-11-12T13:42:44+01:00"}
3 |  RESP: {
3 |    "event_type": "add",
3 |    "port": {
3 |      "matching_boards": [
3 |        {
3 |          "name": "Arduino Uno",
3 |          "fqbn": "arduino:avr:uno"
3 |        }
3 |      ],
3 |      "port": {
3 |        "address": "/dev/cu.usbmodem14101",
3 |        "label": "/dev/cu.usbmodem14101",
3 |        "protocol": "serial",
3 |        "protocol_label": "Serial Port (USB)",
3 |        "properties": {
3 |          "pid": "0x0043",
3 |          "serialNumber": "75830303934351618212",
3 |          "vid": "0x2341"
3 |        }
3 |      }
3 |    }
3 |  }
{"level":"info","msg":"from discovery builtin:serial-discovery received message type: remove, port: /dev/cu.usbmodem14101","time":"2022-11-12T13:42:46+01:00"}
3 |  RESP: {
3 |    "event_type": "remove",
3 |    "port": {
3 |      "port": {
3 |        "address": "/dev/cu.usbmodem14101",
3 |        "protocol": "serial"
3 |      }
3 |    }
3 |  }
{"level":"info","msg":"from discovery builtin:serial-discovery received message type: add, port: /dev/cu.usbmodem14101","time":"2022-11-12T13:42:47+01:00"}
3 |  RESP: {
3 |    "event_type": "add",
3 |    "port": {
3 |      "matching_boards": [
3 |        {
3 |          "name": "Arduino Uno",
3 |          "fqbn": "arduino:avr:uno"
3 |        }
3 |      ],
3 |      "port": {
3 |        "address": "/dev/cu.usbmodem14101",
3 |        "label": "/dev/cu.usbmodem14101",
3 |        "protocol": "serial",
3 |        "protocol_label": "Serial Port (USB)",
3 |        "properties": {
3 |          "pid": "0x0043",
3 |          "serialNumber": "75830303934351618212",
3 |          "vid": "0x2341"
3 |        }
3 |      }
3 |    }
3 |  }
{"level":"info","msg":"from discovery builtin:serial-discovery received message type: remove, port: /dev/cu.usbmodem14101","time":"2022-11-12T13:42:49+01:00"}
3 |  RESP: {
3 |    "event_type": "remove",
3 |    "port": {
3 |      "port": {
3 |        "address": "/dev/cu.usbmodem14101",
3 |        "protocol": "serial"
3 |      }
3 |    }
3 |  }
{"level":"info","msg":"from discovery builtin:serial-discovery received message type: add, port: /dev/cu.usbmodem14101","time":"2022-11-12T13:42:54+01:00"}
3 |  RESP: {
3 |    "event_type": "add",
3 |    "port": {
3 |      "matching_boards": [
3 |        {
3 |          "name": "Arduino Uno",
3 |          "fqbn": "arduino:avr:uno"
3 |        }
3 |      ],
3 |      "port": {
3 |        "address": "/dev/cu.usbmodem14101",
3 |        "label": "/dev/cu.usbmodem14101",
3 |        "protocol": "serial",
3 |        "protocol_label": "Serial Port (USB)",
3 |        "properties": {
3 |          "pid": "0x0043",
3 |          "serialNumber": "75830303934351618212",
3 |          "vid": "0x2341"
3 |        }
3 |      }
3 |    }
3 |  }
3 |  REQ:  {
3 |    "instance": {
3 |      "id": 1
3 |    },
3 |    "interrupt": true
3 |  }

My code sends an interrupt after 20 sec. It's correctly received. :point_up_2: and :point_down: :

{"level":"info","msg":"boards watcher interrupted by client","time":"2022-11-12T13:42:56+01:00"}
3 STREAM CLOSED

The daemon still logs if I plug in and remove the board:

{"level":"info","msg":"from discovery builtin:serial-discovery received message type: remove, port: /dev/cu.usbmodem14101","time":"2022-11-12T13:43:00+01:00"}
{"level":"info","msg":"from discovery builtin:serial-discovery received message type: add, port: /dev/cu.usbmodem14101","time":"2022-11-12T13:43:02+01:00"}
{"level":"info","msg":"from discovery builtin:serial-discovery received message type: remove, port: /dev/cu.usbmodem14101","time":"2022-11-12T13:43:04+01:00"}
{"level":"info","msg":"from discovery builtin:serial-discovery received message type: add, port: /dev/cu.usbmodem14101","time":"2022-11-12T13:43:07+01:00"}
{"level":"info","msg":"from discovery builtin:serial-discovery received message type: remove, port: /dev/cu.usbmodem14101","time":"2022-11-12T13:43:08+01:00"}

If I do not explicitly start the watch, the CLI daemon contains no discovery log items.

Thank you!

Hi @dankeboy36. Very cool that you are using the Arduino CLI gRPC interface!

Here is my understanding of this subject:

When you send any request that requires discovery (BoardList, BoardListWatch), Arduino CLI starts the discovery tools (if they are not already started).

Even after the request has been completed, the discovery tools are left running. The reason for this is the discovery tool processes are intended to be shared between all Arduino CLI instances. Even if one instance is no longer using them, it doesn't know whether another instance might still be using them.

The log output is simply echoing the information Arduino CLI receives from the tools. Arduino CLI always uses these tools in START_SYNC mode, so the tools send a message to Arduino CLI every time an event occurs.

Even though the wording of the documentation implies otherwise

interrupt bool Set this to true to stop the discovery process

the interrupt field of the BoardListWatch only determines whether Arduino CLI creates response data for those events.

I don't know why it was designed that way. I assumed BoardList was based on the LIST command, BoardListWatch based on the START_SYNC command, and the discovery tools were in STOP mode whenever Arduino CLI was not using them.


Is this log output causing you some problem?

Thank you for your great support! All clear now.

I did not have any errors, all works well.

I'm glad if I was able to be of assistance.

About this:

I asked about this and learned the reason is that it can take a significant amount to get a list of ports using a START+LIST+STOP approach. The solution found to obtain the port list quickly was to leave the discovery tools in the START_SYNC mode.

I also learned that the "interrupt": true request was found to not be very useful because the same could be accomplished by simply closing the streaming request. So the presence of this field in the BoardListWatch request message probably serves no purpose and only makes the interface more confusing.

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