All Projects → zhaodahai → wx-ant-ble

zhaodahai / wx-ant-ble

Licence: MIT license
微信、支付宝小程序BLE蓝牙SDK

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to wx-ant-ble

pymetawear
Community developed SDK around the Python bindings for the C++ SDK
Stars: ✭ 42 (-44%)
Mutual labels:  bluetooth, ble
ZJ-SDK-RT-Thread-NORDIC
基于RT-Thread操作系统在子敬电子ZJ-TEK系列开发板的软件开发包
Stars: ✭ 68 (-9.33%)
Mutual labels:  ant, ble
BLELib
This library contains many of the features you need to interact with BLE peripherals
Stars: ✭ 21 (-72%)
Mutual labels:  bluetooth, ble
easyble
A simple framework for Android Bluetooth Low Energy (BLE)
Stars: ✭ 43 (-42.67%)
Mutual labels:  bluetooth, ble
awesome-bluetooth-security
List of Bluetooth BR/EDR/LE security resources
Stars: ✭ 220 (+193.33%)
Mutual labels:  bluetooth, ble
bluetooth-iot-service-python
This application connects two devices over Bluetooth and allows one to send messages to the other using json. Raspberry Pi Bluetooth interfacing with Linux via RFCOMM BT network
Stars: ✭ 23 (-69.33%)
Mutual labels:  bluetooth, ble
bluetooth-gatt-parser
Bluetooth GATT service and characteristic parser
Stars: ✭ 61 (-18.67%)
Mutual labels:  bluetooth, ble
ChromeBluetooth
Demo of a "Stress Display" using Chrome Bluetooth. Reads Heart-rate data, and displays "stress" colors to a smart bulb. (Uses a SBT5007 smart bulb)
Stars: ✭ 14 (-81.33%)
Mutual labels:  bluetooth, ble
python-sonicare
Python library to communicate with a Phillips Sonicare toothbrush via Bluetooth Low Energy
Stars: ✭ 46 (-38.67%)
Mutual labels:  bluetooth, ble
arduino-ble-gadget
Create your own Do-It-Yourself BLE enabled sensor gadget on the ESP32 platform.
Stars: ✭ 31 (-58.67%)
Mutual labels:  bluetooth, ble
GoFIT SDK Android
GoFIT SDK for Android — GOLiFE 手環 App 介接 SDK
Stars: ✭ 32 (-57.33%)
Mutual labels:  bluetooth, ble
Bluetooth-ble-beamer-and-scanner-for-tracing-corona-virus-infected-individual
Bluetooth ble beacon beamer and scanner for tracing corona virus infected person similar to Trace Together app
Stars: ✭ 26 (-65.33%)
Mutual labels:  bluetooth, ble
mi-lamp-re
💡 Reverse Engineering Notes for the Yeelight Bedside Lamp (BLE)
Stars: ✭ 35 (-53.33%)
Mutual labels:  bluetooth, ble
react-native-google-nearby-messages
📲 Communicate with nearby devices using Bluetooth, BLE, WiFi and near-ultrasonic audio. Broadcast and receive small payloads (like strings) using the easy-to-use React Native API!
Stars: ✭ 143 (+90.67%)
Mutual labels:  bluetooth, ble
ESP32BleAdvertise
Simple library for BLE advertise using ESP32 in Arduino
Stars: ✭ 39 (-48%)
Mutual labels:  bluetooth, ble
taroCloud
记日常、GitHub trending资讯小程序 taro-hooks + rematch+云开发
Stars: ✭ 25 (-66.67%)
Mutual labels:  wxapp, wx
theheraldproject.github.io
Herald - Proximity Detection Protocol and research documentation, including the Fair Efficacy Formula
Stars: ✭ 17 (-77.33%)
Mutual labels:  bluetooth, ble
ble2mqtt
A BLE to MQTT bridge
Stars: ✭ 60 (-20%)
Mutual labels:  bluetooth, ble
H.E.L.P.
Home Environment Locating People 🍍
Stars: ✭ 19 (-74.67%)
Mutual labels:  bluetooth, ble
Metro-Weapp
微信小程序-上海地铁Lite
Stars: ✭ 15 (-80%)
Mutual labels:  wxapp, wx

wx-ant-ble

npm version

微信、支付宝小程序BLE蓝牙SDK

详细接口说明

Release Notes

v1.1.0

2019/01/15
1、发布第一个可用版本。封装蓝牙接口,兼容微信和支付宝小程序。附有说明和demo。

v1.1.1

