RIOT icon indicating copy to clipboard operation
RIOT copied to clipboard

Add support for WebUSB

Open pathnirvana opened this issue 4 years ago • 14 comments

Description

connecting a dev board to a computer and be able to configure the app via javascript (nodejs or website) is very attractive to beginners. I am not sure if it is technically possible to add webusb to riot nor such a feature matches with the philosopy of this project. If not feel free to close this issue.

Useful links

Zephyr demo app https://docs.zephyrproject.org/latest/samples/subsys/usb/webusb/README.html

pathnirvana avatar Sep 09 '21 16:09 pathnirvana

This should be well within what's possible with the current USB stack, and primarily a matter of setting the right descriptors.

My gut feeling is that this will even be more effort on the browser side (to get a WebUSB demo application to run with it) than on the RIOT side.

chrysn avatar Sep 13 '21 06:09 chrysn

There are many web demos written in JS that can connect to devices already. It is pretty straightforward on the browser side. Actually at the moment I have webusb from tinyusb running on my blackpill401 and connecting to the chrome browser.

pathnirvana avatar Sep 13 '21 07:09 pathnirvana

Is there a particular demo application you'd suggest for whoever'd start implementing this? Zephyr points to https://github.com/finikorg/webusb-sample, is that a good demo?

chrysn avatar Sep 13 '21 07:09 chrysn

Yes it is a good demo. Also the TinyUSB demo https://example.tinyusb.org/webusb-serial/ They both do the same thing, send something to the mcu and mcu echoes it back to the browser.

pathnirvana avatar Sep 13 '21 07:09 pathnirvana

I won't have time to work on this right now, but expecting it to be straightforward enough, I've marked this as "good first issue", and offer to help with questions arising if you (or any other novice contributor) want to give it a try.

chrysn avatar Sep 13 '21 07:09 chrysn

I myself am a web developer who got interested in the embedded recently. I would be happy to help on the JS front to write a demo app if needed.

pathnirvana avatar Sep 13 '21 07:09 pathnirvana

Having looked around a bit, there are applications for DFU and serial as you linked, along with a lot of custom ones. Do you happen to know if anyone has ventured into implementing the host side of CDC-ECM (USB Ethernet) on the Javascript / WASM side?

(That could make this a useful thing for setting up security in RIOT based systems even when the user does not have root access on the host; CDC-ACM aka serial might work too but that'd mean that the embedded device would need two separate services).

chrysn avatar Sep 13 '21 08:09 chrysn

From what I understand about USB ethernet, it is not something specific to JS unlike webusb. Usb Ethernet needs a driver for windows. Then the device can be accessed through ethernet using any programming language including JS. I haven't seen any demos those.

pathnirvana avatar Sep 13 '21 10:09 pathnirvana

What I meant was that given there are implementations of USB Serial in JavaScript, there could also be an implementation of Ethernet in JavaScript. And like USB Serial over JavaScript should work immaterial of whether the OS deals with serial devices well, doing USB Ethernet in JavaScript could allow some limited use of USB Ethernet devices on Windows or other badly configured systems. (It wouldn't route out, but a typical demo application might listen for route advertisements or send pings down a network of which the operating system doesn't even notice it's there).

chrysn avatar Sep 13 '21 10:09 chrysn

JS running on the browser have limited access to operating system unlike other programming languages. As long as there is an ip address JS can send requests and receive responses.

pathnirvana avatar Sep 13 '21 10:09 pathnirvana

A JS implementation of CDC-ECM would use its own IP stack, like a has become fashion in some areas with Unikernels (and inside this "virtual" world be allowed to send arbitrary messages) -- but let's leave that discussion to when there's actually basic WebUSB support (which should be the easy part).

chrysn avatar Sep 13 '21 10:09 chrysn

I think this would work with nodejs but not inside the browser. Take a look at this https://stackoverflow.com/questions/17999950/communicating-with-arduino-over-ethernet-using-node-js

pathnirvana avatar Sep 13 '21 10:09 pathnirvana

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

stale[bot] avatar Apr 17 '22 07:04 stale[bot]

If I have understood it correctly, you want to run a web server.

Hateem-Arshad avatar Aug 25 '24 22:08 Hateem-Arshad