• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

src/03-Apr-2024-630370

CMakeLists.txtD03-Apr-2024290 117

README.rstD03-Apr-20242.9 KiB9263

demo.rstD03-Apr-202489 85

index.htmlD03-Apr-20243.1 KiB127110

prj.confD03-Apr-2024344 1412

sample.yamlD03-Apr-2024177 1110

README.rst

1.. zephyr:code-sample:: webusb
2   :name: WebUSB
3   :relevant-api: usbd_api
4
5   Receive and echo data from a web page using WebUSB API.
6
7For a deeper dive into the WebUSB, refer to
8https://developers.google.com/web/updates/2016/03/access-usb-devices-on-the-web
9
10WebUSB API Specification:
11https://wicg.github.io/webusb/
12
13Overview
14********
15
16This simple echo application demonstrates the WebUSB sample application.
17This application receives the data and echoes back to the WebUSB
18based web application (web page) running in the browser at host.
19This application is intended for testing purposes only. For running
20real usecase, implement applications based on the WebUSB API.
21This sample can be found under :zephyr_file:`samples/subsys/usb/webusb` in the
22Zephyr project tree.
23
24Requirements
25************
26
27This project requires an USB device driver, which is available for multiple
28boards supported in Zephyr.
29
30Building and Running
31********************
32
33Build and flash webusb sample with:
34
35.. zephyr-app-commands::
36   :zephyr-app: samples/subsys/usb/webusb
37   :board: <board to use>
38   :goals: flash
39   :compact:
40
41Testing with the latest Google Chrome on host
42*********************************************
43
44This sample application requires the latest Google Chrome, a web page
45based on WebUSB API to connect to the USB device and optionally
46http server running on localhost to serve the web page.
47
48WebUSB is a powerful new feature added to the Web and it is available
49only to secure origins. This means the web page/site that is used to
50connect to the device must be served over a secure connection (HTTPS).
51
52Follow these steps to run the demo on your host system:
53
54#. Run the latest Google Chrome on host.
55
56#. Implement a web app (web page) using WebUSB API and run
57   it on localhost.
58
59   The sample can be found in the webusb sample directory:
60   :zephyr_file:`samples/subsys/usb/webusb/index.html`.
61
62   This sample web page demonstrates how to create and use a WebUSB
63   interface, as well as demonstrate the communication between browser
64   and WebUSB enabled device.
65
66   There are two ways to access this sample page:
67
68   * Using Chrome browser go to :doc:`demo`
69
70   * Host the demo page locally: Start a web server
71     in the webusb sample directory.
72
73     .. code-block:: console
74
75        $ python -m http.server
76
77     Using Chrome browser open url http://localhost:8001/
78
79#. Connect the board to your host.
80
81#. Once the device is booted, you should see a notification from
82   Chrome: "Go to localhost to connect.". Click on the notification
83   to open demo page.
84   Note that at the moment WebUSB landing page notification is disabled
85   in Chrome on Windows. See https://github.com/WICG/webusb#implementation-status
86
87#. Click on the :guilabel:`Connect` button to connect to the device.
88
89#. Send some text to the device by clicking on the :guilabel:`Send` button.
90   The demo app will receive the same text from the device and display it in
91   the text area.
92