npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mnlphlp/plugin-blec

v0.3.3

Published

JS Bindings for BLE-Client plugin for Tauri

Downloads

391

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')

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};

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
    .lock()
    .await
    .send_data(CHARACTERISTIC_UUID, &DATA)
    .await
    .unwrap();