MCPcopy Index your code
hub / github.com/MnlPhlp/tauri-plugin-blec

github.com/MnlPhlp/tauri-plugin-blec @v0.3.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.3.0 ↗ · + Follow
188 symbols 312 edges 29 files 20 documented · 11% updated 1d ago★ 2237 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Tauri Plugin blec

A BLE-Client plugin based on btlelug.

The main difference to using btleplug directly is that this uses the tauri plugin system for android. All other platforms use the btleplug implementation.

Docs

Installation

Install the rust part of the plugin:

cargo add tauri-plugin-blec

Or manually add it to the src-tauri/Cargo.toml

[dependencies]
tauri-plugin-blec = "0.1"

Install the js bindings

use your preferred JavaScript package manager to add @mnlphlp/plugin-blec:

yarn add @mnlphlp/plugin-blec
npm add @mnlphlp/plugin-blec

Register the plugin in Tauri

src-tauri/src/lib.rs

tauri::Builder::default()
    .plugin(tauri_plugin_blec::init())
    .run(tauri::generate_context!())
    .expect("error while running tauri application");

IOS Setup

Add an entry to the info.plist of your app:

<key>NSBluetoothAlwaysUsageDescription</key>
<string>The App uses Bluetooth to communicate with BLE devices</string>

Add the CoreBluetooth Framework in your xcode procjet: - open with tauri ios dev --open - click on your project to open settings - Add Framework under General -> Frameworks,Libraries and Embedded Content

Usage in Frontend

See examples/plugin-blec-example for a full working example that scans for devices, connects and sends/receives data. In order to use it run examples/test-server on another device and connect to that server.

Short example:

import { connect, sendString } from '@mnlphlp/plugin-blec'
// get address by scanning for devices and selecting the desired one
let address = ...
// connect and run a callback on disconnect
await connect(address, () => console.log('disconnected'))
// send some text to a characteristic
const CHARACTERISTIC_UUID = '51FF12BB-3ED8-46E5-B4F9-D64E2FEC021B'
await sendString(CHARACTERISTIC_UUID, 'Test', 'withResponse')

Usage in Backend

The plugin can also be used from the rust backend.

The handler returned by get_handler() is the same that is used by the frontend commands. This means if you connect from the frontend you can send data from rust without having to call connect on the backend.

use uuid::{uuid, Uuid};
use tauri_plugin_blec::models::WriteType;

const CHARACTERISTIC_UUID: Uuid = uuid!("51FF12BB-3ED8-46E5-B4F9-D64E2FEC021B");
const DATA: [u8; 500] = [0; 500];
let handler = tauri_plugin_blec::get_handler().unwrap();
handler
    .send_data(CHARACTERISTIC_UUID, &DATA, WriteType::WithResponse)
    .await
    .unwrap();

Core symbols most depended-on inside this repo

get_handle
called by 13
src/android.rs
get_handler
called by 12
src/lib.rs
is_connected
called by 5
src/handler.rs
id
called by 4
src/android.rs
services
called by 4
src/android.rs
get_charac
called by 4
src/handler.rs
stop_scan
called by 4
src/handler.rs
init
called by 3
src/lib.rs

Shape

Method 100
Function 46
Class 38
Enum 4

Languages

Rust59%
Kotlin35%
TypeScript7%

Modules by API surface

src/android.rs42 symbols
src/handler.rs29 symbols
android/src/main/java/Peripheral.kt23 symbols
android/src/main/java/BleClientPlugin.kt18 symbols
src/commands.rs15 symbols
src/models.rs13 symbols
guest-js/index.ts13 symbols
android/src/main/java/BleClient.kt13 symbols
src/lib.rs3 symbols
examples/plugin-blec-example/src-tauri/gen/android/buildSrc/src/main/java/com/plugin_blec_example/app/kotlin/RustPlugin.kt3 symbols
examples/plugin-blec-example/src-tauri/gen/android/buildSrc/src/main/java/com/plugin_blec_example/app/kotlin/BuildTask.kt3 symbols
src/error.rs2 symbols

For agents

$ claude mcp add tauri-plugin-blec \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact