Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 148 additions & 0 deletions docs-vitepress/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,34 @@ const sidebar: ExtendedSidebar = {
},
],
},
{
text: '相机',
collapsed: true,
items: [
{
text: 'CameraContext',
link: '/api-proxy/media/camera/CameraContext',
items: [
{
text: 'CameraContext.setZoom',
link: '/api-proxy/media/camera/CameraContext/setZoom',
},
{
text: 'CameraContext.startRecord',
link: '/api-proxy/media/camera/CameraContext/startRecord',
},
{
text: 'CameraContext.stopRecord',
link: '/api-proxy/media/camera/CameraContext/stopRecord',
},
{
text: 'CameraContext.takePhoto',
link: '/api-proxy/media/camera/CameraContext/takePhoto',
},
]
},
],
}
],
},
{
Expand Down Expand Up @@ -687,6 +715,56 @@ const sidebar: ExtendedSidebar = {
},
],
},
{
text: '蓝牙-通用',
collapsed: true,
items: [
{
text: 'openBluetoothAdapter',
link: '/api-proxy/device/bluetooth/openBluetoothAdapter',
},
{
text: 'closeBluetoothAdapter',
link: '/api-proxy/device/bluetooth/closeBluetoothAdapter',
},
{
text: 'startBluetoothDevicesDiscovery',
link: '/api-proxy/device/bluetooth/startBluetoothDevicesDiscovery',
},
{
text: 'stopBluetoothDevicesDiscovery',
link: '/api-proxy/device/bluetooth/stopBluetoothDevicesDiscovery',
},
{
text: 'onBluetoothDeviceFound',
link: '/api-proxy/device/bluetooth/onBluetoothDeviceFound',
},
{
text: 'offBluetoothDeviceFound',
link: '/api-proxy/device/bluetooth/offBluetoothDeviceFound',
},
{
text: 'getConnectedBluetoothDevices',
link: '/api-proxy/device/bluetooth/getConnectedBluetoothDevices',
},
{
text: 'getBluetoothAdapterState',
link: '/api-proxy/device/bluetooth/getBluetoothAdapterState',
},
{
text: 'onBluetoothAdapterStateChange',
link: '/api-proxy/device/bluetooth/onBluetoothAdapterStateChange',
},
{
text: 'offBluetoothAdapterStateChange',
link: '/api-proxy/device/bluetooth/offBluetoothAdapterStateChange',
},
{
text: 'getBluetoothDevices',
link: '/api-proxy/device/bluetooth/getBluetoothDevices',
},
]
},
{
text: '蓝牙-低功耗中心设备',
collapsed: true,
Expand All @@ -703,8 +781,78 @@ const sidebar: ExtendedSidebar = {
text: 'onBLEConnectionStateChange',
link: '/api-proxy/device/bluetooth-ble/onBLEConnectionStateChange',
},
{
text: 'offBLEConnectionStateChange',
link: '/api-proxy/device/bluetooth-ble/offBLEConnectionStateChange',
},
{
text: 'writeBLECharacteristicValue',
link: '/api-proxy/device/bluetooth-ble/writeBLECharacteristicValue',
},
{
text: 'readBLECharacteristicValue',
link: '/api-proxy/device/bluetooth-ble/readBLECharacteristicValue',
},
{
text: 'notifyBLECharacteristicValueChange',
link: '/api-proxy/device/bluetooth-ble/notifyBLECharacteristicValueChange',
},
{
text: 'onBLECharacteristicValueChange',
link: '/api-proxy/device/bluetooth-ble/onBLECharacteristicValueChange',
},
{
text: 'offBLECharacteristicValueChange',
link: '/api-proxy/device/bluetooth-ble/offBLECharacteristicValueChange',
},
{
text: 'setBLEMTU',
link: '/api-proxy/device/bluetooth-ble/setBLEMTU',
},
{
text: 'getBLEDeviceRSSI',
link: '/api-proxy/device/bluetooth-ble/getBLEDeviceRSSI',
},
{
text: 'getBLEDeviceServices',
link: '/api-proxy/device/bluetooth-ble/getBLEDeviceServices',
},
{
text: 'getBLEDeviceCharacteristics',
link: '/api-proxy/device/bluetooth-ble/getBLEDeviceCharacteristics',
},
],
},
{
text: 'Wi-Fi',
collapsed: true,
items: [
{
text: 'startWifi',
link: '/api-proxy/device/wifi/startWifi',
},
{
text: 'stopWifi',
link: '/api-proxy/device/wifi/stopWifi',
},
{
text: 'getWifiList',
link: '/api-proxy/device/wifi/getWifiList',
},
{
text: 'onGetWifiList',
link: '/api-proxy/device/wifi/onGetWifiList',
},
{
text: 'offGetWifiList',
link: '/api-proxy/device/wifi/offGetWifiList',
},
{
text: 'getConnectedWifi',
link: '/api-proxy/device/wifi/getConnectedWifi',
},
]
},
{
text: '剪贴板',
collapsed: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mpx.closeBLEConnection(Object object)
## mpx.closeBLEConnection(Object object)

断开与蓝牙低功耗设备的连接。

支持情况: 微信、支付宝
支持情况: 微信、支付宝、RN

[参考文档](https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.closeBLEConnection.html)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
mpx.createBLEConnection(Object object)
## mpx.createBLEConnection(Object object)

连接蓝牙低功耗设备。

若小程序在之前已有搜索过某个蓝牙设备,并成功建立连接,可直接传入之前搜索获取的 deviceId 直接尝试连接该设备,无需再次进行搜索操作。

支持情况: 微信、支付宝
支持情况: 微信、支付宝、RN

[参考文档](https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.createBLEConnection.html)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
## mpx.getBLEDeviceCharacteristics(Object object)

获取蓝牙低功耗设备某个服务中所有特征 (characteristic)。

支持情况: 微信、支付宝、RN

[参考文档](https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.getBLEDeviceCharacteristics.html)

### 参数 {#parameters}
**Object object**

| 属性 | 类型 | 默认值 | 必填 | 说明 |
| --- | --- | --- | --- | --- |
| deviceId | string | | 是 | 蓝牙设备 id。需要已经通过 wx.createBLEConnection 建立连接 |
| serviceId | string | | 是 | 蓝牙服务 UUID。需要先调用 wx.getBLEDeviceServices 获取 |
| success | function | | 否 | 接口调用成功的回调函数 |
| fail | function | | 否 | 接口调用失败的回调函数 |
| complete | function | | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)|

