https://github.com/tuemb/ble_wasm_example
https://github.com/tuemb/ble_wasm_example
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/tuemb/ble_wasm_example
- Owner: TuEmb
- Created: 2025-06-19T05:50:40.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-06-19T06:02:17.000Z (10 months ago)
- Last Synced: 2025-06-19T06:34:53.118Z (10 months ago)
- Language: Rust
- Size: 0 Bytes
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Web Bluetooth Rust Example
This project demonstrates using Rust and WebAssembly to scan for Bluetooth Low Energy (BLE) devices in the browser.
## Prerequisites
- [Rust](https://www.rust-lang.org/tools/install)
- [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/)
- [npm](https://nodejs.org/) (for running a local web server)
## Build
1. Build the WebAssembly package using `wasm-pack`:
**Windows**
```sh
set RUSTFLAGS=--cfg=web_sys_unstable_apis
wasm-pack build --target web
```
**Linux/MacOS**
```sh
export RUSTFLAGS="--cfg=web_sys_unstable_apis"
wasm-pack build --target web
```
This will generate the `pkg/` directory with the necessary JS and WASM files.
## Run
2. Serve the project locally (you need a web server to use Web Bluetooth):
```sh
npx serve .
```
Or use any other static file server (e.g., `python -m http.server`).
3. Open [http://localhost:5000](http://localhost:5000) (or the port shown in your terminal) in a supported browser (e.g., Chrome).
4. Click the **Scan BLE Devices** button to start scanning for BLE devices.
## Notes
- Web Bluetooth only works on secure contexts (localhost or HTTPS).
- Make sure your browser supports the [Web Bluetooth API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API).
## Project Structure
- [`src/lib.rs`](src/lib.rs): Rust source code for BLE scanning.
- [`index.html`](index.html): Web page UI and JS glue code.
- [`pkg/`](pkg/): Generated WebAssembly and JS bindings.