mini_program_gizwits_sdk 3.7.4-cozev5 → 3.7.4-gefeier

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  # 机智云小程序 SDK
4
4
 
5
+
5
6
  ## ⚠️ 重要
6
7
 
7
8
  使用小程序 sdk 前,请在微信开发者后台-开发管理-开发设置-服务器域名添加以下请求地址。
@@ -11,7 +12,6 @@
11
12
  ```txt
12
13
  https://api.gizwits.com
13
14
  https://site.gizwits.com
14
- https://agent.gizwitsapi.com
15
15
  ```
16
16
 
17
17
  - socket 合法域名
@@ -21,16 +21,17 @@ wss://wxstage.gizwits.com
21
21
  wss://wxm2m.gizwits.com
22
22
  ```
23
23
 
24
- - 关于 services
24
+ - 关于services
25
25
 
26
- 为了搜索效率,sdk 会根据`services `过滤蓝牙设备。默认 ['ABF8', 'ABF0', 'F0AB', 'F8AB']。
26
+ 为了搜索效率,sdk会根据`services `过滤蓝牙设备。默认 ['ABF8', 'ABF0', 'F0AB', 'F8AB']。
27
27
  如果有特殊情况,不想用`services `过滤设备,可以
28
28
 
29
29
  ```js
30
- sdk.scanBleDevice(3000, []);
31
- sdk.startAutoScan([]);
30
+ sdk.scanBleDevice(3000, [])
31
+ sdk.startAutoScan([])
32
32
  ```
33
33
 
34
+
34
35
  ## 🔧 安装
35
36
 
36
37
  ```bash
