mini_program_gizwits_sdk 3.4.9 → 3.4.12
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/index.js +3 -3
- package/dist/src/handler/ble.d.ts +1 -1
- package/dist/src/sdk.d.ts +3 -1
- package/dist/src/wifiConfig/ConfigBase.d.ts +8 -2
- package/dist/src/wifiConfig/ble.d.ts +14 -11
- package/package.json +2 -2
- package/src/handler/ble.ts +6 -8
- package/src/sdk.ts +10 -10
- package/src/wifiConfig/ConfigBase.ts +13 -3
- package/src/wifiConfig/ble.ts +274 -215
|
@@ -112,7 +112,7 @@ export declare class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
112
112
|
private updateCtime;
|
|
113
113
|
private checkDeviceIsChange;
|
|
114
114
|
private handleBluetoothDeviceFound;
|
|
115
|
-
startScan: (
|
|
115
|
+
startScan: (delay?: number, services?: string[]) => Promise<IStartScanResult>;
|
|
116
116
|
stopScan: () => Promise<any>;
|
|
117
117
|
disableScan: () => Promise<WechatMiniprogram.BluetoothError>;
|
|
118
118
|
enableScan: () => void;
|
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[]>>;
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import { IRandomCodesResult, IResult } from "../sdk";
|
|
1
|
+
import { IRandomCodesResult, IResult, TimeoutHandle } 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;
|
|
@@ -9,7 +14,8 @@ declare class ConfigBase {
|
|
|
9
14
|
specialProductKeys: string[];
|
|
10
15
|
disableSearchDevice: boolean;
|
|
11
16
|
specialProductKeySecrets: string[];
|
|
12
|
-
|
|
17
|
+
timeoutHandler: TimeoutHandle;
|
|
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,21 @@
|
|
|
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
|
+
type EnableAndGetBluetoothDevicesRes = Promise<{
|
|
5
|
+
success: false;
|
|
6
|
+
err: IError;
|
|
7
|
+
} | {
|
|
8
|
+
success: true;
|
|
9
|
+
bleDevices?: IDevice[];
|
|
10
|
+
}>;
|
|
4
11
|
interface IArgs {
|
|
5
12
|
bleDeviceId: string;
|
|
6
13
|
arrayBuffer: ArrayBuffer;
|
|
7
14
|
serviceUUIDSuffix?: string;
|
|
8
15
|
characteristicUUIDSuffix?: string;
|
|
9
16
|
bleHandle: BleHandle;
|
|
17
|
+
eventCallBack: (event: ConfigEventData) => void;
|
|
10
18
|
}
|
|
11
|
-
export declare function sendBLEConfigCmd({ bleDeviceId, arrayBuffer, serviceUUIDSuffix, characteristicUUIDSuffix, bleHandle }: IArgs): Promise<boolean | void>;
|
|
12
19
|
interface configBLEDeviceParams {
|
|
13
20
|
ssid: string;
|
|
14
21
|
password: string;
|
|
@@ -19,26 +26,22 @@ interface ISetDeviceOnboardingDeployProps {
|
|
|
19
26
|
timeout: number;
|
|
20
27
|
isBind: boolean;
|
|
21
28
|
softAPSSIDPrefix: string;
|
|
29
|
+
eventCallBack: (event: ConfigEventData) => void;
|
|
22
30
|
}
|
|
23
31
|
declare class BLEConfig extends ConfigBase {
|
|
24
32
|
bleHandle: BleHandle;
|
|
25
33
|
constructor(ssid: string, bssid: string, password: string, specialProductKeys: string[], specialProductKeySecrets: string[], bleHandle: BleHandle);
|
|
34
|
+
sendBLEConfigCmd: ({ bleDeviceId, arrayBuffer, serviceUUIDSuffix, characteristicUUIDSuffix, bleHandle, eventCallBack }: IArgs) => Promise<boolean | void>;
|
|
26
35
|
destroy: () => void;
|
|
27
|
-
isValidBleDevice: (
|
|
36
|
+
isValidBleDevice: (device: IDevice, softAPSSIDPrefix?: string) => boolean;
|
|
28
37
|
enableBluetoothDevicesDescovery: () => Promise<{
|
|
29
38
|
success: false;
|
|
30
39
|
err: IError;
|
|
31
40
|
} | {
|
|
32
41
|
success: true;
|
|
33
42
|
}>;
|
|
34
|
-
enableAndGetBluetoothDevices: (softAPSSIDPrefix?: string) =>
|
|
35
|
-
|
|
36
|
-
err: IError;
|
|
37
|
-
} | {
|
|
38
|
-
success: true;
|
|
39
|
-
bleDevices?: WechatMiniprogram.BlueToothDevice[];
|
|
40
|
-
}>;
|
|
41
|
-
setDeviceOnboardingDeploy: ({ timeout, isBind, softAPSSIDPrefix, }: ISetDeviceOnboardingDeployProps) => Promise<IResult<IDevice[]>>;
|
|
43
|
+
enableAndGetBluetoothDevices: (softAPSSIDPrefix?: string) => EnableAndGetBluetoothDevicesRes;
|
|
44
|
+
setDeviceOnboardingDeploy: ({ timeout, isBind, softAPSSIDPrefix, eventCallBack, }: ISetDeviceOnboardingDeployProps) => Promise<IResult<IDevice[]>>;
|
|
42
45
|
configBLEDevice: ({ ssid, password, softAPSSIDPrefix, }: configBLEDeviceParams) => Promise<IResult<IRandomCodesResult[]>>;
|
|
43
46
|
}
|
|
44
47
|
export default BLEConfig;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mini_program_gizwits_sdk",
|
|
3
|
-
"version": "3.4.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "3.4.12",
|
|
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/handler/ble.ts
CHANGED
|
@@ -419,6 +419,10 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
419
419
|
}
|
|
420
420
|
const res = await this.getBluetoothAdapterState();
|
|
421
421
|
this.isInitSuccess = true
|
|
422
|
+
|
|
423
|
+
wx.onBluetoothDeviceFound((resData) => {
|
|
424
|
+
this.handleBluetoothDeviceFound(resData);
|
|
425
|
+
});
|
|
422
426
|
return res;
|
|
423
427
|
}
|
|
424
428
|
|
|
@@ -501,7 +505,6 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
501
505
|
|
|
502
506
|
private handleBluetoothDeviceFound = (
|
|
503
507
|
resData: WechatMiniprogram.OnBluetoothDeviceFoundListenerResult,
|
|
504
|
-
onScanDevice: OnScanDevice
|
|
505
508
|
) => {
|
|
506
509
|
/**
|
|
507
510
|
* TODO
|
|
@@ -565,7 +568,7 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
565
568
|
this.updateDevice(newDevice);
|
|
566
569
|
// GizLog.debug("GIZ_SDK: same device", newDevice, isChange);
|
|
567
570
|
if (isChange) {
|
|
568
|
-
|
|
571
|
+
this.notifyDevices();
|
|
569
572
|
}
|
|
570
573
|
}
|
|
571
574
|
} else {
|
|
@@ -579,7 +582,7 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
579
582
|
const newDevice = BTDevice2GDevice(device, this.pks);
|
|
580
583
|
if (newDevice.productKey && newDevice.mac) {
|
|
581
584
|
this.scanList.push(newDevice);
|
|
582
|
-
|
|
585
|
+
this.notifyDevices();
|
|
583
586
|
}
|
|
584
587
|
}
|
|
585
588
|
}
|
|
@@ -587,7 +590,6 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
587
590
|
};
|
|
588
591
|
|
|
589
592
|
public startScan = async (
|
|
590
|
-
onScanDevice: OnScanDevice,
|
|
591
593
|
delay: number = 5000,
|
|
592
594
|
services?: string[]
|
|
593
595
|
) => {
|
|
@@ -597,10 +599,6 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
597
599
|
}
|
|
598
600
|
}
|
|
599
601
|
return new Promise<IStartScanResult>(async (res) => {
|
|
600
|
-
wx.onBluetoothDeviceFound((resData) => {
|
|
601
|
-
this.handleBluetoothDeviceFound(resData, onScanDevice);
|
|
602
|
-
});
|
|
603
|
-
|
|
604
602
|
GizLog.debug("GIZ_SDK: start scan", delay);
|
|
605
603
|
await wx.startBluetoothDevicesDiscovery({
|
|
606
604
|
// 如果有传的话,就按传入的方式来搜索
|
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 {
|
|
@@ -678,13 +680,9 @@ class GizwitsMiniSDK {
|
|
|
678
680
|
// this.bleDevices = deviceList;
|
|
679
681
|
// }, -1);
|
|
680
682
|
// }
|
|
681
|
-
this.bleHandle.startScan(
|
|
682
|
-
this.bleDevices = deviceList;
|
|
683
|
-
}, -1, services);
|
|
683
|
+
this.bleHandle.startScan( -1, services);
|
|
684
684
|
}, autoTime);
|
|
685
|
-
this.bleHandle.startScan(
|
|
686
|
-
this.bleDevices = deviceList;
|
|
687
|
-
}, -1, services);
|
|
685
|
+
this.bleHandle.startScan(-1, services);
|
|
688
686
|
};
|
|
689
687
|
|
|
690
688
|
/**
|
|
@@ -786,9 +784,7 @@ class GizwitsMiniSDK {
|
|
|
786
784
|
services?: string[]
|
|
787
785
|
): Promise<ISDKResult<IDevice[]>> => {
|
|
788
786
|
this.bleHandle.scanList = [];
|
|
789
|
-
const data = await this.bleHandle.startScan(
|
|
790
|
-
this.bleDevices = deviceList;
|
|
791
|
-
}, delay, services);
|
|
787
|
+
const data = await this.bleHandle.startScan(delay, services);
|
|
792
788
|
return {
|
|
793
789
|
success: true,
|
|
794
790
|
data: data.scanList,
|
|
@@ -1391,6 +1387,7 @@ class GizwitsMiniSDK {
|
|
|
1391
1387
|
timeout,
|
|
1392
1388
|
isBind = true,
|
|
1393
1389
|
softAPSSIDPrefix,
|
|
1390
|
+
eventCallBack
|
|
1394
1391
|
}: ISetDeviceOnboardingDeployProps): Promise<ISDKResult<IDevice[]>> => {
|
|
1395
1392
|
if (this.currentWifiConfigHandle) {
|
|
1396
1393
|
return {
|
|
@@ -1408,13 +1405,14 @@ class GizwitsMiniSDK {
|
|
|
1408
1405
|
bssid,
|
|
1409
1406
|
password,
|
|
1410
1407
|
this.specialProductKeys,
|
|
1411
|
-
this.specialProductKeySecrets
|
|
1408
|
+
this.specialProductKeySecrets,
|
|
1412
1409
|
);
|
|
1413
1410
|
const data =
|
|
1414
1411
|
await this.currentWifiConfigHandle.setDeviceOnboardingDeploy({
|
|
1415
1412
|
timeout,
|
|
1416
1413
|
isBind,
|
|
1417
1414
|
softAPSSIDPrefix,
|
|
1415
|
+
eventCallBack,
|
|
1418
1416
|
});
|
|
1419
1417
|
this.currentWifiConfigHandle = null;
|
|
1420
1418
|
const eTime = new Date().getTime();
|
|
@@ -1436,6 +1434,7 @@ class GizwitsMiniSDK {
|
|
|
1436
1434
|
timeout,
|
|
1437
1435
|
isBind,
|
|
1438
1436
|
softAPSSIDPrefix,
|
|
1437
|
+
eventCallBack,
|
|
1439
1438
|
});
|
|
1440
1439
|
this.currentWifiConfigHandle = null;
|
|
1441
1440
|
const eTime = new Date().getTime();
|
|
@@ -1470,6 +1469,7 @@ class GizwitsMiniSDK {
|
|
|
1470
1469
|
timeout,
|
|
1471
1470
|
isBind,
|
|
1472
1471
|
softAPSSIDPrefix,
|
|
1472
|
+
eventCallBack,
|
|
1473
1473
|
});
|
|
1474
1474
|
this.currentWifiConfigHandle = null;
|
|
1475
1475
|
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 = '';
|
|
@@ -15,7 +20,9 @@ class ConfigBase {
|
|
|
15
20
|
specialProductKeys: string[] = [];
|
|
16
21
|
disableSearchDevice = false;
|
|
17
22
|
specialProductKeySecrets: string[] = []
|
|
18
|
-
|
|
23
|
+
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
|
|
|
@@ -145,11 +152,14 @@ class ConfigBase {
|
|
|
145
152
|
|
|
146
153
|
if (data.err || (data.data as IRandomCodesResult[]).length === 0) {
|
|
147
154
|
// 重新请求
|
|
148
|
-
GizLog.debug('GIZ_SDK: 大循环没有发现设备');
|
|
149
|
-
await sleep(
|
|
155
|
+
// GizLog.debug('GIZ_SDK: 大循环没有发现设备');
|
|
156
|
+
await sleep(250);
|
|
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,
|