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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@yolanda-qn/qn-mp-plugin

v1.0.1

Published

小程序蓝牙对象

Readme

轻牛小程序蓝牙库

安装依赖

npm install @yolanda-qn/qn-mp-plugin

使用流程介绍

1、初始化

先实例化蓝牙类,并设置蓝牙事件监听类和设备事件监听类

然后在page的onReady事件中,调用初始化方法

注意!安卓手机通常都需要打开定位开关才能使用蓝牙功能,苹果手机则需要获得蓝牙权限

//引入小程序蓝牙类
import { QNMPPlugin } from '@yolanda-qn/qn-mp-plugin';

/**
 * 微信的本地日志功能,需要用户手动反馈才能拿到日志文件
 */
const logger = () => {
  const wxlogger =
    wx.getLogManager &&
    wx.getLogManager({
      level: 0,
    });
  const log = (...params) => {
    console.log(...params);
    wxlogger && wxlogger.log(...params);
  };
  return {
    log,
  };
}

 onLoad: function (options) {
    // 初始化蓝牙
    this.bleApi = new QNMPPlugin({
      appId: APPID, // 必须, 客户小程序的appid, 需要配置才能使用,
      logger: logger(), // 非必须,日志功能,最好有,方便排查问题,可以替换为客户自己的
    });
    // 错误监听
    this.bleApi.onError = (err) => { console.error('捕捉到错误', err.detail); };
    // 初始化
    this.bleApi.init()
    // 初始化回调
    this.bleApi.onReady = ({
      bleEnableState, //表示当前蓝牙是否为开启状态
    }) => {
      if (bleEnableState) {
        this.bleApi.startBleDeviceDiscovery();
      } else {
        console.log('蓝牙状态为关闭');
      }
    };
    // 设置蓝牙监听事件
    this.bleApi.setBleEventListener(this.bleEventListener());
  }

2、启动扫描

调用 this.bleApi.startBleDeviceDiscovery(),会启动蓝牙扫描

扫描的数据会在this.bleApi.setBleEventListener(this);中的 onBleDeviceFound 回调,其中参数是扫描到的设备对象

3、创建连接

调用 this.bleApi.createBleConnection(device,deviceEventListener operation) 会进行ble的连接

4、处理数据

连接成功后,会在deviceEventListener中的, onGetUnsteadyWeightonGetScaleData等方法回调一些数据

  • 对于体重秤最终稳定的数据会在 onGetScaleData中回调
  • 对于身高测量仪最终稳定的数据会在 onGetHandHeightData中回调

5、停止蓝牙活动

在离开页面的时候,需要调用this.bleApi.stop() 来停止当前的蓝牙活动

事件监听说明

插件中主要提供两个事件监听回调

  • 蓝牙事件监听回调,回调蓝牙相关的事件,比如蓝牙开关变化,连接成功,扫描到数据等
  • 设备事件回调,回调设备端的事件,该回调需要在连接成功后,才能生效,不同的设备,可能回调的时间不一样

蓝牙事件回调

interface QNBleEventListener {
    /**
     * 蓝牙开关状态变化,available 为true 蓝牙已打开,false 是蓝牙已关闭,
     */
    onBluetoothEnableChange: (payload: { available: boolean }) => void;
    /**
     * 回调启动了蓝牙扫描
     */
    onStartDiscoveryDevice: () => void;
    /**
     * 回调停止了蓝牙扫描
     */
    onStopDiscoveryDevice: () => void;
    /**
     * 回调扫描到的蓝牙设备
     */
    onBleDeviceFound: (device: QNBleDevice) => void;
    /**
     * 设备连接成功
     */
    onConnected: (payload: { deviceId: string }) => void;
    /**
     * 设备断开连接
     */
    onDisconnected: (payload: { deviceId: string }) => void;
    /**
     * 设备连接超时
     */
    onConnectOverTime: (payload: { deviceId: string }) => void;
    // onError: QNBleErrorListener
  }

类型声明库

@yolanda-qn/qn-ble-types

DEMO地址

https://gitee.com/yolandaqingniu/qn_mp_plugin_demo