### object.success 回调函数
**参数**
**Object res**

<table>
<thead>
<tr>
<th>属性</th>
<th>类型</th>
<th>说明</th>
<th>支付宝</th>
<th>RN</th>
</tr>
</thead>
<tbody>
<tr>
<td>characteristics</td>
<td>Array.&lt;Object&gt;</td>
<td>设备特征列表</td>
<td><span style="color: green; font-weight: bold;">✓</span></td>
<td><span style="color: green; font-weight: bold;">✓</span></td>
</tr>
<tr>
<td colspan="5">
<table style="width:100%">
<thead>
<tr>
<th>结构属性</th>
<th>类型</th>
<th>说明</th>
<th>支付宝</th>
<th>RN</th>
</tr>
</thead>
<tbody>
<tr>
<td>uuid</td>
<td>string</td>
<td>蓝牙设备特征的 UUID</td>
<td><span style="color: green; font-weight: bold;">✓</span></td>
<td><span style="color: green; font-weight: bold;">✓</span></td>
</tr>
<tr>
<td>properties</td>
<td>Object</td>
<td>该特征支持的操作类型</td>
<td><span style="color: green; font-weight: bold;">✓</span></td>
<td><span style="color: green; font-weight: bold;">✓</span></td>
</tr>
<tr>
<td colspan="5">
<table style="width:100%">
<thead>
<tr>
<th>结构属性</th>
<th>类型</th>
<th>说明</th>
<th>支付宝</th>
<th>RN</th>
</tr>
</thead>
<tbody>
<tr><td>read</td><td>boolean</td><td>该特征是否支持 read 操作</td><td><span style="color: green; font-weight: bold;">✓</span></td><td><span style="color: green; font-weight: bold;">✓</span></td></tr>
<tr><td>write</td><td>boolean</td><td>该特征是否支持 write 操作</td><td><span style="color: green; font-weight: bold;">✓</span></td><td><span style="color: green; font-weight: bold;">✓</span></td></tr>
<tr><td>notify</td><td>boolean</td><td>该特征是否支持 notify 操作</td><td><span style="color: green; font-weight: bold;">✓</span></td><td><span style="color: green; font-weight: bold;">✓</span></td></tr>
<tr><td>indicate</td><td>boolean</td><td>该特征是否支持 indicate 操作</td><td><span style="color: green; font-weight: bold;">✓</span></td><td><span style="color: green; font-weight: bold;">✓</span></td></tr>
<tr><td>writeNoResponse</td><td>boolean</td><td>该特征是否支持无回复写操作</td><td><span style="color: green; font-weight: bold;">✓</span></td><td><span style="color: green; font-weight: bold;">✓</span></td></tr>
<tr><td>writeDefault</td><td>boolean</td><td>该特征是否支持有回复写操作</td><td><span style="color: green; font-weight: bold;">✓</span></td><td><span style="color: red; font-weight: bold;">✗</span></td></tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>

