Open serial port automatically

Hi everyone!
I'm using the Serial port library on Snap! with the Arduino Uno board.
I would like Chrome not to show me the prompt to connect the board... but just connect the board.
I saw that it should be possible via the Chrome API.
Do you think it is possible to use Snap to act on Chrome and bypass the prompt to request connection to Arduino?

It's designed this way to prevent unattended opening of someone's port.
And to be simple and stateless.

It may be possible but I've never seen that implemented in any block programming language that uses webSerial to connect to a device from a browser.

Just as a matter of interest, what sort of things are you doing with an Arduino and Snap! ?

I'm implementing a code for an exercise with touch sensors.
Basically, when specific points light up on the snap screen, the user must touch those same points on a support with the touch sensors. Arduino reads which sensors have been touched and sends a byte array to snap. Snap checks that the list that comes from Arduino contains the points touched in the same order in which they lit up and, if it is correct, adds a score, otherwise subtracts it.

It works very well but I would like to avoid the user having to act on the Chrome prompt and I would like to automate the Arduino selection on the prompt and the click on Connect.
I found this post on stackoverflow and I was wondering if it was possible to implement something like this on Snap.

@dardoro you are right and I agree with you, it is also a security issue.
In fact I was wondering if there was a way to "tell Chrome" that my USB device is safe and therefore it can connect to it without problems maybe using idVendor and idProduct (?).

It might be worth your time to try out
https://snap4arduino.rocks

and see if that auto connects

this is actually up to date with current Snap!, something most mods arent

yeah, I think its even updated to 10.3.6!

You may authorize and open some/many WEB Serial ports without extra dialog but...

  1. You need a way to "de-authorize" or select another port
  2. Advanced web futures are hidden behind "user gesture" so you can't just open port with "green flag" event, i.e. auto-run from URL

If you can control your environment (modify the client browser or serve modified Snap!) I can post a modified auto-connect procedure.

Ports can be removed with the browser dialog (sorry for the localized UI)


You may test (JS required)
serialEx script pic (7)
to reopen, already authorized and still connected, port [#1].
If there is no port with the given # (e.g. 0) a dialog opens.

@cymplecy I tried but S4A needs a user gesture to confirm Arduino connection, so the problem occurs again

@dardoro I am trying to understand if I can use and modify a Chromium version (not Chrome) to authorize connections without gestures from the user and showing a disclaimer to communicate to the user that he must use Chromium only and exclusively for this type of exercise so as to prevent risks.
About the connection of an already authorized device, I am using the Chrome APIs with this idea and I have created a block of instructions that seems to work.

However, I am interested in your block. How can I test it?

It's modified version of the block from "Web serial" library.
Drag "smart" image into Snap!


Maybe it will work without the user gesture....
Serial': "Must be handling a user gesture", https://github.com/WICG/serial/issues/131 :link:

requestDevice() must always be called with a user gesture. If you are trying to reconnect to a port the user has already granted the site access to you can call getPorts() and open() without a user gesture.

BTW: This subject may be better "served" at Computer Science > Physical Computing category.

I tried it and it seems to work.
Unless I close the browser, the block makes Arduino reconnect to Snap without user gesture.

Mh....maybe the requestPort and requestDevice functions can't be changed so deeply and user confirmation is absolutely necessary.
I'll try to look into this further.

Anyway, thanks @dardoro for your help and your block to.
It will definitely be helpful.