@@ -62,7 +63,7 @@ export default class Index extends Component {
62
63
  private gizSdk: GizwitsSdk;
63
64
 
64
65
  componentDidMount() {
65
- const sdkInitParams = {
66
+ this.gizSdk = new GizwitsSdk({
66
67
  appID: 'appID',
67
68
  appSecret: 'appSecret',
68
69
  productInfo: [
@@ -71,12 +72,9 @@ export default class Index extends Component {
71
72
  productSecret: 'productSecret',
72
73
  },
73
74
  ],
74
- };
75
- if (!this.gizSdk) {
76
- this.gizSdk = new GizwitsSdk(sdkInitParams);
77
- } else {
78
- this.gizSdk.reInit(sdkInitParams);
79
- }
75
+ uid: 'giz_uid', // 必填
76
+ token: 'giz_token', // 必填
77
+ });
80
78
  }
81
79
 
82
80
  render() {
@@ -86,474 +84,106 @@ export default class Index extends Component {
86
84
  ```
87
85
 
88
86
  ## 📋 日志
89
-
90
87
  sdk.setLogLevel("debug")
91
88
 
92
- ## 用户相关
93
-
94
- SDK 提供了两种登录方式:匿名登录和微信登录。
95
-
96
- ### 匿名登录
97
-
98
- ```typescript
99
- // 使用 唯一ID 进行匿名登录
100
- // 适用于 已经有业务后台的场景
101
- const result = await sdk.login(openID);
102
- if (result.success) {
103
- // 登录成功,可以获取到 token 和 uid
104
- const { token, uid } = result.data;
105
- }
106
- ```
107
-
108
- ### 微信登录
109
-
110
- ```typescript
111
- // 使用微信登录 直接登录到 Gizwits
112
- const result = await sdk.wxLogin();
113
- if (result.success) {
114
- // 登录成功,返回数据包含:
115
- // - token: 访问令牌
116
- // - uid: 用户ID
117
- // - expire_at: 令牌过期时间
118
- const { token, uid, expire_at } = result.data;
119
- } else {
120
- // 登录失败
121
- console.error(result.message);
122
- }
123
- ```
124
-
125
- ### 登录结果说明
126
-
127
- 登录成功后会:
128
-
129
- 1. 自动保存 token 和 uid 到全局数据
130
- 2. 更新 WebSocket 连接的认证信息
131
- 3. 返回登录结果,包含:
132
- - token: 访问令牌
133
- - uid: 用户 ID
134
- - expire_at: 令牌过期时间(仅微信登录返回)
135
-
136
- #### 注意事项
137
-
138
- 1. 登录是使用其他功能的前提,建议在初始化 SDK 后立即进行登录
139
- 2. 微信登录需要确保小程序已经获取了用户授权
140
- 3. 登录成功后,SDK 会自动处理 token 的存储和更新
141
-
142
- #### 错误处理
143
-
144
- ```typescript
145
- try {
146
- const result = await sdk.wxLogin();
147
- if (!result.success) {
148
- // 处理登录失败
149
- console.error('登录失败:', result.message);
150
- }
151
- } catch (error) {
152
- // 处理异常
153
- console.error('登录异常:', error);
154
- }
155
- ```
156
-
157
- ## ota
158
-
159
- ### 获取设备当前版本
160
-
161
- 获取设备的软硬件版本信息。
162
-
163
- ```typescript
164
- const result = await sdk.getDeviceVersion(deviceId);
165
- if (result.success) {
166
- // 获取成功
167
- const { soft_version, hard_version } = result.data;
168
- console.log('软件版本:', soft_version);
169
- console.log('硬件版本:', hard_version);
170
- } else {
171
- // 获取失败
172
- console.error('获取版本失败:', result.err);
173
- }
174
- ```
175
-
176
- #### 参数说明
177
-
178
- | 参数 | 类型 | 必填 | 说明 |
179
- | -------- | ------ | ---- | ------- |
180
- | deviceId | string | 是 | 设备 ID |
181
-
182
- #### 返回值说明
183
-
184
- | 字段 | 类型 | 说明 |
185
- | ------------ | ------ | ---------- |
186
- | soft_version | string | 软件版本号 |
187
- | hard_version | string | 硬件版本号 |
188
-
189
- #### 注意事项
190
-
191
- 1. 设备必须已经绑定
192
- 2. 设备必须在线
193
- 3. 版本号格式通常为 x.y.z 的形式
194
-
195
- #### 错误处理
196
-
197
- ```typescript
198
- try {
199
- const result = await sdk.getDeviceVersion(deviceId);
200
-
201
- if (!result.success) {
202
- // 处理获取失败
203
- console.error('获取版本失败:', result.err);
204
- return;
205
- }
206
-
207
- // 获取成功,可以开始使用版本信息
208
- const { soft_version, hard_version } = result.data;
209
- } catch (error) {
210
- // 处理异常
211
- console.error('获取版本异常:', error);
212
- }
213
- ```
214
-
215
- ### 检查更新
216
-
217
- ```typescript
218
- const result = await sdk.checkAvailableUpdates(deviceInfo.id, deviceInfo.soft_version);
219
- console.log('resultresultresult', result);
220
- if (result.success && result.data) {
221
- setUpdateInfo(result.data);
222
- } else {
223
- setUpdateInfo(null);
224
- Taro.showToast({
225
- title: '没有可用的更新',
226
- icon: 'none',
227
- });
228
- }
229
- ```
230
-
231
- ### 开始更新
232
-
233
- ```typescript
234
- const sdk = getGlobalData('gizSdk');
235
- const result = await sdk.startUpdate(deviceInfo.id);
236
- console.log('resultresultresult', result);
237
- ```
238
-
239
- ### 查询进度
240
-
241
- 获取设备 OTA 更新的当前进度。
242
-
243
- ```typescript
244
- const result = await sdk.getOtaStatus(deviceId);
245
- if (result.success) {
246
- if (result.data !== null) {
247
- // 有进度信息,显示进度
248
- console.log('OTA 更新进度:', result.data);
249
- } else {
250
- // 没有进度信息
251
- console.log('暂无 OTA 更新进度');
252
- }
253
- } else {
254
- // 获取进度失败
255
- console.error('获取 OTA 进度失败:', result.err);
256
- }
257
- ```
258
-
259
- #### 参数说明
260
-
261
- | 参数 | 类型 | 必填 | 说明 |
262
- | -------- | ------ | ---- | ------- |
263
- | deviceId | string | 是 | 设备 ID |
264
-
265
- #### 返回值说明
266
-
267
- | 字段 | 类型 | 说明 |
268
- | ---- | -------------- | ----------------------------------------------------- |
269
- | data | number \| null | 更新进度百分比(0-100),如果为 null 表示暂无进度信息 |
270
-
271
- #### 注意事项
272
-
273
- 1. 设备必须已经绑定
274
- 2. 设备必须在线
275
- 3. 只有在进行 OTA 更新时才会返回进度信息
276
- 4. 进度信息有 1 分钟的有效期,超过 1 分钟未更新则返回 null
277
-
278
- #### 错误处理
279
-
280
- ```typescript
281
- try {
282
- const result = await sdk.getOtaStatus(deviceId);
283
-
284
- if (!result.success) {
285
- // 处理获取失败
286
- console.error('获取 OTA 进度失败:', result.err);
287
- return;
288
- }
289
-
290
- // 获取成功,处理进度信息
291
- if (result.data !== null) {
292
- // 有进度信息
293
- console.log('OTA 更新进度:', result.data);
294
- } else {
295
- // 没有进度信息
296
- console.log('暂无 OTA 更新进度');
297
- }
298
- } catch (error) {
299
- // 处理异常
300
- console.error('获取 OTA 进度异常:', error);
301
- }
302
- ```
89
+ ## 📖 API
303
90
 
304
- ## 蓝牙相关
91
+ 小程序相关 API。
305
92
 
306
- ### 初始化蓝牙
93
+ ### sdk.initBle()
307
94
 
308
95
  初始化 sdk 蓝牙能力。使用其他`BLE API`前**必须**进行初始化。
309
96
 
310
- ```typescript
311
- sdk.initBle();
312
- ```
313
-
314
- ### 搜索蓝牙
97
+ ### sdk.scanBleDevice(delay?:number, services?: string[])
315
98
 
316
99
  搜索蓝牙设备。搜索到的蓝牙设备会被 [onScanListChange](#onScanListChange) 事件监听。
317
100
 
318
- ```
319
- // 参数
320
- // - delay: 超时时间。
321
- // - services: 过滤services的条件,不传默认 ['ABF8', 'ABF0', 'F0AB', 'F8AB']
322
-
323
- sdk.scanBleDevice(delay?:number, services?: string[])
324
- ```
101
+ #### 参数
325
102
 
326
- ### 自动搜索
103
+ - delay: 超时时间。
104
+ - services: 过滤services的条件,不传默认 ['ABF8', 'ABF0', 'F0AB', 'F8AB']
327
105
 
328
- 间隔 3s 搜索一次
106
+ ### sdk.startAutoScan(services?: string[])
329
107
 
330
108
  间隔自动搜索蓝牙设备 [onScanListChange](#onScanListChange) 事件监听。
331
109
 
332
- ```typescript
333
- // 参数
334
- // - services: 过滤services的条件,不传默认 ['ABF8', 'ABF0', 'F0AB', 'F8AB']
335
- sdk.startAutoScan(services?: string[])
336
- ```
337
-
338
- ## 设备管理
339
-
340
- ### 获取设备列表
341
-
342
- 刷新设备列表(同时也会在 GizDeviceListNotifications 事件里推送)
343
-
344
- ```typescript
345
- const data = await sdk.getDevices();
346
- console.log(data);
347
- ```
348
-
349
- ### 开始配网
350
-
351
- 配网是将设备连接到 WiFi 网络的过程。SDK 支持多种配网方式:SoftAP、BLE 和 NFC(仅安卓)。
352
-
353
- ```typescript
354
- const result = await sdk.setDeviceOnboardingDeploy({
355
- ssid: 'wifi_ssid', // WiFi 名称
356
- password: 'wifi_password', // WiFi 密码
357
- mode: 3, // 配网模式:0-SoftAP, 3-BLE, 5-NFC
358
- timeout: 60, // 配网超时时间(秒)
359
- productKey: 'product_key', // 产品 Key
360
- isBind: true, // 是否自动绑定设备
361
- softAPSSIDPrefix: 'XPG-GAgent-', // SoftAP 模式下的设备热点前缀,蓝牙配网模式下的蓝牙设备名称
362
- eventCallBack: event => {
363
- // 配网过程事件回调
364
- console.log('配网事件:', event);
365
- },
366
- mac: '123456', // BLE配网下使用mac对蓝牙设备进行过滤
367
- });
368
-
369
- if (result.success) {
370
- // 配网成功,返回配网成功的设备列表
371
- const devices = result.data;
372
- console.log('配网成功:', devices);
373
- } else {
374
- // 配网失败
375
- console.error('配网失败:', result.err);
376
- }
377
- ```
378
-
379
- #### 参数说明
380
-
381
- | 参数 | 类型 | 必填 | 说明 |
382
- | ---------------- | -------- | ---- | -------------------------------- |
383
- | ssid | string | 是 | WiFi 网络名称 |
384
- | password | string | 是 | WiFi 网络密码 |
385
- | mode | number | 是 | 配网模式:0-SoftAP, 3-BLE, 5-NFC |
386
- | timeout | number | 否 | 配网超时时间,单位秒,默认 60 |
387
- | productKey | string | 否 | 产品 Key |
388
- | isBind | boolean | 否 | 是否自动绑定设备,默认 true |
389
- | softAPSSIDPrefix | string | 否 | SoftAP 模式下的设备热点前缀 |
390
- | eventCallBack | function | 否 | 配网过程事件回调 |
391
-
392
- #### 配网模式说明
393
-
394
- 1. **SoftAP 模式 (mode: 0)**
395
-
396
- - 设备会创建一个 WiFi 热点
397
- - 手机需要先连接到设备热点
398
- - 适用于大多数 WiFi 设备
399
-
400
- 2. **BLE 模式 (mode: 3)**
401
-
402
- - 通过蓝牙传输配网信息
403
- - 设备需要支持蓝牙功能
404
- - 适用于支持蓝牙的 WiFi 设备
405
-
406
- 3. **NFC 模式 (mode: 5)**
407
- - 通过 NFC 传输配网信息
408
- - 仅支持安卓设备
409
- - 设备需要支持 NFC 功能
410
-
411
- #### 注意事项
412
-
413
- 1. 配网前确保设备处于配网状态
414
- 2. 确保 WiFi 密码正确
415
- 3. 配网过程中不要切换网络或关闭蓝牙
416
- 4. 如果配网超时,可以调用 `stopDeviceOnboardingDeploy` 停止配网
417
- 5. 配网成功后,设备会自动连接到指定的 WiFi 网络
418
-
419
- #### 错误处理
420
-
421
- ```typescript
422
- try {
423
- const result = await sdk.setDeviceOnboardingDeploy({
424
- ssid: 'wifi_ssid',
425
- password: 'wifi_password',
426
- mode: 3,
427
- });
428
-
429
- if (!result.success) {
430
- // 处理配网失败
431
- console.error('配网失败:', result.err);
432
- return;
433
- }
434
-
435
- // 配网成功,可以开始使用设备
436
- const devices = result.data;
437
- } catch (error) {
438
- // 处理异常
439
- console.error('配网异常:', error);
440
- }
441
- ```
442
-
443
- ### 停止配网
444
-
445
- 取消当前正在进行的配网过程。
446
-
447
- ```typescript
448
- sdk.stopDeviceOnboardingDeploy();
449
- ```
450
-
451
- ### 绑定设备
452
-
453
- 绑定设备到机智云平台,绑定成功后才能进行设备控制和数据交互。
454
-
455
- ```typescript
456
- const result = await sdk.bindRemoteDevice({
457
- mac: 'device_mac', // 设备 MAC 地址
458
- productKey: 'product_key', // 产品 Key
459
- alias: 'device_name', // 可选,设备别名
460
- beOwner: true, // 可选,是否作为设备所有者
461
- });
462
-
463
- if (result.success) {
464
- // 绑定成功
465
- const device = result.data;
466
- console.log('设备绑定成功:', device);
467
- } else {
468
- // 绑定失败
469
- console.error('设备绑定失败:', result.err);
470
- }
471
- ```
472
-
473
- #### 参数说明
110
+ #### 参数
111
+ - services: 过滤services的条件,不传默认 ['ABF8', 'ABF0', 'F0AB', 'F8AB']
474
112
 
475
- | 参数 | 类型 | 必填 | 说明 |
476
- | ---------- | ------- | ---- | ------------------------------- |
477
- | mac | string | 是 | 设备的 MAC 地址 |
478
- | productKey | string | 是 | 产品 Key,用于标识设备类型 |
479
- | alias | string | 否 | 设备别名,用于自定义设备名称 |
480
- | beOwner | boolean | 否 | 是否作为设备所有者,默认为 true |
113
+ ### sdk.deviceSafetyRegister(Object object)
481
114
 
482
- #### 注意事项
115
+ 安全注册目标设备,蓝牙设备绑定前,需要调用这个接口,否则无法发起设备绑定。返回值中可以拿到注册结果。
483
116
 
484
- 1. 绑定前需要确保设备已经注册到机智云平台
485
- 2. 绑定成功后,设备会自动添加到设备列表中
486
- 3. 一个设备只能被一个用户绑定为所有者,但可以被多个用户共享
117
+ #### 参数
487
118
 
488
- #### 错误处理
119
+ - Object object
489
120
 
490
- ```typescript
491
- try {
492
- const result = await sdk.bindRemoteDevice({
493
- mac: 'device_mac',
494
- productKey: 'product_key',
495
- });
121
+ | 属性 | 类型 | 描述 |
122
+ | ---------- | ------ | ------------------ |
123
+ | mac | string | 待注册设备 mac |
124
+ | productKey | string | 待注册设备所属产品 |
496
125
 
497
- if (!result.success) {
498
- // 处理绑定失败
499
- console.error('绑定失败:', result.err);
500
- return;
501
- }
126
+ ### sdk.bindRemoteDevice(Object object)
502
127
 
503
- // 绑定成功,可以开始使用设备
504
- const device = result.data;
505
- } catch (error) {
506
- // 处理异常
507
- console.error('绑定异常:', error);
508
- }
509
- ```
128
+ 绑定远程设备,否则无法发起设备订阅。返回值中可以拿到绑定结果。
510
129
 
511
- ### 解绑设备
130
+ ### sdk.unbindDevice({devices: [IDevice]})
512
131
 
513
- ```typescript
514
- sdk.unbindDevice({ devices: [{ mac: string, productKey: string }] });
515
- ```
132
+ 解绑设备
516
133
 
517
134
  #### 参数
518
135
 
136
+ - Object object
137
+
519
138
  | 属性 | 类型 | 描述 |
520
139
  | ---------- | ------ | ------------------ |
521
140
  | mac | string | 待绑定设备 mac |
522
141
  | productKey | string | 待绑定设备所属产品 |
523
142
 
524
- ### 获取设备状态
143
+ ### sdk.subscribe(device:[IDevice](#IDevice),connectType:[TConnectType](#TConnectType))
525
144
 
526
- 查询目标设备当前状态,attrNames 不传则查询所有数据
145
+ 订阅目标设备,订阅成功后可控制设备。返回值中可以拿到订阅结果。
527
146
 
528
- ```typescript
529
- sdk.getDeviceStatus(device:[IDevice], attrNames?: string[])
530
- ```
147
+ ### sdk.getDeviceStatus(device:[IDevice](#IDevice), attrNames?: string[])
531
148
 
532
- ### 下发控制指令
149
+ 查询目标设备当前状态,attrNames 不传则查询所有数据
150
+
151
+ ### sdk.write(device:[IDevice](#IDevice),cmd:{[key]:value})
533
152
 
534
153
  向目标设备发送指令。 其中`key`为数据点名称,value 为数据点的值。
535
154
 
536
- ```typescript
537
- sdk.write(device:[IDevice])
155
+ ### sdk.unSubscribe(device:[IDevice](#IDevice))
156
+
157
+ 取消订阅目标设备。蓝牙设备会断开连接。返回值中可拿到取消订阅结果。
158
+
159
+ ### sdk.getDevices()
160
+ 刷新设备列表(同时也会在 GizDeviceListNotifications 事件里推送)
161
+ ```ts
162
+ const data = await sdk.getDevices()
163
+ console.log(data)
538
164
  ```
539
165
 
540
- ## 事件监听
166
+ ### sdk.stopDeviceOnboardingDeploy
167
+ 停止配网
541
168
 
542
- ### 注册事件监听
169
+ ### sdk.setDeviceOnboardingDeploy
170
+ 开始配网
543
171
 
544
- ```typescript
545
- sdk.addEventListener(type, listener);
546
- ```
172
+ 详细参数请查阅类型定义
173
+
174
+ ### sdk.addEventListener(type,listener)
175
+
176
+ #### 概览
547
177
 
548
- | 事件种类 type | 回调参数类型 | 回调参数描述 |
549
- | ---------------------------- | --------------------------------------- | -------------------- |
550
- | GizDeviceListNotifications | [IDevice[]](#IDevice) | 设备列表变更 |
551
- | GizDeviceStatusNotifications | [IDeviceStatusNoti](#IDeviceStatusNoti) | 设备在线状态变更 |
552
- | GizDeviceAttrsNotifications | [IDeviceAttrsNoti](#IDeviceAttrsNoti) | 设备数据点变更通知 |
553
- | onScanListChange | [IDevice[]](#IDevice) | 扫描设备列表变更通知 |
554
- | onBleHandleError | [IError](#IError) | ble 错误通知 |
178
+ | 事件种类 type | 回调参数类型 | 回调参数描述 |
179
+ | --------------------------- | ------------------------------------- | -------------------- |
180
+ | GizDeviceListNotifications | [IDevice[]](#IDevice) | 设备列表变更 |
181
+ | GizDeviceStatusNotifications | [IDeviceStatusNoti](#IDeviceStatusNoti) | 设备在线状态变更 |
182
+ | GizDeviceAttrsNotifications | [IDeviceAttrsNoti](#IDeviceAttrsNoti) | 设备数据点变更通知 |
183
+ | onScanListChange | [IDevice[]](#IDevice) | 扫描设备列表变更通知 |
184
+ | onBleHandleError | [IError](#IError) | ble 错误通知 |
555
185
 
556
- #### GizDeviceListNotifications
186
+ - <a id="GizDeviceListNotifications"> GizDeviceListNotifications </a>
557
187
 
558
188
  ```ts
559
189
  this.gizSdk.addEventListener('GizDeviceListNotifications', (deviceList: IDevice[]) => {
@@ -561,7 +191,7 @@ this.gizSdk.addEventListener('GizDeviceListNotifications', (deviceList: IDevice[
561
191
  });
562
192
  ```
563
193
 
564
- #### GizDeviceStatusNotifications
194
+ - <a id="GizDeviceStatusNotifications"> GizDeviceStatusNotifications </a>
565
195
 
566
196
  ```ts
567
197
  this.gizSdk.addEventListener('GizDeviceStatusNotifications', (e: IDeviceStatusNoti) => {
@@ -569,9 +199,7 @@ this.gizSdk.addEventListener('GizDeviceStatusNotifications', (e: IDeviceStatusNo
569
199
  });
570
200
  ```
571
201
 
572
- #### onScanListChange
573
-
574
- 蓝牙扫描的设备回调
202
+ - <a id="onScanListChange">onScanListChange</a>
575
203
 
576
204
  ```ts
577
205
  const initBle = () => {
@@ -592,7 +220,7 @@ initBle();
592
220
  scanBle();
593
221
  ```
594
222
 
595
- #### GizDeviceAttrsNotifications
223
+ - <a id="GizDeviceAttrsNotifications">GizDeviceAttrsNotifications</a>
596
224
 
597
225
  监听设备上报数据。
598
226
 
@@ -605,9 +233,9 @@ this.gizSdk.addEventListener(
605
233
  );
606
234
  ```
607
235
 
608
- ## 类型定义
236
+ #### 类型定义
609
237
 
610
- ### IDevice
238
+ - <a id="IDevice">IDevice</a>
611
239
 
612
240
  ```ts
613
241
  interface IDevice {
@@ -625,14 +253,14 @@ interface IDevice {
625
253
  }
626
254
  ```
627
255
 
628
- ### TConnectType
256
+ - <a id="TConnectType">TConnectType</a>
629
257
 
630
258
  ```ts
631
259
  type TConnectType = 'BLE' | 'BLE_BROADCAST' | 'LAN' | 'WAN' | 'NONE';
632
260
  }
633
261
  ```
634
262
 
635
- ### IDeviceAttrsNoti
263
+ - <a id="IDeviceAttrsNoti">IDeviceAttrsNoti</a>
636
264
 
637
265
  ```ts
638
266
  interface IDeviceAttrsNoti {
@@ -641,7 +269,7 @@ interface IDeviceAttrsNoti {
641
269
  }
642
270
  ```
643
271
 
644
- ### IDeviceStatusNoti
272
+ - <a id="IDeviceStatusNoti">IDeviceStatusNoti</a>
645
273
 
646
274
  ```ts
647
275
  interface IDeviceStatusNoti {
@@ -650,7 +278,7 @@ interface IDeviceStatusNoti {
650
278
  }
651
279
  ```
652
280
 
653
- ### TConnectType
281
+ - <a id="TConnectType">TConnectType</a>
654
282
 
655
283
  ```ts
656
284
  type TConnectType = 'BLE' | 'BLE_BROADCAST' | 'LAN' | 'WAN' | 'NONE';
@@ -664,3 +292,111 @@ interface IError {
664
292
  errorMessage?: string; // 错误信息
665
293
  }
666
294
  ```
295
+
296
+ ### sdk.removeEventListener(type:K,func:TListenerType[K])
297
+
298
+ 销毁事件监听。
299
+
300
+ # 配网相关
301
+
302
+ ## 使用方法
303
+
304
+ ```javascript
305
+ import GizwitsSdk, { errorCode } from 'mini_program_gizwits_sdk';
306
+
307
+ const configData = {
308
+ appID: "xxx",
309
+ appSecret: "xxx",
310
+ productInfo: [
311
+ {
312
+ productKey: "xxx",
313
+ productSecret: "xxx",
314
+ },
315
+ ],
316
+ };
317
+ const sdk = new GizwitsSdk(configData);
318
+
319
+ try {
320
+ const data = await sdk.setDeviceOnboardingDeploy({
321
+ ssid: SSID,
322
+ password: password,
323
+ mode: 3, // 蓝牙配网
324
+ // mode:0 // softAp
325
+ timeout: 60,
326
+ softAPSSIDPrefix: 'XPG-GAgent-',
327
+ });
328
+ } catch (error) {
329
+ console.log(error);
330
+ }
331
+ ```
332
+
333
+ 其中`data`代表配网成功的设备。
334
+
335
+ 如果失败的话会返回数据
336
+
337
+ ```javascript
338
+ {
339
+ success: false,
340
+ err: {
341
+ errorCode: 'code',
342
+ errorMessage: 'message',
343
+ }
344
+ }
345
+ ```
346
+
347
+ ```ts
348
+ const errorCode: IErrorCode = {
349
+ GIZ_OPENAPI_DEVICE_NOT_BOUND: {
350
+ errorCode: 9017,
351
+ errorMessage: 'not bind',
352
+ },
353
+ GIZ_SDK_HTTP_REQUEST_FAILED: {
354
+ errorCode: 8099,
355
+ errorMessage: '网络请求失败',
356
+ },
357
+ GIZ_SDK_SDK_NOT_INITIALIZED: {
358
+ errorCode: 8300,
359
+ errorMessage: 'not init',
360
+ },
361
+ CONFIG_TIME_OUT: {
362
+ errorCode: 8023,
363
+ errorMessage: 'Config Timeout',
364
+ },
365
+ WECHAT_ERROR: {
366
+ errorCode: 10000,
367
+ errorMessage: 'wechat error',
368
+ },
369
+ GIZ_SDK_ONBOARDING_STOPPED: {
370
+ errorCode: 8318,
371
+ errorMessage: '配网中断',
372
+ },
373
+ GIZ_SDK_DEVICE_CONFIG_IS_RUNNING: {
374
+ errorCode: 8022,
375
+ errorMessage: '配置正在进行中',
376
+ },
377
+ GIZ_OPENAPI_TOKEN_INVALID: {
378
+ errorCode: 9004,
379
+ errorMessage: 'token 失效',
380
+ },
381
+ GIZ_SDK_BIND_DEVICE_FAILED: {
382
+ errorCode: 8039,
383
+ errorMessage: '设备绑定失败',
384
+ },
385
+ GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON: {
386
+ errorCode: 8281,
387
+ errorMessage: '蓝牙未启用',
388
+ },
389
+ GIZ_SDK_OTHERWISE: {
390
+ errorCode: 8100,
391
+ errorMessage: '',
392
+ },
393
+ GIZ_SDK_DEVICE_NOT_SUBSCRIBED: {
394
+ errorCode: 8029,
395
+ errorMessage: '设备还未订阅',
396
+ },
397
+ GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY: {
398
+ errorCode: 8250,
399
+ errorMessage: '产品类型不在指定范围内',
400
+ },
401
+ };
402
+ ```