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

qcloud-iotexplorer-bluetooth-adapter-llsync

v3.0.117

Published

腾讯连连 llsync sdk 开发文档,小程序可以通过本 sdk 完成和标准蓝牙设备进行连接,绑定,控制等流程。通过下面的图片可以直观地了解整个流程:

Downloads

332

Readme

qcloud-iotexplorer-bluetooth-adapter-llsync

腾讯连连 llsync sdk 开发文档,小程序可以通过本 sdk 完成和标准蓝牙设备进行连接,绑定,控制等流程。通过下面的图片可以直观地了解整个流程:

1. 创建一个 bluetoothAdapter

bluetoothAdapter 可以用来搜索设备,连接到设备。代码如下:

import { BlueToothAdapter } from 'qcloud-iotexplorer-bluetooth-adapter';
import { LLSyncDeviceAdapter } from 'qcloud-iotexplorer-bluetooth-adapter-llsync';

// 关于appDevSdk文档,详见https://www.npmjs.com/package/qcloud-iotexplorer-appdev-sdk
const options = {
  appDevSdk, // 通过qcloud-iotexplorer-appdev-sdk得到的实例
}
LLSyncDeviceAdapter.injectOptions(options);
export const bluetoothAdapter = new BlueToothAdapter({
  deviceAdapters: [
    LLSyncDeviceAdapter,
  ],
});

2. 获取蓝牙设备列表

通过 bluetoothAdapter.startSearch方法,我们可以发现设备,获得设备列表。

  const serviceIds = [BleComboLLSyncDeviceAdapter.serviceId];
  await bluetoothAdapter.startSearch({
    ignoreDeviceIds,
    serviceIds,
    ignoreServiceIds,
    onError: (error) => {
      console.log('----error', error);
      // 搜索设备出错
      bluetoothAdapter.stopSearch();
    },
    onSearch: (devices) => {
      console.log('searched devices', devices);
      if (devices.length > 0) {
        console.log('找到设备', devices); // 此时可以在页面上展示
      }
    },
    timeout: 1.4 * 15 * 1000,
  });

在上面的 onSearch 回调函数中,我们可以获得搜寻到的设备列表,这时可以将设备列表展示到页面上,供用户选择要连接哪个设备。

tip: 如果设备无法搜索到,请确认设备没有被绑定

3. 连接设备

用户从上面获取到的设备中选择一个,并发起连接操作时,可以调用 bluetoothAdapter.connectDevice 方法进行连接。连接成功后会返回一个 deviceAdapter,可以用来向连接的设备发送Wi-Fi,token等数据。

tip: 如果在连接时提示没有权限操作该产品,请到控制台/应用开发对应用和产品进行关联

try {
  // device 参数是上一步 onSearch 回调中获取 devices 数组的某一项
  const deviceAdapter = await bluetoothAdapter.connectDevice(device);

  if (!deviceAdapter) {
    throw {
      code: 'CONNECT_ERROR',
    }
  }
} catch (err) {
  console.error('连接到设备出错');
}

在这一步中,可以通过连接设备获得 deviceAdapter ,通过 deviceAdapter 可以完成后续设备的绑定和解绑操作

4. 绑定设备

绑定设备时,可以传入familyId, roomId, 从而将设备绑定到特定的家庭和房间

try {
  const deviceId = await deviceAdapter.bindDevice({ familyId, roomId });
} catch (err) {
  console.log(err);
}

5. 解绑设备

设备绑定后,也可以通过小程序发起删除设备的操作,这时需要调用解绑api,解绑完成后设备会恢复未绑定的状态。

try{
  await deviceAdapter.unbindDevice({ familyId, deviceId });
} catch (err) {
  console.log(err);
}

6. deviceAdapter事件

|事件|描述|参数| |---|---|---| connect | 蓝牙设备连接时触发 |DeviceInfo disconnect|蓝牙设备连接断开时触发|DeviceInfo| authorized|蓝牙设备授权完成时触发|{ version, mtu, otaVersion, }|