mini_program_gizwits_sdk 3.7.2-cozev5 → 3.7.2-kuka

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