### 错误 {#error}

| 错误码 | 错误信息 | 说明 | 支付宝 | RN |
| --- | --- | --- | --- | --- |
| 0 | ok | 正常 | **<span style="color: red;">✗</span>** | **<span style="color: green;">✓</span>** |
| -1 | already connect | 已连接 | **<span style="color: red;">✗</span>** | **<span style="color: red;">✗</span>** |
| 10000 | not init | 未初始化蓝牙适配器 | **<span style="color: green;">✓</span>** | **<span style="color: green;">✓</span>** |
| 10001 | not available | 当前蓝牙适配器不可用 | **<span style="color: green;">✓</span>** | **<span style="color: red;">✗</span>** |
| 10002 | no device | 没有找到指定设备 | **<span style="color: green;">✓</span>** | **<span style="color: red;">✗</span>** |
| 10003 | connection fail | 连接失败 | **<span style="color: green;">✓</span>** | **<span style="color: red;">✗</span>** |
| 10004 | no service | 没有找到指定服务 | **<span style="color: green;">✓</span>** | **<span style="color: red;">✗</span>** |
| 10005 | no characteristic | 没有找到指定特征 | **<span style="color: green;">✓</span>** | **<span style="color: red;">✗</span>** |
| 10006 | no connection | 当前连接已断开 | **<span style="color: green;">✓</span>** | **<span style="color: red;">✗</span>** |
| 10007 | property not support | 当前特征不支持此操作 | **<span style="color: green;">✓</span>** | **<span style="color: red;">✗</span>** |
| 10008 | system error | 其余所有系统上报的异常 | **<span style="color: green;">✓</span>** | **<span style="color: red;">✗</span>** |
| 10009 | system not support | Android 系统特有,系统版本低于 4.3 不支持 BLE | **<span style="color: green;">✓</span>** | **<span style="color: red;">✗</span>** |
| 10012 | operate time out | 连接超时 | **<span style="color: green;">✓</span>** | **<span style="color: red;">✗</span>** |
| 10013 | invalid_data | 连接 deviceId 为空或者是格式不正确 | **<span style="color: green;">✓</span>** | **<span style="color: red;">✗</span>** |

### 示例代码 {#example-code}

```js
mpx.getBLEDeviceCharacteristics({
// 这里的 deviceId 需要已经通过 wx.createBLEConnection 与对应设备建立链接
deviceId,
// 这里的 serviceId 需要在 wx.getBLEDeviceServices 接口中获取
serviceId,
success (res) {
console.log('device getBLEDeviceCharacteristics:', res.characteristics)
}
})
```
26 changes: 26 additions & 0 deletions docs-vitepress/api-proxy/device/bluetooth-ble/getBLEDeviceRSSI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## mpx.getBLEDeviceRSSI(Object object)

获取蓝牙低功耗设备的信号强度 (Received Signal Strength Indication, RSSI)。

支持情况: 微信、支付宝、RN

[参考文档](https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.getBLEDeviceRSSI.html)

### 参数 {#parameters}
**Object object**

| 属性 | 类型 | 默认值 | 必填 | 说明 |
| --- | --- | --- | --- | --- |
| deviceId | string | | 是 | 蓝牙设备 id |
| success | function | | 否 | 接口调用成功的回调函数 |
| fail | function | | 否 | 接口调用失败的回调函数 |
| complete | function | | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |


### object.success 回调函数
**参数**
**Object res**

| 属性 | 类型 | 说明 |
| --- | --- | --- |
| RSSI | Number | 信号强度,单位 dBm |
Loading
Loading