UNPKG

mcblekit

Version:

该微信小程序开源代码库用于管理微信小程序中的蓝牙功能。支持初始化蓝牙适配器、扫描和连接蓝牙设备、获取设备服务和特征、监听特征值变化、读写特征值以及断开连接等操作。通过设置不同的监听器,可灵活处理蓝牙连接状态变化、设备发现、服务和特征发现等事件,适用于需要与蓝牙设备进行数据交互的微信小程序开发场景。This WeChat mini program open-source code library is used to manage the Bluetooth function in WeChat mini

34 lines (32 loc) 665 B
/** * MCrssi.js. * MCBleKit * * Created by Morgan Chen on 2025/4/17. * https://github.com/Json031 */ /** * get Bluetooth Device RSSI * * @param {string} deviceId Bluetooth device id * * @return {number} RSSI value */ function getDeviceRSSI(deviceId) { return new Promise((resolve, reject) => { wx.getBLEDeviceRSSI({ deviceId, success(res) { console.log(`📶 当前设备 RSSI: ${res.RSSI}`) resolve(res.RSSI) }, fail(err) { console.error('❌ 获取 RSSI 失败', err) reject(err) } }) }) } module.exports = { getDeviceRSSI: getDeviceRSSI };