Using USB vitual comm port without root on host

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
furo
Posts: 6
Joined: Mon Apr 03, 2017 9:20 am

Using USB vitual comm port without root on host

Post by furo » Mon Apr 03, 2017 11:52 am

Hey everyone,

I am new to MicroPython and microcontrollers in general.

I am trying to use MicroPython's virtual comm port class to display some status messages from the Pyboard on the host computer and transfer some files from the board to the host. However, I do not have root access on the host computer.

For Ubuntu I can work around this by setting the usb_mode of the Pyboard to 'VCP+MSC'. This gives me 666 permission for /dev/ttyACM0. To me this seems like an Ubuntu bug. Also, it does not work on other distros (I checked CentOS and Gentoo).

Is there a way to connect to the Pyboard via virtual comm (e.g. using pyserial on the host) without root access on the host computer?

Best,
Flo

PS: I checked out dhylands json-ipc and rshell, but both do not work without root, as the permission is denied to connect to /dev/ttyACM0.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Using USB vitual comm port without root on host

Post by dhylands » Mon Apr 03, 2017 9:17 pm

Under ubuntu, the simplest way to get permissions to the serial ports is to add your user to the dialout group.

Code: Select all

sudo usermod -a -G dialout USERNAME
Replace USERNAME with your ubuntu login username (You can use the whoami command to determine your username.

Alternatively, you can also use some udev rules. The udev rules on this page: https://github.com/micropython/micropyt ... -Discovery should also work for the pyboard.

Be aware that changing the usb_mode may also change the USB PID. The pyboard can have a PID of 9800 for VCP+MSC, 9801 or VCP+HID, or 9802 for VCP only mode.

furo
Posts: 6
Joined: Mon Apr 03, 2017 9:20 am

Re: Using USB vitual comm port without root on host

Post by furo » Tue Apr 04, 2017 7:56 am

I have done both. I added myself to dailout and used the udev rules on my private computer. This indeed resolves all the permission issues.

The intended host, however, is the computer of an MRI scanner. Its system is maintained by the manufacturer, meaning I cannot run any sudo commands.

I also asked about this on superuser(https://superuser.com/questions/1195006 ... oot-access). It seems the only way to avoid the permission issues is to use e.g. Ethernet instead.

As an alternative, I was thinking to use the board in mass storage mode and write a file with output to the sd card and use machine.reset() regularly. Using reset should trigger the auto mount on the host (remounting requires sudo). After auto mount the new file should be visible to the host, and a simple python script running on the host could print its content to the screen.
I know this is an unusual approach and iffy at best.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Using USB vitual comm port without root on host

Post by dhylands » Tue Apr 04, 2017 7:26 pm

That's a problem.

There isn't anything that can be done from the device to give you permissions to use it (at least as a serial device). That requires root access.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Using USB vitual comm port without root on host

Post by pythoncoder » Wed Apr 05, 2017 8:17 am

@furo Using mass storage mode and sharing a data file between the Pyboard and the host PC can lead to problems. USB mass storage mode is not designed for shared file access. You might get away with it if you find a way to guarantee that there is no concurrent access to the file: i.e. the Pyboard closes the file before the PC attempts to access it, and the PC closes it before the Pyboard opens it.

But even that may not ensure reliability.
Peter Hinch
Index to my micropython libraries.

furo
Posts: 6
Joined: Mon Apr 03, 2017 9:20 am

Re: Using USB vitual comm port without root on host

Post by furo » Sun Apr 09, 2017 8:54 pm

Thanks for the replies!

I eventually managed to get the root password and used udev rules to grant the user permission to read and write to the serial device.

This worked without hiccups on the first computer I tried it on (CentOS 7, udev 219). Afterwards I tried it on another computer in our lab running CentOS 5 (udev 095). On this system the udev rules seem to have no effect at all.

Have you encountered similar problems before or do you have any tips on what I could try?

I don't know if this is relevant, but you can find the details of the kernel configurations of the CentOS 5 machine here.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Using USB vitual comm port without root on host

Post by dhylands » Sun Apr 09, 2017 11:37 pm

IIRC, older vesions of udev used SYSFS{idProduct} rather than ATTRS[idProduct} (i.e. used SYSFS rather than ATTRS)

Admin010
Posts: 1
Joined: Thu Apr 27, 2017 11:04 am

Re: Using USB vitual comm port without root on host

Post by Admin010 » Thu Apr 27, 2017 11:06 am

thanks

Post Reply