### Run Example with PYTHONPATH (from examples dir) Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/getting_started.md Run an example script after setting PYTHONPATH to the project root and changing the working directory to 'examples'. ```shell $ cd examples $ export PYTHONPATH=.. $ python3 run_scanner.py usb:0 ``` -------------------------------- ### Run Advertiser Example Source: https://github.com/google/bumble/blob/main/examples/README.md Example for running a Bluetooth advertiser. ```python # run_advertiser.py ``` -------------------------------- ### Run Scanner Example Source: https://github.com/google/bumble/blob/main/examples/README.md Run a host application connected to a BLE controller that starts scanning and prints out scan results. ```python # run_scanner.py ``` -------------------------------- ### Run GATT Client and Server Example Source: https://github.com/google/bumble/blob/main/examples/README.md Example for running both a GATT client and a GATT server. ```python # run_gatt_client_and_server.py ``` -------------------------------- ### Install Package Dependencies Source: https://github.com/google/bumble/blob/main/README.md Install the necessary package dependencies to run Bumble examples. This includes upgrading pip and installing the package with test, development, and documentation extras. ```bash python -m pip install --upgrade pip ``` ```bash python -m pip install " .[test,development,documentation]" ``` -------------------------------- ### Install lsusb on Linux Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/transports/usb.md Command to install the `lsusb` utility on Linux using apt. ```bash sudo apt-get install usbutils ``` -------------------------------- ### Install AuraCast Dependencies from PyPI Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/auracast.md Install the optional 'auracast' dependencies from PyPI. ```bash $ python3 -m pip install "bumble[auracast]" ``` -------------------------------- ### Run Bumble Example with netsim Source: https://github.com/google/bumble/blob/main/rust/README.md Example of how to run a Bumble example client using Android netsim. Ensure your PYTHONPATH is correctly set to include the virtualenv's site-packages. ```bash PYTHONPATH=..:~/.virtualenvs/bumble/lib/python3.10/site-packages/ \ cargo run --example battery_client -- \ --transport android-netsim --target-addr F0:F1:F2:F3:F4:F5 ``` -------------------------------- ### Start Speaker App with SBC Codec and Save to File Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/speaker.md Starts the speaker app, explicitly setting the codec to SBC and specifying an output file for the audio. ```bash $ bumble-speaker --codec sbc --output audio.sbc usb:0 ``` -------------------------------- ### Install AuraCast Dependencies from Source Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/auracast.md Install the optional 'auracast' dependencies when building from source. ```bash $ python3 -m pip install ".[auracast]" ``` -------------------------------- ### Launch Rfcomm Server Bench with adb Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/extras/android_bt_bench.md Starts the Rfcomm Server benchmark action using the `adb shell am start` command. This is useful for setting up a server to receive connections for testing. ```bash $ adb shell am start -n com.github.google.bumble.btbench/.MainActivity --es autostart rfcomm-server ``` -------------------------------- ### Install LC3 Module Separately Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/auracast.md Install the 'lc3' Python module from its GitHub repository if not automatically installed with Bumble. ```bash $ python3 -m pip install "git+https://github.com/google/liblc3.git" ``` -------------------------------- ### Run AuraCast as Installed Package Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/auracast.md Execute the 'auracast' tool when installed as a package. ```bash $ bumble-auracast ``` -------------------------------- ### Run GATT Client Example Source: https://github.com/google/bumble/blob/main/examples/README.md Run a host application that connects to a BLE controller, discovers services and attributes of a peer device, and displays them. ```python # run_gatt_client.py ``` -------------------------------- ### Install Bumble from Source Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/getting_started.md Install Bumble in development mode from its source code directory using pip. ```shell $ python3 -m pip install -e . ``` -------------------------------- ### Install Bumble from PyPI Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/getting_started.md Install the Bumble module from the Python Package Index using pip. ```shell $ python3 -m pip install bumble ``` -------------------------------- ### L2CAP Throughput Example Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/bench.md Tests L2CAP throughput by setting up an L2CAP server on the peripheral and an L2CAP client on the central. ```bash $ bumble-bench --mode l2cap-server peripheral usb:0 ``` ```bash $ bumble-bench --mode l2cap-client central usb:1 ``` -------------------------------- ### Build Static HTML Documentation Source: https://github.com/google/bumble/blob/main/README.md Build the static HTML site from markdown text using mkdocs. Ensure mkdocs is installed. ```bash mkdocs build -f docs/mkdocs/mkdocs.yml ``` -------------------------------- ### Start Speaker App and Save Audio to File Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/speaker.md Starts the speaker app, specifying an output file to save the received AAC audio. ```bash $ bumble-speaker --output audio.aac usb:0 ``` -------------------------------- ### Start Speaker App Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/speaker.md Starts the speaker app and waits for a connection from another Bluetooth device. ```bash $ bumble-speaker usb:0 ``` -------------------------------- ### Run GATT Server Example Source: https://github.com/google/bumble/blob/main/examples/README.md Run a host application that connects to a BLE controller and hosts a simple GATT server with basic services and characteristics. ```python # run_gatt_server.py ``` -------------------------------- ### Install Bumble from GitHub (Specific Commit) Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/getting_started.md Install Bumble from a specific commit hash on GitHub using pip. ```shell $ python3 -m pip install git+https://github.com/google/bumble.git@27c0551 ``` -------------------------------- ### Launch Rfcomm Client Bench with adb and parameters Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/extras/android_bt_bench.md Starts the Rfcomm Client benchmark action with specified packet count, packet size, and peer Bluetooth address. This allows for automated testing with specific configurations. ```bash $ adb shell am start -n com.github.google.bumble.btbench/.MainActivity --es autostart rfcomm-client --ei packet-count 100 --ei packet-size 1024 --es peer-bluetooth-address DA:4C:10:DE:17:02 ``` -------------------------------- ### Install Bumble from GitHub (Specific Tag) Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/getting_started.md Install a specific tagged version of Bumble from GitHub using pip. ```shell $ python3 -m pip install git+https://github.com/google/bumble.git@v0.0.1 ``` -------------------------------- ### Install PortAudio on Linux Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/auracast.md Install the PortAudio library on Linux systems, which is required by the 'sounddevice' module. ```bash $ sudo apt install libportaudio2 ``` -------------------------------- ### Install lsusb on macOS Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/transports/usb.md Command to install the `lsusb` utility on macOS using Homebrew. ```bash brew install lsusb ``` -------------------------------- ### Install Bumble from GitHub (Latest Commit) Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/getting_started.md Install the latest version of Bumble directly from the main branch on GitHub using pip. ```shell $ python3 -m pip install git+https://github.com/google/bumble.git ``` -------------------------------- ### PTY to Link Relay Example Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/hci_bridge.md Example of bridging a PTY (emulated UART) with a Link Relay transport. This setup is useful for connecting emulated hosts to virtual controllers mediated by a Link Relay. ```bash python hci_bridge.py serial:emulated_uart_pty,1000000 link-relay:ws://127.0.0.1:10723/test ``` -------------------------------- ### Start Speaker App and Connect to Remote Device Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/speaker.md Starts the speaker app and initiates a connection to a remote device using its Bluetooth address. ```bash $ bumble-speaker --connect B8:7B:C5:05:57:ED usb:0 ``` -------------------------------- ### Run USB Probe Tool (PyPI) Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/usb_probe.md Invoke the USB probe tool when installed from PyPI. No arguments are needed for basic listing. ```bash $ bumble-usb-probe ``` -------------------------------- ### USB Probe Tool Example Output Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/usb_probe.md Example output from the USB probe tool, showing device ID, Bumble transport names, bus/device info, class, subclass/protocol, manufacturer, and product. ```text ID 0A12:0001 Bumble Transport Names: usb:0 or usb:0A12:0001 Bus/Device: 020/034 Class: Wireless Controller Subclass/Protocol: 1/1 [Bluetooth] Manufacturer: None Product: USB2.0-BT ``` -------------------------------- ### Start Proxy from Command Line Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/extras/android_remote_hci.md Launch the remote HCI proxy from the command line on the phone. This command assumes the APK has been pushed to `/data/local/tmp/remotehci.apk` and will listen on the default TCP port. ```bash adb shell "CLASSPATH=/data/local/tmp/remotehci.apk app_process /system/bin com.github.google.bumble.remotehci.CommandLineInterface" ``` -------------------------------- ### Get Help for Bumble CLI Source: https://github.com/google/bumble/blob/main/rust/README.md Command to display help for the Bumble CLI tool. Replace '[virtualenv site-packages]' with the actual path to your virtual environment's site-packages directory. ```bash PYTHONPATH=..:[virtualenv site-packages] \ cargo run --features bumble-tools --bin bumble -- --help ``` -------------------------------- ### GATT Throughput Example Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/bench.md Runs a default GATT throughput test with a Central and Peripheral. The Central acts as a Sender (GATT client) and the Peripheral as a Receiver (GATT server). ```bash $ bumble-bench peripheral usb:0 ``` ```bash $ bumble-bench central usb:1 ``` -------------------------------- ### Attach Bumble Virtual Controller using VHCI Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/platforms/linux.md Use the run_controller.py example script with the 'vhci' transport to attach a Bumble virtual controller to the BlueZ stack. ```bash python3 examples/run_controller.py F6:F7:F8:F9:FA:FB examples/device1.json vhci ``` -------------------------------- ### PTY Transport Moniker Example Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/transports/pty.md This example shows the moniker syntax for creating a PTY transport and a symbolic link for convenient access. ```text pty:virtual_hci ``` -------------------------------- ### Ping/Pong Latency Example Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/bench.md Measures ping/pong latency by configuring one device for ping and the other for pong scenarios. ```bash $ bumble-bench --scenario pong peripheral usb:0 ``` ```bash $ bumble-bench --scenario ping central usb:1 ``` -------------------------------- ### Run Bumble Scanner with UART Configuration Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/platforms/linux.md Example of running the Bumble scanner script, specifying the UART device and speed obtained from the hciuart status. ```bash python3 run_scanner.py serial:/dev/serial1,3000000 ``` -------------------------------- ### bumble-intel-util Usage Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/drivers/intel.md Shows the usage for the bumble-intel-util command-line tool, which interacts with Intel USB controllers. It lists available options and commands such as rebooting to bootloader mode, getting firmware info, and loading firmware. ```text Usage: bumble-intel-util [OPTIONS] COMMAND [ARGS]... Options: --help Show this message and exit. Commands: bootloader Reboot in bootloader mode. info Get the firmware info. load Load a firmware image. ``` -------------------------------- ### Example lsusb Output Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/transports/usb.md Sample output from the `lsusb` command, showing detected USB devices and their IDs. The device ID for the Bluetooth interface is highlighted. ```bash $ lsusb Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 003 Device 014: ID 0b05:17cb ASUSTek Computer, Inc. Broadcom BCM20702A0 Bluetooth ``` -------------------------------- ### Start Proxy with Specific TCP Port Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/extras/android_remote_hci.md Start the remote HCI proxy and specify a custom TCP port for communication. This is useful if the default port is in use or for specific network configurations. ```bash adb shell "CLASSPATH=/data/local/tmp/remotehci.apk app_process /system/bin com.github.google.bumble.remotehci.CommandLineInterface 12345" ``` -------------------------------- ### Run Bumble controller with PTY transport on Linux Source: https://github.com/google/bumble/blob/main/examples/README.md Run the Bumble controller example using a PTY device as the HCI transport. A symbolic link named 'hci_pty' will be created. ```python python run_controller.py device1.json pty:hci_pty ``` -------------------------------- ### Start Bluetooth Daemon Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/platforms/linux.md Restart the `bluetoothd` service after it has been stopped. ```bash $ sudo systemctl start bluetooth.service ``` -------------------------------- ### Import LitElement Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/hive/web/scanner/scanner.html Imports LitElement and html from the Lit CDN. This is a common setup for LitElement applications. ```javascript import {LitElement, html} from 'https://cdn.jsdelivr.net/gh/lit/dist@2/core/lit-core.min.js'; ``` -------------------------------- ### Run USB Probe Tool with Verbose Output (PyPI) Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/usb_probe.md Run the USB probe tool with the --verbose flag to get additional details. This is useful for deeper inspection. ```bash $ bumble-usb-probe --v ``` -------------------------------- ### RFComm Throughput Example Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/bench.md Tests RFComm throughput with custom packet size and count. Note that the Peripheral's BT address will be printed and must be used with the --peripheral option for the Central. ```bash $ bumble-bench --mode rfcomm-server peripheral usb:0 ``` ```bash $ bumble-bench --mode rfcomm-client --packet-size 2000 --packet-count 100 central --peripheral 00:16:A4:5A:40:F2 usb:1 ``` -------------------------------- ### Construct LE Set Scan Enable Command Source: https://github.com/google/bumble/blob/main/rust/README.md Example of constructing an 'LE Set Scan Enable' command using the LeSetScanEnableBuilder. This command is used to enable or disable scanning for Bluetooth LE devices. ```rust use bumble::enable::Enable; use bumble::hci::LeSetScanEnableBuilder; // The "LE Set Scan Enable" command can be found in the Core Bluetooth Spec. // It can also be found in `packets.pdl` as `packet LeSetScanEnable : Command` fn main() { let device = init_device_as_desired(); let le_set_scan_enable_command_builder = LeSetScanEnableBuilder { filter_duplicates: Enable::Disabled, le_scan_enable: Enable::Enabled, }; } ``` -------------------------------- ### Initialize WebSocket and Audio Player Source: https://github.com/google/bumble/blob/main/examples/asha_sink.html Sets up a WebSocket connection to localhost:8888 and initializes a PCMPlayer for audio playback. Handles WebSocket events like open, close, error, and message. Binary messages are fed to the player. ```javascript let atResponseInput = document.getElementById("at_response") let gainInput = document.getElementById('browser-gain') let log = document.getElementById("log") let socket = new WebSocket('ws://localhost:8888'); let sampleRate = 0; let player; socket.binaryType = "arraybuffer"; socket.onopen = _ => { log.textContent += 'SOCKET OPEN\n' } socket.onclose = _ => { log.textContent += 'SOCKET CLOSED\n' } socket.onerror = (error) => { log.textContent += 'SOCKET ERROR\n' console.log(`ERROR: ${error}`) } socket.onmessage = function (message) { if (typeof message.data === 'string' || message.data instanceof String) { log.textContent += `<-- ${event.data}\n` } else { // BINARY audio data. if (player == null) return; player.feed(message.data); } }; ``` -------------------------------- ### Build Static HTML Site With MkDocs Source: https://github.com/google/bumble/blob/main/docs/README.md Use this command to build the static HTML documentation site from the project's root directory. Ensure you specify the correct mkdocs.yml configuration file. ```bash $ mkdocs build -f docs/mkdocs/mkdocs.yml ``` -------------------------------- ### Initialize WebSocket and Handle Messages Source: https://github.com/google/bumble/blob/main/apps/lea_unicast/index.html Sets up a WebSocket connection to the server and defines handlers for incoming messages, including binary audio data. Ensure the PCMPlayer is initialized before receiving audio. ```javascript let player = null; const wsStatus = document.getElementById("ws-status"); const wsStatusSpinner = document.getElementById("ws-status-spinner"); const socket = new WebSocket('ws://127.0.0.1:7654/channel'); socket.binaryType = "arraybuffer"; socket.onmessage = function (message) { if (typeof message.data === 'string' || message.data instanceof String) { console.log(`channel MESSAGE: ${message.data}`); } else { console.log(typeof (message.data)) // BINARY audio data. if (player == null) return; player.feed(message.data); } }; socket.onopen = (message) => { wsStatusSpinner.remove(); wsStatus.textContent = "WebSocket Connected"; } socket.onclose = (message) => { wsStatus.textContent = "WebSocket Disconnected"; } ``` -------------------------------- ### Launch RemoteHCI with Autostart Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/extras/android_remote_hci.md Use this command to launch the RemoteHCI app with the autostart feature enabled. ```bash $ adb shell am start -n com.github.google.bumble.remotehci/.MainActivity --ez autostart true ``` -------------------------------- ### Serial Transport Moniker Examples Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/transports/serial.md Examples of moniker syntax for configuring a serial transport. The default baud rate is 1,000,000 if not specified. Hardware flow control and port opening delays can be enabled. ```text /dev/tty.usbmodem0006839912172 ``` ```text /dev/tty.usbmodem0006839912172,1000000 ``` ```text /dev/tty.usbmodem0006839912172,rtscts ``` ```text /dev/tty.usbmodem0006839912172,rtscts,delay ``` -------------------------------- ### List Available HCI Controllers Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/platforms/linux.md The `hciconfig` command lists all available HCI controllers and their current states. ```bash $ hciconfig ``` ```text pi@raspberrypi:~ $ hciconfig hci1: Type: Primary Bus: USB BD Address: 00:16:A4:5A:40:F2 ACL MTU: 1021:8 SCO MTU: 64:1 DOWN RX bytes:84056 acl:0 sco:0 events:51 errors:0 TX bytes:1980 acl:0 sco:0 commands:90 errors:0 hci0: Type: Primary Bus: UART BD Address: DC:A6:32:75:2C:97 ACL MTU: 1021:8 SCO MTU: 64:1 DOWN RX bytes:68038 acl:0 sco:0 events:692 errors:0 TX bytes:20105 acl:0 sco:0 commands:843 errors:0 ``` -------------------------------- ### USB Transport Moniker Examples Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/transports/usb.md Examples of different moniker formats used to identify USB Bluetooth dongles. These include index-based, vendor/product ID, serial number, and port path specifications. The '!' suffix indicates forced mode. ```text usb:04b4:f901 ``` ```text usb:0 ``` ```text usb:04b4:f901/0016A45B05D8 ``` ```text usb:04b4:f901/#1 ``` ```text usb:0B05:17CB! ``` ```text usb:3-3.4.1 ``` -------------------------------- ### General Usage of bumble-bench Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/bench.md This displays the general usage and available options for the bumble-bench command-line tool. It outlines global settings and available commands. ```bash Usage: bumble-bench [OPTIONS] COMMAND [ARGS]... Options: --device-config FILENAME Device configuration file --scenario [send|receive|ping|pong] --mode [gatt-client|gatt-server|l2cap-client|l2cap-server|rfcomm-client|rfcomm-server] --att-mtu MTU GATT MTU (gatt-client mode) [23<=x<=517] --extended-data-length TEXT Request a data length upon connection, specified as tx_octets/tx_time --role-switch [central|peripheral] Request role switch upon connection (central or peripheral) --rfcomm-channel INTEGER RFComm channel to use (specify 0 for channel discovery via SDP) --rfcomm-uuid TEXT RFComm service UUID to use (ignored if --rfcomm-channel is not 0) --rfcomm-l2cap-mtu INTEGER RFComm L2CAP MTU --rfcomm-max-frame-size INTEGER RFComm maximum frame size --rfcomm-initial-credits INTEGER RFComm initial credits --rfcomm-max-credits INTEGER RFComm max credits --rfcomm-credits-threshold INTEGER RFComm credits threshold --l2cap-psm INTEGER L2CAP PSM to use --l2cap-mtu INTEGER L2CAP MTU to use --l2cap-mps INTEGER L2CAP MPS to use --l2cap-max-credits INTEGER L2CAP maximum number of credits allowed for the peer -s, --packet-size SIZE Packet size (send or ping scenario) [8<=x<=8192] -c, --packet-count COUNT Packet count (send or ping scenario) -sd, --start-delay SECONDS Start delay (send or ping scenario) --repeat N Repeat the run N times (send and ping scenario)(0, which is the fault, to run just once) --repeat-delay SECONDS Delay, in seconds, between repeats --pace MILLISECONDS Wait N milliseconds between packets (0, which is the fault, to send as fast as possible) --linger Don't exit at the end of a run (receive and pong scenarios) --help Show this message and exit. Commands: central Run as a central (initiates the connection) peripheral Run as a peripheral (waits for a connection) ``` -------------------------------- ### Run AuraCast from Source Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/auracast.md Execute the 'auracast' tool directly from the source code. ```bash $ python3 apps/auracast.py ``` -------------------------------- ### Launch RemoteHCI with Autostart and Custom Port Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/extras/android_remote_hci.md Launch the RemoteHCI app with autostart enabled and specify a custom TCP port for connections. ```bash $ adb shell am start -n com.github.google.bumble.remotehci/.MainActivity --ez autostart true --ei port 9995 ``` -------------------------------- ### Handle Get Element Attributes Response Source: https://github.com/google/bumble/blob/main/examples/avrcp_as_sink.html Updates the UI with element attributes when a response is received. Assumes a global `getElementAttributesResponseTable` and `createTable` function are available. ```javascript if (message.type == "get-element-attributes-response") { getElementAttributesResponseTable.replaceChildren(createTable(message.params)) } ``` -------------------------------- ### WebSocket Connection and Event Handling Source: https://github.com/google/bumble/blob/main/examples/keyboard.html Establishes a WebSocket connection and sets up listeners for mouse and keyboard events. Sends event data to the server. ```javascript let portInput = document.getElementById("port") let mouseInfo = document.getElementById("mouseInfo") let ketInfo = document.getElementById("keyInfo") let frame = document.getElementById("frame") let socketState = document.getElementById("socketState") let socket frame.addEventListener('mousemove', onMouseMove) document.addEventListener('keydown', onKeyDown) document.addEventListener('keyup', onKeyUp) function connect() { socket = new WebSocket(`ws://localhost:${portInput.value}`); socket.onopen = _ => { socketState.innerText = 'OPEN' } socket.onclose = _ => { socketState.innerText = 'CLOSED' } socket.onerror = (error) => { socketState.innerText = 'ERROR' console.log(`ERROR: ${error}`) } } function send(message) { if (socket && socket.readyState == WebSocket.OPEN) { socket.send(JSON.stringify(message)) } } function onMouseMove(event) { //console.log(event.movementX, event.movementY) mouseInfo.innerText = `MOUSE: x=${event.movementX}, y=${event.movementY}` send({ type:'mousemove', x: event.movementX, y: event.movementY }) } function onKeyDown(event) { //console.log(event) keyInfo.innerText = `KEYDOWN: ${event.key}` send({ type:'keydown', key: event.key }) } function onKeyUp(event) { //console.log(event) keyInfo.innerText = `KEYUP: ${event.key}` send({ type:'keyup', key: event.key }) } ``` -------------------------------- ### Receive Audio to Standard Output Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/auracast.md Configure the 'receive' command to output decoded audio samples to standard output as float32 PCM samples. ```bash --output stdout ``` -------------------------------- ### Parse ACL Packet Source: https://github.com/google/bumble/blob/main/rust/README.md Example of parsing a byte array identified as an ACL packet using the `Acl::parse` method. This is useful when dealing with raw HCI data. ```rust use bumble::hci::Acl; fn main() { let bytes = bytes_that_are_certainly_acl(); let acl_packet = Acl::parse(bytes).unwrap(); } ``` -------------------------------- ### Initialize UI Elements and Event Listeners Source: https://github.com/google/bumble/blob/main/examples/avrcp_as_sink.html Sets up references to HTML elements and attaches event listeners for keyboard input and WebSocket messages. This is essential for the web interface to function. ```javascript const portInput = document.getElementById("port") const connectButton = document.getElementById("connectButton") const socketState = document.getElementById("socketState") const volumeText = document.getElementById("volumeText") const positionText = document.getElementById("positionText") const trackText = document.getElementById("trackText") const playbackStatusText = document.getElementById("playbackStatusText") const addressedPlayerText = document.getElementById("addressedPlayerText") const uidCounterText = document.getElementById("uidCounterText") const supportedEventsText = document.getElementById("supportedEventsText") const playerSettingsTable = document.getElementById("playerSettingsTable") const getPlayStatusResponseTable = document.getElementById("getPlayStatusResponseTable") const getElementAttributesResponseTable = document.getElementById("getElementAttributesResponseTable") let socket let volume = 0 const keyNames = [ "SELECT", "UP", "DOWN", "LEFT", "RIGHT", "RIGHT_UP", "RIGHT_DOWN", "LEFT_UP", "LEFT_DOWN", "ROOT_MENU", "SETUP_MENU", "CONTENTS_MENU", "FAVORITE_MENU", "EXIT", "NUMBER_0", "NUMBER_1", "NUMBER_2", "NUMBER_3", "NUMBER_4", "NUMBER_5", "NUMBER_6", "NUMBER_7", "NUMBER_8", "NUMBER_9", "DOT", "ENTER", "CLEAR", "CHANNEL_UP", "CHANNEL_DOWN", "PREVIOUS_CHANNEL", "SOUND_SELECT", "INPUT_SELECT", "DISPLAY_INFORMATION", "HELP", "PAGE_UP", "PAGE_DOWN", "POWER", "VOLUME_UP", "VOLUME_DOWN", "MUTE", "PLAY", "STOP", "PAUSE", "RECORD", "REWIND", "FAST_FORWARD", "EJECT", "FORWARD", "BACKWARD", "ANGLE", "SUBPICTURE", "F1", "F2", "F3", "F4", "F5", ] document.addEventListener('keydown', onKeyDown) document.addEventListener('keyup', onKeyUp) const buttons = document.getElementById("buttons") keyNames.forEach(name => { const button = document.createElement("BUTTON") button.appendChild(document.createTextNode(name)) button.addEventListener("mousedown", event => { send({type: 'send-key-down', key: name}) }) button.addEventListener("mouseup", event => { send({type: 'send-key-up', key: name}) }) buttons.appendChild(button) }) updateVolume(0) ``` -------------------------------- ### Activate Bumble Conda Environment Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/development/python_environments.md After creating a Conda environment, use this command to activate it. This command sets up your shell to use the Python interpreter and packages installed in the 'bumble' environment. ```bash $ conda activate bumble ``` -------------------------------- ### Connect Audio with PCMPlayer Source: https://github.com/google/bumble/blob/main/examples/asha_sink.html Initializes and connects the audio player using PCMPlayer with specified codec, channels, sample rate, and flush time. Updates the button state to indicate connection. The volume is set based on the browser-gain input. ```javascript function connectAudio() { player = new PCMPlayer({ inputCodec: 'Int16', channels: 1, sampleRate: 16000, flushTime: 20, }); player.volume(gainInput.value); const button = document.getElementById("connect-audio") button.disabled = true; button.textContent = "Audio Connected"; } ``` -------------------------------- ### List Available Sound Devices Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/auracast.md Invoke the 'receive' command with '--output "device:?"' to list available sound devices and their IDs. ```bash --output "device:?" ``` -------------------------------- ### Run USB Probe Tool from Source Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/usb_probe.md Execute the USB probe tool directly from the source distribution using Python 3. This is useful for development or testing. ```bash python3 apps/usb-probe.py ``` -------------------------------- ### Receive Audio to File Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/auracast.md Configure the 'receive' command to write decoded audio samples to a specified file. ```bash --output ``` ```bash --output file: ``` -------------------------------- ### Run USB Probe Tool from Source with Verbose Output Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/usb_probe.md Execute the USB probe tool from the source distribution with the --verbose flag for more detailed output. ```bash python3 apps/usb-probe.py --verbose ``` -------------------------------- ### Send HCI Command and Interpret Response Source: https://github.com/google/bumble/blob/main/rust/README.md Example of sending an HCI command from a device and receiving its event response. The `check_result` parameter controls whether to receive the event response even on controller failure. ```rust use bumble::hci::{LeSetScanEnableBuilder, LeSetScanEnableComplete}; fn main() { // ... // `check_result` to false to receive the event response even if the controller returns a failure code let event = device.send_command(le_set_scan_enable_command_builder.into(), /*check_result*/ false); // Coerce the event into the expected format. A `Command` should have an associated event response // "Complete". let le_set_scan_enable_complete_event: LeSetScanEnableComplete = event.try_into().unwrap(); } ``` -------------------------------- ### Audio Playback Initialization Source: https://github.com/google/bumble/blob/main/examples/hfp_gateway.html Initializes the PCMPlayer for handling incoming audio data. This function should be called after the sample rate is known, typically after a 'sco_state_change' event. It sets up the player with specified codec, channels, and sample rate. ```javascript function connectAudio() { player = new PCMPlayer({ inputCodec: 'Int16', channels: 1, sampleRate: sampleRate, flushTime: 7.5, }); player.volume(gainInput.value); } ``` -------------------------------- ### UDP to Serial with Command Short-circuiting Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/hci_bridge.md Example of bridging UDP and serial transports, short-circuiting specific vendor-specific HCI commands (0x3f:0x0070, 0x3f:0x0074, 0x3f:0x0077, 0x3f:0x0078). This is useful when the host sends commands not supported by the controller. ```bash python hci_bridge.py udp:0.0.0.0:9000,127.0.0.1:9001 serial:/dev/tty.usbmodem0006839912171,1000000 0x3f:0x0070,0x3f:0x0074,0x3f:0x0077,0x3f:0x0078 ``` -------------------------------- ### Receive Audio to Sound Device Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/auracast.md Configure the 'receive' command to output decoded audio samples to the host's default sound device. ```bash --output "device" ``` -------------------------------- ### Set PYTHONPATH Globally (Unix-like) Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/getting_started.md Set the PYTHONPATH environment variable globally to include the current directory, allowing Python to find the Bumble module without installation. This is useful when working directly with the source code. ```shell $ export PYTHONPATH=. $ python3 apps/console.py serial:/dev/tty.usbmodem0006839912171 ``` -------------------------------- ### bumble-intel-fw-download Usage Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/drivers/intel.md Displays the usage instructions for the bumble-intel-fw-download utility, used to obtain Intel firmware images and configuration data. It outlines available options for output directory, source, single image download, and forcing overwrites. ```text Usage: bumble-intel-fw-download [OPTIONS] Download Intel firmware images and configs. Options: --output-dir TEXT Output directory where the files will be saved. Defaults to the OS-specific app data dir, which the driver will check when trying to find firmware --source [linux-kernel] [default: linux-kernel] --single TEXT Only download a single image set, by its base name --force Overwrite files if they already exist --help Show this message and exit. ``` -------------------------------- ### Initialize PCM Player for Audio Playback Source: https://github.com/google/bumble/blob/main/apps/lea_unicast/index.html Creates a new PCMPlayer instance with specified audio parameters and updates the UI to indicate audio connection. This function should be called after the WebSocket is established. ```javascript function connectAudio() { player = new PCMPlayer({ inputCodec: 'Int16', channels: 2, sampleRate: 48000, flushTime: 10, }); const button = document.getElementById("connect-audio") button.disabled = true; button.textContent = "Audio Connected"; } ``` -------------------------------- ### Interact with Realtek USB Dongles Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/drivers/realtek.md This utility allows interaction with Realtek USB dongles and firmware images. It supports commands for dropping, loading, and parsing firmware, as well as retrieving device information. ```bash Usage: bumble-rtk-util [OPTIONS] COMMAND [ARGS]... Options: --help Show this message and exit. Commands: drop Drop a firmware image from the USB dongle. info Get the firmware info from a USB dongle. load Load a firmware image into the USB dongle. parse Parse a firmware image. ``` -------------------------------- ### Receive Audio via FFPlay Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/auracast.md Configure the 'receive' command to pipe decoded audio samples to the 'ffplay' command. ```bash --output ffplay ``` -------------------------------- ### Restart adb as root Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/extras/android_remote_hci.md Before running the proxy, ensure adb is running as root. This is a prerequisite for certain operations. ```bash $ adb root ``` -------------------------------- ### Central Command Options for bumble-bench Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/bench.md This displays the specific options available when using the 'central' command in bumble-bench. These options are used to configure how the central device initiates and manages a connection. ```bash Usage: bumble-bench central [OPTIONS] TRANSPORT Run as a central (initiates the connection) Options: --peripheral ADDRESS_OR_NAME Address or name to connect to --connection-interval, --ci CONNECTION_INTERVAL Connection interval (in ms) --phy [1m|2m|coded] PHY to use --authenticate Authenticate (RFComm only) --encrypt Encrypt the connection (RFComm only) --help Show this message and exit. ``` -------------------------------- ### Run Pylint Linter Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/development/code_style.md Execute the project's linter with default settings, which enables Errors and Warnings. ```bash $ invoke project.lint ``` -------------------------------- ### Speaker App Usage Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/speaker.md Displays the help message for the speaker.py script, outlining available options and transports. ```bash Usage: speaker.py [OPTIONS] TRANSPORT Run the speaker. Options: --codec [sbc|aac] [default: aac] --discover Discover remote endpoints once connected --output NAME Send audio to this named output (may be used more than once for multiple outputs) --ui-port HTTP_PORT HTTP port for the UI server [default: 7654] --connect ADDRESS_OR_NAME Address or name to connect to --device-config FILENAME Device configuration file --help Show this message and exit. ``` -------------------------------- ### Reversed L2CAP Modes with Custom PHY Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/bench.md Shows reversed L2CAP modes (client on peripheral, server on central) with a custom PHY setting. ```bash $ bumble-bench --mode l2cap-client peripheral usb:0 ``` ```bash $ bumble-bench --mode l2cap-server central --phy 2m usb:1 ``` -------------------------------- ### Run GATT Server with Emulator via Netsim (Specific Host/Port) Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/platforms/android.md Connects a Bumble host stack to a specific Netsim gRPC server endpoint. Use this when automatic port discovery fails or when you need to specify the host and port manually. ```shell $ python3 run_gatt_server.py device1.json android-netsim:localhost:8877 ``` -------------------------------- ### Verify Virtual Controller with hciconfig Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/platforms/linux.md Check if the virtual controller has been attached to the BlueZ stack by inspecting the output of the 'hciconfig' command. ```bash $ hciconfig ``` -------------------------------- ### Connect to WebSocket Server Source: https://github.com/google/bumble/blob/main/examples/mcp_server.html Establishes a WebSocket connection to a server based on the provided port input. Handles connection opening, closing, errors, and incoming messages by updating a log element. ```javascript let portInput = document.getElementById("port") let log = document.getElementById("log") let socket function connect() { socket = new WebSocket(`ws://localhost:${portInput.value}`); socket.onopen = _ => { log.textContent += 'OPEN\n' } socket.onclose = _ => { log.textContent += 'CLOSED\n' } socket.onerror = (error) => { log.textContent += 'ERROR\n' console.log(`ERROR: ${error}`) } socket.onmessage = (event) => { log.textContent += `<-- ${event.data}\n` } } ``` -------------------------------- ### Instruct Pixel Buds Pro 2 to Receive Broadcast Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/auracast.md Use the `assist --command add-source` command to instruct Pixel Buds Pro 2 to receive an AuraCast broadcast. Ensure the buds are connected and ready to receive commands. ```bash assist --command add-source ``` -------------------------------- ### Specify Raw PCM Input Format Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/auracast.md Use the '--input-format' option to specify the format of raw PCM audio samples, including sample type, rate, and channels. ```bash --input-format ",," ``` -------------------------------- ### Scan for Devices with Virtual Controller Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/platforms/linux.md Perform a Bluetooth Low Energy scan using 'hcitool' to verify that the virtual 'Bumble' device is visible. ```bash $ sudo hcitool -i hci2 lescan ``` -------------------------------- ### Run Pylint Linter with All Categories Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/development/code_style.md Run the project's linter with all categories enabled by disabling the default filters. ```bash $ invoke project.lint --disable="" ``` -------------------------------- ### Download RTK Firmware Images Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/drivers/realtek.md Use this utility to download Realtek firmware images and configuration files. Specify the output directory, source, and options like overwriting existing files or parsing the image. ```bash Usage: bumble-rtk-fw-download [OPTIONS] Download RTK firmware images and configs. Options: --output-dir TEXT Output directory where the files will be saved [default: .] --source [linux-kernel|realtek-opensource|linux-from-scratch] [default: linux-kernel] --single TEXT Only download a single image set, by its base name --force Overwrite files if they already exist --parse Parse the FW image after saving --help Show this message and exit. ``` -------------------------------- ### Reversed GATT Modes with Custom Connection Interval Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/bench.md Demonstrates reversed GATT modes (client on peripheral, server on central) with a custom connection interval. ```bash $ bumble-bench --mode gatt-client peripheral usb:0 ``` ```bash $ bumble-bench --mode gatt-server central --ci 10 usb:1 ``` -------------------------------- ### List Available Sound Devices for Transmission Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/auracast.md Invoke the 'transmit' command with '--input "device:?"' to list available sound devices and their IDs for input. ```bash --input "device:?" ``` -------------------------------- ### Run Pre-Commit Checks Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/development/contributing.md Execute the project's pre-commit checks to ensure code style compliance and pass basic tests before submitting a Pull Request. ```bash $ invoke project.pre-commit ``` -------------------------------- ### Flash HCI USB Firmware with nrfutil Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/platforms/zephyr.md Use the `nrfutil` tool to flash the HCI USB firmware onto the nRF52840 dongle after placing it in bootloader mode. Ensure the correct serial port is specified. ```bash nrfutil dfu usb-serial -pkg hci_usb.zip -p /dev/ttyACM0 ``` -------------------------------- ### Run Console App Source: https://github.com/google/bumble/blob/main/docs/mkdocs/src/apps_and_tools/console.md Execute the console application with a specified transport. The transport-spec defines how to connect to the Bluetooth adapter. ```bash python console.py ``` ```bash python console.py usb:0 ```