mini_program_gizwits_sdk 3.4.8 → 3.4.9-configEvent

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/dist/src/sdk.d.ts CHANGED
@@ -3,6 +3,7 @@ import { OTAEventCallback, OTAProgressEventCallback } from './handler/ble';
3
3
  import { TLogType } from './GizLog';
4
4
  import { IOpenApiDevice, ISafeRegisterReturn, IUnbindReturn } from './services/devices';
5
5
  import { ILoginRes } from './services/login';
6
+ import { ConfigEventData } from './wifiConfig/ConfigBase';
6
7
  interface SyncCallBackParams {
7
8
  event: TSyncEvnet;
8
9
  currentNum?: number;
@@ -29,6 +30,7 @@ export interface ISetCommonDeviceOnboardingDeployProps {
29
30
  }
30
31
  export interface ISetDeviceOnboardingDeployProps extends ISetCommonDeviceOnboardingDeployProps {
31
32
  softAPSSIDPrefix: string;
33
+ eventCallBack: (event: ConfigEventData) => void;
32
34
  }
33
35
  export interface IRandomCodesResult {
34
36
  random_code: string;
@@ -204,7 +206,7 @@ declare class GizwitsMiniSDK {
204
206
  }) => Promise<ISDKResult<IUnbindReturn>>;
205
207
  deviceSafetyRegister: ({ mac, productKey, }: IDeviceSafetyRegisterParams) => Promise<ISDKResult<ISafeRegisterReturn>>;
206
208
  deviceSafetyUnbind: ({ mac, productKey, }: IDeviceSafetyRegisterParams) => Promise<ISDKResult<ISafeRegisterReturn>>;
207
- setDeviceOnboardingDeploy: ({ ssid, bssid, password, mode, timeout, isBind, softAPSSIDPrefix, }: ISetDeviceOnboardingDeployProps) => Promise<ISDKResult<IDevice[]>>;
209
+ setDeviceOnboardingDeploy: ({ ssid, bssid, password, mode, timeout, isBind, softAPSSIDPrefix, eventCallBack }: ISetDeviceOnboardingDeployProps) => Promise<ISDKResult<IDevice[]>>;
208
210
  private setDomain;
209
211
  private deviceSafetyApi;
210
212
  getBindingList: () => Promise<import("./openApiRequest").IServiceResult<IDevice[]>>;
@@ -2,6 +2,11 @@ import { IRandomCodesResult, IResult } from "../sdk";
2
2
  interface IRejectCallback {
3
3
  (result: IResult<unknown>): void;
4
4
  }
5
+ export type TConfigEvent = 'GIZ_CONFIG_START' | 'GIZ_DISCOVER_SUCCESS' | 'GIZ_CONNECT_SUCCESS' | 'GIZ_CONFIG_SEND_SUCCESS' | 'GIZ_CONFIG_RECV_SUCCESS' | 'GIZ_CONFIG_SUCCESS';
6
+ export interface ConfigEventData {
7
+ event: TConfigEvent;
8
+ deviceID?: string;
9
+ }
5
10
  declare class ConfigBase {
6
11
  ssid: string;
7
12
  bssid: string;
@@ -10,6 +15,7 @@ declare class ConfigBase {
10
15
  disableSearchDevice: boolean;
11
16
  specialProductKeySecrets: string[];
12
17
  private timeoutHandler;
18
+ eventCallBack: (event: ConfigEventData) => void;
13
19
  private setDeviceOnboardingDeployRej?;
14
20
  constructor(ssid: string, bssid: string, password: string, specialProductKeys: string[], specialProductKeySecrets: string[]);
15
21
  cleanTimeout: () => void;
@@ -1,14 +1,15 @@
1
1
  import { IRandomCodesResult, IResult } from "../sdk";
2
2
  import { BleHandle } from "../handler/ble";
3
- import ConfigBase from "./ConfigBase";
3
+ import ConfigBase, { ConfigEventData } from "./ConfigBase";
4
4
  interface IArgs {
5
5
  bleDeviceId: string;
6
6
  arrayBuffer: ArrayBuffer;
7
7
  serviceUUIDSuffix?: string;
8
8
  characteristicUUIDSuffix?: string;
9
9
  bleHandle: BleHandle;
10
+ eventCallBack: (event: ConfigEventData) => void;
10
11
  }
11
- export declare function sendBLEConfigCmd({ bleDeviceId, arrayBuffer, serviceUUIDSuffix, characteristicUUIDSuffix, bleHandle }: IArgs): Promise<boolean | void>;
12
+ export declare function sendBLEConfigCmd({ bleDeviceId, arrayBuffer, serviceUUIDSuffix, characteristicUUIDSuffix, bleHandle, eventCallBack }: IArgs): Promise<boolean | void>;
12
13
  interface configBLEDeviceParams {
13
14
  ssid: string;
14
15
  password: string;
@@ -19,6 +20,7 @@ interface ISetDeviceOnboardingDeployProps {
19
20
  timeout: number;
20
21
  isBind: boolean;
21
22
  softAPSSIDPrefix: string;
23
+ eventCallBack: (event: ConfigEventData) => void;
22
24
  }
23
25
  declare class BLEConfig extends ConfigBase {
24
26
  bleHandle: BleHandle;
@@ -38,7 +40,7 @@ declare class BLEConfig extends ConfigBase {
38
40
  success: true;
39
41
  bleDevices?: WechatMiniprogram.BlueToothDevice[];
40
42
  }>;
41
- setDeviceOnboardingDeploy: ({ timeout, isBind, softAPSSIDPrefix, }: ISetDeviceOnboardingDeployProps) => Promise<IResult<IDevice[]>>;
43
+ setDeviceOnboardingDeploy: ({ timeout, isBind, softAPSSIDPrefix, eventCallBack, }: ISetDeviceOnboardingDeployProps) => Promise<IResult<IDevice[]>>;
42
44
  configBLEDevice: ({ ssid, password, softAPSSIDPrefix, }: configBLEDeviceParams) => Promise<IResult<IRandomCodesResult[]>>;
43
45
  }
44
46
  export default BLEConfig;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mini_program_gizwits_sdk",
3
- "version": "3.4.8",
4
- "description": "修正随机码生成方式",
3
+ "version": "3.4.9-configEvent",
4
+ "description": "增加配网回调",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
7
7
  "test": "node_modules/mocha/bin/_mocha -r ts-node/register tests/**/*.spec.ts -file ./tests/setup-wx.js -timeout 60s",
package/src/sdk.ts CHANGED
@@ -41,6 +41,7 @@ import {
41
41
  import ApConfig from './wifiConfig/ap';
42
42
  import BLEConfig from './wifiConfig/ble';
43
43
  import NFCConfig from './wifiConfig/nfc';
44
+ import { ConfigEventData } from './wifiConfig/ConfigBase';
44
45
 
45
46
  const version = sdkConfig.version;
46
47
  interface SyncCallBackParams {
@@ -73,6 +74,7 @@ export interface ISetCommonDeviceOnboardingDeployProps {
73
74
  export interface ISetDeviceOnboardingDeployProps
74
75
  extends ISetCommonDeviceOnboardingDeployProps {
75
76
  softAPSSIDPrefix: string;
77
+ eventCallBack: (event: ConfigEventData) => void, // 配网回调
76
78
  }
77
79
 
78
80
  export interface IRandomCodesResult {
@@ -1391,6 +1393,7 @@ class GizwitsMiniSDK {
1391
1393
  timeout,
1392
1394
  isBind = true,
1393
1395
  softAPSSIDPrefix,
1396
+ eventCallBack
1394
1397
  }: ISetDeviceOnboardingDeployProps): Promise<ISDKResult<IDevice[]>> => {
1395
1398
  if (this.currentWifiConfigHandle) {
1396
1399
  return {
@@ -1408,13 +1411,14 @@ class GizwitsMiniSDK {
1408
1411
  bssid,
1409
1412
  password,
1410
1413
  this.specialProductKeys,
1411
- this.specialProductKeySecrets
1414
+ this.specialProductKeySecrets,
1412
1415
  );
1413
1416
  const data =
1414
1417
  await this.currentWifiConfigHandle.setDeviceOnboardingDeploy({
1415
1418
  timeout,
1416
1419
  isBind,
1417
1420
  softAPSSIDPrefix,
1421
+ eventCallBack,
1418
1422
  });
1419
1423
  this.currentWifiConfigHandle = null;
1420
1424
  const eTime = new Date().getTime();
@@ -1436,6 +1440,7 @@ class GizwitsMiniSDK {
1436
1440
  timeout,
1437
1441
  isBind,
1438
1442
  softAPSSIDPrefix,
1443
+ eventCallBack,
1439
1444
  });
1440
1445
  this.currentWifiConfigHandle = null;
1441
1446
  const eTime = new Date().getTime();
@@ -1470,6 +1475,7 @@ class GizwitsMiniSDK {
1470
1475
  timeout,
1471
1476
  isBind,
1472
1477
  softAPSSIDPrefix,
1478
+ eventCallBack,
1473
1479
  });
1474
1480
  this.currentWifiConfigHandle = null;
1475
1481
  const eTime = new Date().getTime();
@@ -8,6 +8,11 @@ import GizLog from "../GizLog";
8
8
  interface IRejectCallback {
9
9
  (result: IResult<unknown>): void;
10
10
  }
11
+ export type TConfigEvent = 'GIZ_CONFIG_START' | 'GIZ_DISCOVER_SUCCESS' | 'GIZ_CONNECT_SUCCESS' | 'GIZ_CONFIG_SEND_SUCCESS' | 'GIZ_CONFIG_RECV_SUCCESS' | 'GIZ_CONFIG_SUCCESS'
12
+ export interface ConfigEventData {
13
+ event: TConfigEvent;
14
+ deviceID?: string;
15
+ }
11
16
  class ConfigBase {
12
17
  ssid = '';
13
18
  bssid = '';
@@ -16,6 +21,8 @@ class ConfigBase {
16
21
  disableSearchDevice = false;
17
22
  specialProductKeySecrets: string[] = []
18
23
  private timeoutHandler: TimeoutHandle = null;
24
+ eventCallBack: (event: ConfigEventData) => void;
25
+
19
26
  private setDeviceOnboardingDeployRej?: (value: unknown) => void = () => {}; // 保存promise的rej,用于临时中断
20
27
  // private setDeviceOnboardingDeployRes?: (value: unknown) => void = () => {}; // 保存promise的res,用于临时中断
21
28
 
@@ -150,6 +157,9 @@ class ConfigBase {
150
157
  !this.disableSearchDevice && query();
151
158
  } else {
152
159
  // 搜索到设备
160
+ this.eventCallBack?.({
161
+ event: "GIZ_CONFIG_SUCCESS",
162
+ });
153
163
  GizLog.debug('GIZ_SDK: 大循环搜索到设备', data);
154
164
  res({
155
165
  success: true,
@@ -10,7 +10,7 @@ import {
10
10
  getBLEDeviceCharacteristics, getBLEDeviceServices, getBluetoothAdapterState, getBluetoothDevices,
11
11
  notifyBLECharacteristicValueChange, retryConnect, startBluetoothDevicesDiscovery, unpackWriteBLECharacteristicValue
12
12
  } from '../wechatApi';
13
- import ConfigBase from "./ConfigBase";
13
+ import ConfigBase, { ConfigEventData } from "./ConfigBase";
14
14
 
15
15
  interface IArgs {
16
16
  bleDeviceId: string;
@@ -18,6 +18,7 @@ interface IArgs {
18
18
  serviceUUIDSuffix?: string;
19
19
  characteristicUUIDSuffix?: string;
20
20
  bleHandle: BleHandle;
21
+ eventCallBack: (event: ConfigEventData) => void, // 配网回调
21
22
  }
22
23
 
23
24
  const configAck = '0000000303000002';
@@ -27,7 +28,8 @@ export function sendBLEConfigCmd({
27
28
  arrayBuffer,
28
29
  serviceUUIDSuffix = 'abf0',
29
30
  characteristicUUIDSuffix = 'abf7',
30
- bleHandle
31
+ bleHandle,
32
+ eventCallBack
31
33
  }: IArgs) {
32
34
  let sendInterval = null;
33
35
  let closeTimeout = null;
@@ -119,6 +121,10 @@ export function sendBLEConfigCmd({
119
121
  GizLog.debug(
120
122
  'GIZ_SDK: check characteristic and service success',
121
123
  );
124
+ eventCallBack?.({
125
+ event: "GIZ_CONNECT_SUCCESS",
126
+ deviceID: bleDeviceId
127
+ })
122
128
 
123
129
  await notifyBLECharacteristicValueChange(
124
130
  bleDeviceId,
@@ -126,10 +132,19 @@ export function sendBLEConfigCmd({
126
132
  characteristic.uuid
127
133
  );
128
134
 
135
+ eventCallBack?.({
136
+ event: "GIZ_CONFIG_SEND_SUCCESS",
137
+ deviceID: bleDeviceId
138
+ })
139
+
129
140
  // 这里有个问题,模组好像不一定每次都会回
130
141
  const handleBLECharacteristicValueChange = (res: WechatMiniprogram.OnBLECharacteristicValueChangeListenerResult) => {
131
142
  const hexString = ab2hex(res.value);
132
143
  GizLog.debug('GIZ_SDK: 收到设备返回ack', hexString)
144
+ eventCallBack({
145
+ event: "GIZ_CONFIG_RECV_SUCCESS",
146
+ deviceID: bleDeviceId
147
+ })
133
148
  if (hexString === configAck) {
134
149
  // 发送成功
135
150
  bleHandle.removeEventListener("GizBleDeviceData", handleBLECharacteristicValueChange)
@@ -198,13 +213,19 @@ interface ISetDeviceOnboardingDeployProps {
198
213
  timeout: number;
199
214
  isBind: boolean;
200
215
  softAPSSIDPrefix: string;
216
+ eventCallBack: (event: ConfigEventData) => void; // 配网回调
201
217
  }
202
218
 
203
219
 
204
220
  class BLEConfig extends ConfigBase {
205
221
  bleHandle: BleHandle;
206
222
 
207
- constructor(ssid: string, bssid: string, password: string, specialProductKeys: string[], specialProductKeySecrets: string[],bleHandle: BleHandle) {
223
+ constructor(
224
+ ssid: string, bssid: string,
225
+ password: string, specialProductKeys: string[],
226
+ specialProductKeySecrets: string[],
227
+ bleHandle: BleHandle,
228
+ ) {
208
229
  super(ssid, bssid, password,specialProductKeys,specialProductKeySecrets)
209
230
  this.bleHandle = bleHandle;
210
231
  }
@@ -286,8 +307,14 @@ class BLEConfig extends ConfigBase {
286
307
  timeout,
287
308
  isBind = true,
288
309
  softAPSSIDPrefix,
310
+ eventCallBack = (e) => {},
289
311
  }: ISetDeviceOnboardingDeployProps) => {
312
+ this.eventCallBack = eventCallBack;
290
313
  return new Promise<IResult<IDevice[]>>(async (res, rej) => {
314
+ this.eventCallBack?.({
315
+ event: "GIZ_CONFIG_START",
316
+ deviceID: null
317
+ })
291
318
  const ssid = this.ssid;
292
319
  const password = this.password;
293
320
  this.destroy();
@@ -388,6 +415,10 @@ class BLEConfig extends ConfigBase {
388
415
  }
389
416
  const bleDevice = bleDevices.shift();
390
417
  if (bleDevice) {
418
+ this.eventCallBack?.({
419
+ event: "GIZ_DISCOVER_SUCCESS",
420
+ deviceID: bleDevice.deviceId
421
+ })
391
422
  GizLog.debug('GIZ_SDK: startConfigDevice, target device: ', bleDevice);
392
423
  }
393
424
 
@@ -396,7 +427,8 @@ class BLEConfig extends ConfigBase {
396
427
  (await sendBLEConfigCmd({
397
428
  bleDeviceId: bleDevice.deviceId,
398
429
  arrayBuffer: uint8Array.buffer,
399
- bleHandle: this.bleHandle
430
+ bleHandle: this.bleHandle,
431
+ eventCallBack: this.eventCallBack
400
432
  }));
401
433
 
402
434
  if (!success) {