2019/08/15
1、修复微信小程序安卓手机断开连接,状态更新不回调的bug。
2、已知另一个微信小程序蓝牙bug。安卓手机在设备异常断开时(比如断电),不会触发onBLEConnectionStateChange回调。除非在已经设置监听notify的情况下。

Features

  • 兼容微信和支付宝小程序
  • 简洁但功能完整的Api,可以根据需求自由调用
  • 接口均有返回状态,判断是否调用成功
  • 单例模式
  • 完整例子

Directory

  • ~/index.js SDK入口
  • ~/src SDK源码
  • ~/example 微信和支付宝小程序demo

Installation

  • npm
  npm install wx-ant-ble

  // 微信小程序请查看npm文档,支付宝小程序仅下载
  • 直接下载或者使用git克隆
  git clone https://github.com/zhaodahai/wx-ant-ble.git

Usage

1、引入SDK管理类和枚举

  // 引入SDK管理类 微信小程序通过npm构建后
  import { BTManager, ConnectStatus } from 'wx-ant-ble';
  // 引入SDK管理类 支付宝小程序
  import { BTManager, ConnectStatus } from '../../wx-ant-ble/index.js';

2、初始化蓝牙管理器 & 设置用户信息

  // 初始化蓝牙管理器 单例模式
  this.bt = new BTManager({
    debug: true // 是否开启打印调试
  });

3、注册回调

  // 注册状态更新回调
  this.bt.registerDidUpdateConnectStatus(res => {
    // 参数结构注意查看log
    console.log('registerDidUpdateConnectStatus', res);
    if (res.connectStatus === ConnectStatus.connected) {
      this.setData({ isConnected: true });
      ...
    }else if (res.connectStatus === ConnectStatus.disconnected) {
      this.setData({ isConnected: false });
      ...
    }
  });
  // 注册发现外设回调,当扫描到设备时回调,或者达到超时时间回调。
  this.bt.registerDidDiscoverDevice(res => {
    // 参数结构注意查看log
    console.log('registerDidDiscoverDevice', res);
    ...
  });
  // 注册特征值改变回调,当监听的特征值改变时回调,或者读特征值时回调。
  this.bt.registerDidUpdateValueForCharacteristic(res => {
    // 参数结构注意查看log
    console.log('registerDidUpdateValueForCharacteristic', res);
    ...
  });

4、扫描 & 停止扫描

  // 开始扫描
  this.bt.scan({
    services: [],              // 主service的uuid列表
    allowDuplicatesKey: false, // 是否允许重复上报设备
    interval: 0,               // 上报新设备的间隔,默认为0
    timeout: 15000,            // 扫描超时时间,毫秒
    deviceName: '',            // 需要匹配的设备名称
    containName: ''            // 需要包含的设备名称
  }).then(res => {
    console.log('scan success', res);
  }).catch(e => {
    console.log('scan fail', e);
  });
  // 停止扫描
  this.bt.stopScan()
  .then(res => {
    console.log('stopScan success', res);
  }).catch(e => {
    console.log('stopScan fail', e);
  })

5、连接 & 断开连接

  // 连接设备
  this.bt.connect(device) // device应为registerDidDiscoverDevice注册的方法上报的设备对象
  .then(res => {
    console.log('connect success', res);
  }).catch(e => {
    console.log('connect fail', e);
  });
  // 断开连接
  this.bt.disconnect()
  .then(res => {
    console.log('disconnect success', res);
  }).catch(e => {
    console.log('disconnect fail', e);
  })

5、Read & Notify & Write

  // 读特征值,读到的值从registerDidUpdateValueForCharacteristic注册的方法上报
  this.bt.read({
    suuid: 'xxxx', // 特征对应的服务uuid
    cuuid: 'xxxx'  // 特征uuid
  }).then(res => {
    console.log('read success', res);
  }).catch(e => {
    console.log('read fail', e);
  })
  // 向蓝牙模块写入数据
  this.bt.write({
    suuid: 'xxxx', // 特征对应的服务uuid
    cuuid: 'xxxx', // 特征uuid
    value: 'FFFF'  // 写入的数据
  }).then(res => {
    console.log('write success', res);
  }).catch(e => {
    console.log('write fail', e);
  })
  // 监听/停止监听 特征值改变,改变特征值从registerDidUpdateValueForCharacteristic注册的方法上报
  this.bt.notify({
    suuid: 'xxxx',     // 特征对应的服务uuid
    cuuid: 'xxxx',     // 特征uuid
    state: true/false  // 是否监听
  }).then(res => {
    console.log('notify success', res);
  }).catch(e => {
    console.log('notify fail', e);
  })

WxApp

仓库地址

BLE蓝牙开发助手二维码

BLE蓝牙开发助手演示

Notice

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].