mini_program_gizwits_sdk 3.7.0-cozev5 → 3.7.2-cozev5

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 (3) hide show
  1. package/README.md +81 -77
  2. package/dist/index.js +2 -2
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  # 机智云小程序 SDK
4
4
 
5
-
6
5
  ## ⚠️ 重要
7
6
 
8
7
  使用小程序 sdk 前,请在微信开发者后台-开发管理-开发设置-服务器域名添加以下请求地址。
@@ -22,17 +21,16 @@ wss://wxstage.gizwits.com
22
21
  wss://wxm2m.gizwits.com
23
22
  ```
24
23
 
25
- - 关于services
24
+ - 关于 services
26
25
 
27
- 为了搜索效率,sdk会根据`services `过滤蓝牙设备。默认 ['ABF8', 'ABF0', 'F0AB', 'F8AB']。
26
+ 为了搜索效率,sdk 会根据`services `过滤蓝牙设备。默认 ['ABF8', 'ABF0', 'F0AB', 'F8AB']。
28
27
  如果有特殊情况,不想用`services `过滤设备,可以
29
28
 
30
29
  ```js
31
- sdk.scanBleDevice(3000, [])
32
- sdk.startAutoScan([])
30
+ sdk.scanBleDevice(3000, []);
31
+ sdk.startAutoScan([]);
33
32
  ```
34
33
 
35
-
36
34
  ## 🔧 安装
37
35
 
38
36
  ```bash
