blec

Crates.ioblec
lib.rsblec
version0.3.4
sourcesrc
created_at2023-07-17 15:50:17.273731
updated_at2024-07-25 15:17:34.631157
descriptionsimple cross-platform ble client library based on btleplug
homepagehttps://github.com/MnlPhlp/blec
repositoryhttps://github.com/MnlPhlp/blec
max_upload_size
id918619
size38,103
Manuel Philipp (MnlPhlp)

documentation

README

BLEC

A simple cross-platform BLE Client library based on the awesome btleplug library

This mainly wraps btleplug methods in way that is easier to use if you just need one active connection. It also deals with setup on the different platforms. Most of that setup was taken from flutter_btleplug.

My use case and the reason I created this is for simple communication in an Android app created in Flutter with business logic in Rust.

Basic Usage

// initialize library
blec::init();

// scan for available devices
// either use channel to receive devices when discovered
let (tx,rx) = mpsc::channel(1);
blec::discover(tx,1000);
// or use discover_blocking() or discover_async() to receive Vec with devices after timeout
let devices = blec::discover_blocking(1000);

// get address of wanted device and call connect
// you also have to pass the wanted service and characteristics UUIDs
// a callback called on disconnect is optional
let adr = devices[0].address;
blec::connect(adr,<service UUID>, <charac UUIDs>, None / Some(disconnect callback));

// after this you can send/receive data to/from  the characteristics
// send
blec::send_data(<charac UUID>, <data>);
// read
let data = blec::recv_data(<charac UUD>);
// listen for notification
// the callback gets called with the notification data when a notification is received
blec::subscribe(<charac UUID>, <callblack>);

// at the end you can disconnect
blec::disconnect()

Android Setup

In order to use this on android you need the Java part of jni-utils-rs and droidplug. Some more Information for Android setup is provided by the btleplug library this is based on.

Example

See esp_wifi_setup_app for an example that uses this library in a flutter app to setup wifi credentials on a esp32.

The app part of that example can be used as basis for a flutter app using blec.

Commit count: 18

cargo fmt