@@ -83,6 +81,7 @@ export default class Index extends Component {
83
81
  ```
84
82
 
85
83
  ## 📋 日志
84
+
86
85
  sdk.setLogLevel("debug")
87
86
 
88
87
  ## 用户相关
@@ -90,6 +89,7 @@ sdk.setLogLevel("debug")
90
89
  SDK 提供了两种登录方式:匿名登录和微信登录。
91
90
 
92
91
  ### 匿名登录
92
+
93
93
  ```typescript
94
94
  // 使用 唯一ID 进行匿名登录
95
95
  // 适用于 已经有业务后台的场景
@@ -101,6 +101,7 @@ if (result.success) {
101
101
  ```
102
102
 
103
103
  ### 微信登录
104
+
104
105
  ```typescript
105
106
  // 使用微信登录 直接登录到 Gizwits
106
107
  const result = await sdk.wxLogin();
@@ -119,19 +120,22 @@ if (result.success) {
119
120
  ### 登录结果说明
120
121
 
121
122
  登录成功后会:
123
+
122
124
  1. 自动保存 token 和 uid 到全局数据
123
125
  2. 更新 WebSocket 连接的认证信息
124
126
  3. 返回登录结果,包含:
125
127
  - token: 访问令牌
126
- - uid: 用户ID
128
+ - uid: 用户 ID
127
129
  - expire_at: 令牌过期时间(仅微信登录返回)
128
130
 
129
131
  #### 注意事项
132
+
130
133
  1. 登录是使用其他功能的前提,建议在初始化 SDK 后立即进行登录
131
134
  2. 微信登录需要确保小程序已经获取了用户授权
132
135
  3. 登录成功后,SDK 会自动处理 token 的存储和更新
133
136
 
134
137
  #### 错误处理
138
+
135
139
  ```typescript
136
140
  try {
137
141
  const result = await sdk.wxLogin();
@@ -166,14 +170,14 @@ if (result.success) {
166
170
 
167
171
  #### 参数说明
168
172
 
169
- | 参数 | 类型 | 必填 | 说明 |
170
- |------|------|------|------|
171
- | deviceId | string | 是 | 设备 ID |
173
+ | 参数 | 类型 | 必填 | 说明 |
174
+ | -------- | ------ | ---- | ------- |
175
+ | deviceId | string | 是 | 设备 ID |
172
176
 
173
177
  #### 返回值说明
174
178
 
175
- | 字段 | 类型 | 说明 |
176
- |------|------|------|
179
+ | 字段 | 类型 | 说明 |
180
+ | ------------ | ------ | ---------- |
177
181
  | soft_version | string | 软件版本号 |
178
182
  | hard_version | string | 硬件版本号 |
179
183
 
@@ -188,16 +192,15 @@ if (result.success) {
188
192
  ```typescript
189
193
  try {
190
194
  const result = await sdk.getDeviceVersion(deviceId);
191
-
195
+
192
196
  if (!result.success) {
193
197
  // 处理获取失败
194
198
  console.error('获取版本失败:', result.err);
195
199
  return;
196
200
  }
197
-
201
+
198
202
  // 获取成功,可以开始使用版本信息
199
203
  const { soft_version, hard_version } = result.data;
200
-
201
204
  } catch (error) {
202
205
  // 处理异常
203
206
  console.error('获取版本异常:', error);
@@ -205,26 +208,27 @@ try {
205
208
  ```
206
209
 
207
210
  ### 检查更新
211
+
208
212
  ```typescript
209
213
  const result = await sdk.checkAvailableUpdates(deviceInfo.id, deviceInfo.soft_version);
210
- console.log('resultresultresult', result)
214
+ console.log('resultresultresult', result);
211
215
  if (result.success && result.data) {
212
216
  setUpdateInfo(result.data);
213
-
214
217
  } else {
215
218
  setUpdateInfo(null);
216
219
  Taro.showToast({
217
220
  title: '没有可用的更新',
218
- icon: 'none'
219
- })
221
+ icon: 'none',
222
+ });
220
223
  }
221
224
  ```
222
225
 
223
226
  ### 开始更新
227
+
224
228
  ```typescript
225
229
  const sdk = getGlobalData('gizSdk');
226
230
  const result = await sdk.startUpdate(deviceInfo.id);
227
- console.log('resultresultresult', result)
231
+ console.log('resultresultresult', result);
228
232
  ```
229
233
 
230
234
  ### 查询进度
@@ -249,14 +253,14 @@ if (result.success) {
249
253
 
250
254
  #### 参数说明
251
255
 
252
- | 参数 | 类型 | 必填 | 说明 |
253
- |------|------|------|------|
254
- | deviceId | string | 是 | 设备 ID |
256
+ | 参数 | 类型 | 必填 | 说明 |
257
+ | -------- | ------ | ---- | ------- |
258
+ | deviceId | string | 是 | 设备 ID |
255
259
 
256
260
  #### 返回值说明
257
261
 
258
- | 字段 | 类型 | 说明 |
259
- |------|------|------|
262
+ | 字段 | 类型 | 说明 |
263
+ | ---- | -------------- | ----------------------------------------------------- |
260
264
  | data | number \| null | 更新进度百分比(0-100),如果为 null 表示暂无进度信息 |
261
265
 
262
266
  #### 注意事项
@@ -271,13 +275,13 @@ if (result.success) {
271
275
  ```typescript
272
276
  try {
273
277
  const result = await sdk.getOtaStatus(deviceId);
274
-
278
+
275
279
  if (!result.success) {
276
280
  // 处理获取失败
277
281
  console.error('获取 OTA 进度失败:', result.err);
278
282
  return;
279
283
  }
280
-
284
+
281
285
  // 获取成功,处理进度信息
282
286
  if (result.data !== null) {
283
287
  // 有进度信息
@@ -286,7 +290,6 @@ try {
286
290
  // 没有进度信息
287
291
  console.log('暂无 OTA 更新进度');
288
292
  }
289
-
290
293
  } catch (error) {
291
294
  // 处理异常
292
295
  console.error('获取 OTA 进度异常:', error);
@@ -300,10 +303,11 @@ try {
300
303
  初始化 sdk 蓝牙能力。使用其他`BLE API`前**必须**进行初始化。
301
304
 
302
305
  ```typescript
303
- sdk.initBle()
306
+ sdk.initBle();
304
307
  ```
305
308
 
306
309
  ### 搜索蓝牙
310
+
307
311
  搜索蓝牙设备。搜索到的蓝牙设备会被 [onScanListChange](#onScanListChange) 事件监听。
308
312
 
309
313
  ```
@@ -328,14 +332,13 @@ sdk.startAutoScan(services?: string[])
328
332
 
329
333
  ## 设备管理
330
334
 
331
-
332
335
  ### 获取设备列表
333
336
 
334
337
  刷新设备列表(同时也会在 GizDeviceListNotifications 事件里推送)
335
338
 
336
339
  ```typescript
337
- const data = await sdk.getDevices()
338
- console.log(data)
340
+ const data = await sdk.getDevices();
341
+ console.log(data);
339
342
  ```
340
343
 
341
344
  ### 开始配网
@@ -344,16 +347,18 @@ console.log(data)
344
347
 
345
348
  ```typescript
346
349
  const result = await sdk.setDeviceOnboardingDeploy({
347
- ssid: 'wifi_ssid', // WiFi 名称
348
- password: 'wifi_password', // WiFi 密码
349
- mode: 3, // 配网模式:0-SoftAP, 3-BLE, 5-NFC
350
- timeout: 60, // 配网超时时间(秒)
351
- productKey: 'product_key', // 产品 Key
352
- isBind: true, // 是否自动绑定设备
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, // 是否自动绑定设备
353
356
  softAPSSIDPrefix: 'XPG-GAgent-', // SoftAP 模式下的设备热点前缀,蓝牙配网模式下的蓝牙设备名称
354
- eventCallBack: (event) => { // 配网过程事件回调
357
+ eventCallBack: event => {
358
+ // 配网过程事件回调
355
359
  console.log('配网事件:', event);
356
- }
360
+ },
361
+ mac: '123456', // BLE配网下使用mac对蓝牙设备进行过滤
357
362
  });
358
363
 
359
364
  if (result.success) {
@@ -368,25 +373,27 @@ if (result.success) {
368
373
 
369
374
  #### 参数说明
370
375
 
371
- | 参数 | 类型 | 必填 | 说明 |
372
- |------|------|------|------|
373
- | ssid | string | 是 | WiFi 网络名称 |
374
- | password | string | 是 | WiFi 网络密码 |
375
- | mode | number | 是 | 配网模式:0-SoftAP, 3-BLE, 5-NFC |
376
- | timeout | number | 否 | 配网超时时间,单位秒,默认 60 |
377
- | productKey | string | 否 | 产品 Key |
378
- | isBind | boolean | 否 | 是否自动绑定设备,默认 true |
379
- | softAPSSIDPrefix | string | 否 | SoftAP 模式下的设备热点前缀 |
380
- | eventCallBack | function | 否 | 配网过程事件回调 |
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 | 否 | 配网过程事件回调 |
381
386
 
382
387
  #### 配网模式说明
383
388
 
384
389
  1. **SoftAP 模式 (mode: 0)**
390
+
385
391
  - 设备会创建一个 WiFi 热点
386
392
  - 手机需要先连接到设备热点
387
393
  - 适用于大多数 WiFi 设备
388
394
 
389
395
  2. **BLE 模式 (mode: 3)**
396
+
390
397
  - 通过蓝牙传输配网信息
391
398
  - 设备需要支持蓝牙功能
392
399
  - 适用于支持蓝牙的 WiFi 设备
@@ -411,18 +418,17 @@ try {
411
418
  const result = await sdk.setDeviceOnboardingDeploy({
412
419
  ssid: 'wifi_ssid',
413
420
  password: 'wifi_password',
414
- mode: 3
421
+ mode: 3,
415
422
  });
416
-
423
+
417
424
  if (!result.success) {
418
425
  // 处理配网失败
419
426
  console.error('配网失败:', result.err);
420
427
  return;
421
428
  }
422
-
429
+
423
430
  // 配网成功,可以开始使用设备
424
431
  const devices = result.data;
425
-
426
432
  } catch (error) {
427
433
  // 处理异常
428
434
  console.error('配网异常:', error);
@@ -443,10 +449,10 @@ sdk.stopDeviceOnboardingDeploy();
443
449
 
444
450
  ```typescript
445
451
  const result = await sdk.bindRemoteDevice({
446
- mac: 'device_mac', // 设备 MAC 地址
452
+ mac: 'device_mac', // 设备 MAC 地址
447
453
  productKey: 'product_key', // 产品 Key
448
- alias: 'device_name', // 可选,设备别名
449
- beOwner: true // 可选,是否作为设备所有者
454
+ alias: 'device_name', // 可选,设备别名
455
+ beOwner: true, // 可选,是否作为设备所有者
450
456
  });
451
457
 
452
458
  if (result.success) {
@@ -461,12 +467,12 @@ if (result.success) {
461
467
 
462
468
  #### 参数说明
463
469
 
464
- | 参数 | 类型 | 必填 | 说明 |
465
- |------|------|------|------|
466
- | mac | string | 是 | 设备的 MAC 地址 |
467
- | productKey | string | 是 | 产品 Key,用于标识设备类型 |
468
- | alias | string | 否 | 设备别名,用于自定义设备名称 |
469
- | beOwner | boolean | 否 | 是否作为设备所有者,默认为 true |
470
+ | 参数 | 类型 | 必填 | 说明 |
471
+ | ---------- | ------- | ---- | ------------------------------- |
472
+ | mac | string | 是 | 设备的 MAC 地址 |
473
+ | productKey | string | 是 | 产品 Key,用于标识设备类型 |
474
+ | alias | string | 否 | 设备别名,用于自定义设备名称 |
475
+ | beOwner | boolean | 否 | 是否作为设备所有者,默认为 true |
470
476
 
471
477
  #### 注意事项
472
478
 
@@ -480,18 +486,17 @@ if (result.success) {
480
486
  try {
481
487
  const result = await sdk.bindRemoteDevice({
482
488
  mac: 'device_mac',
483
- productKey: 'product_key'
489
+ productKey: 'product_key',
484
490
  });
485
-
491
+
486
492
  if (!result.success) {
487
493
  // 处理绑定失败
488
494
  console.error('绑定失败:', result.err);
489
495
  return;
490
496
  }
491
-
497
+
492
498
  // 绑定成功,可以开始使用设备
493
499
  const device = result.data;
494
-
495
500
  } catch (error) {
496
501
  // 处理异常
497
502
  console.error('绑定异常:', error);
@@ -501,7 +506,7 @@ try {
501
506
  ### 解绑设备
502
507
 
503
508
  ```typescript
504
- sdk.unbindDevice({devices: [{mac: string, productKey: string}]})
509
+ sdk.unbindDevice({ devices: [{ mac: string, productKey: string }] });
505
510
  ```
506
511
 
507
512
  #### 参数
@@ -523,7 +528,6 @@ sdk.getDeviceStatus(device:[IDevice], attrNames?: string[])
523
528
 
524
529
  向目标设备发送指令。 其中`key`为数据点名称,value 为数据点的值。
525
530
 
526
-
527
531
  ```typescript
528
532
  sdk.write(device:[IDevice])
529
533
  ```
@@ -533,16 +537,16 @@ sdk.write(device:[IDevice])
533
537
  ### 注册事件监听
534
538
 
535
539
  ```typescript
536
- sdk.addEventListener(type,listener)
540
+ sdk.addEventListener(type, listener);
537
541
  ```
538
542
 
539
- | 事件种类 type | 回调参数类型 | 回调参数描述 |
540
- | --------------------------- | ------------------------------------- | -------------------- |
541
- | GizDeviceListNotifications | [IDevice[]](#IDevice) | 设备列表变更 |
542
- | GizDeviceStatusNotifications | [IDeviceStatusNoti](#IDeviceStatusNoti) | 设备在线状态变更 |
543
- | GizDeviceAttrsNotifications | [IDeviceAttrsNoti](#IDeviceAttrsNoti) | 设备数据点变更通知 |
544
- | onScanListChange | [IDevice[]](#IDevice) | 扫描设备列表变更通知 |
545
- | onBleHandleError | [IError](#IError) | ble 错误通知 |
543
+ | 事件种类 type | 回调参数类型 | 回调参数描述 |
544
+ | ---------------------------- | --------------------------------------- | -------------------- |
545
+ | GizDeviceListNotifications | [IDevice[]](#IDevice) | 设备列表变更 |
546
+ | GizDeviceStatusNotifications | [IDeviceStatusNoti](#IDeviceStatusNoti) | 设备在线状态变更 |
547
+ | GizDeviceAttrsNotifications | [IDeviceAttrsNoti](#IDeviceAttrsNoti) | 设备数据点变更通知 |
548
+ | onScanListChange | [IDevice[]](#IDevice) | 扫描设备列表变更通知 |
549
+ | onBleHandleError | [IError](#IError) | ble 错误通知 |
546
550
 
547
551
  #### GizDeviceListNotifications
548
552