mini_program_gizwits_sdk 3.2.30 → 3.2.32-FeiSiMan
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/aepApi/aepApiRequest.d.ts +7 -0
- package/dist/src/handler/ble.d.ts +5 -10
- package/dist/src/protocol/Reset.d.ts +8 -0
- package/dist/src/protocol/SetReset.d.ts +7 -0
- package/dist/src/sdk.d.ts +204 -0
- package/dist/src/wifiConfig/ConfigBase.d.ts +2 -1
- package/dist/src/wifiConfig/ble.d.ts +16 -3
- package/dist/src/wifiConfig/nfc/disposeData.d.ts +2 -0
- package/dist/src/wifiConfig/nfc/formatData.d.ts +3 -0
- package/dist/src/wifiConfig/nfc/formatSSID.d.ts +6 -0
- package/dist/src/wifiConfig/nfc/index.d.ts +22 -0
- package/dist/src/wifiConfig/nfc/isIncludedCH.d.ts +1 -0
- package/dist/src/wifiConfig/nfc/nfcAConnect.d.ts +6 -0
- package/dist/src/wifiConfig/nfc/nfcATransceive.d.ts +5 -0
- package/dist/src/wifiConfig/nfc/ssIDToASC.d.ts +1 -0
- package/dist/src/wifiConfig/nfc/stringToGbk.d.ts +1 -0
- package/dist/src/wifiConfig/nfc/transceive.wx.d.ts +2 -0
- package/dist/src/wifiConfig/nfc/types.d.ts +15 -0
- package/package.json +1 -1
- package/src/aepApi/aepApiRequest.ts +62 -0
- package/src/handler/ble.ts +32 -17
- package/src/protocol/Reset.ts +16 -0
- package/src/protocol/SetReset.ts +13 -0
- package/src/protocol/dataPoint.ts +18 -18
- package/src/sdk.ts +129 -36
- package/src/services/devices.ts +92 -4
- package/src/utils.ts +15 -5
- package/src/wifiConfig/ConfigBase.ts +3 -1
- package/src/wifiConfig/ble.ts +86 -26
- package/src/wifiConfig/nfc/disposeData.ts +63 -0
- package/src/wifiConfig/nfc/formatData.ts +46 -0
- package/src/wifiConfig/nfc/formatSSID.ts +59 -0
- package/src/wifiConfig/nfc/index.ts +136 -0
- package/src/wifiConfig/nfc/isIncludedCH.ts +8 -0
- package/src/wifiConfig/nfc/nfcAConnect.ts +30 -0
- package/src/wifiConfig/nfc/nfcATransceive.ts +29 -0
- package/src/wifiConfig/nfc/ssIDToASC.ts +12 -0
- package/src/wifiConfig/nfc/stringToGbk.ts +51 -0
- package/src/wifiConfig/nfc/transceive.wx.ts +124 -0
- package/src/wifiConfig/nfc/types.ts +18 -0
|
@@ -44,6 +44,7 @@ export declare class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
44
44
|
private connectingDevId;
|
|
45
45
|
pks: string[];
|
|
46
46
|
private listenDevOfflineTimer;
|
|
47
|
+
private methodQueue;
|
|
47
48
|
private boradcastTimer;
|
|
48
49
|
private boradcastDataCache;
|
|
49
50
|
private baseServices;
|
|
@@ -52,6 +53,8 @@ export declare class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
52
53
|
private disableScanFlag;
|
|
53
54
|
private peripheralServer;
|
|
54
55
|
private isActive;
|
|
56
|
+
private isInitSuccess;
|
|
57
|
+
private isRunInit;
|
|
55
58
|
private _offlineThreshold;
|
|
56
59
|
set offlineThreshold(value: any);
|
|
57
60
|
get offlineThreshold(): any;
|
|
@@ -79,12 +82,7 @@ export declare class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
79
82
|
success: boolean;
|
|
80
83
|
}>;
|
|
81
84
|
private getBluetoothAdapterState;
|
|
82
|
-
getDeviceStatus: (deviceId: string, productKey: string, gwDid?: string, attrNames?: string[]) => Promise<
|
|
83
|
-
success: boolean;
|
|
84
|
-
message: string;
|
|
85
|
-
} | {
|
|
86
|
-
success: boolean;
|
|
87
|
-
}>;
|
|
85
|
+
getDeviceStatus: (deviceId: string, productKey: string, gwDid?: string, attrNames?: string[]) => Promise<any>;
|
|
88
86
|
private updateDevice;
|
|
89
87
|
private updateCtime;
|
|
90
88
|
private checkDeviceIsChange;
|
|
@@ -125,10 +123,7 @@ export declare class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
125
123
|
success: boolean;
|
|
126
124
|
message?: undefined;
|
|
127
125
|
}>;
|
|
128
|
-
write: (bleDeviceID:
|
|
129
|
-
success: boolean;
|
|
130
|
-
message: string;
|
|
131
|
-
}>;
|
|
126
|
+
write: (bleDeviceID: any, value: any) => Promise<any>;
|
|
132
127
|
disConnectDevice: (deviceId: string) => Promise<{
|
|
133
128
|
err: string;
|
|
134
129
|
success: boolean;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { TLogType } from './GizLog';
|
|
2
|
+
import { IDataPointConfig } from './protocol/DataPoint';
|
|
3
|
+
import { IOpenApiDevice, ISafeRegisterReturn, IUnbindReturn } from './services/devices';
|
|
4
|
+
import { ILoginRes } from './services/login';
|
|
5
|
+
interface SyncCallBackParams {
|
|
6
|
+
event: TSyncEvnet;
|
|
7
|
+
currentNum?: number;
|
|
8
|
+
totalNum?: number;
|
|
9
|
+
message?: string;
|
|
10
|
+
}
|
|
11
|
+
type TSyncEvnet = 'SYNC_START' | 'SYNC_END' | 'SYNC_FAIL' | 'SYNC_CANCEL' | 'SYNC_PROGRESS';
|
|
12
|
+
export type SyncCallBack = (data: SyncCallBackParams) => void;
|
|
13
|
+
export interface ISDKResult<T> {
|
|
14
|
+
data?: T;
|
|
15
|
+
err?: IError;
|
|
16
|
+
message?: string;
|
|
17
|
+
success: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface ISetCommonDeviceOnboardingDeployProps {
|
|
20
|
+
ssid: string;
|
|
21
|
+
bssid?: string;
|
|
22
|
+
password: string;
|
|
23
|
+
timeout: number;
|
|
24
|
+
isBind?: boolean;
|
|
25
|
+
mode?: 0 | 3 | 5;
|
|
26
|
+
softAPSSIDPrefix?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface ISetDeviceOnboardingDeployProps extends ISetCommonDeviceOnboardingDeployProps {
|
|
29
|
+
softAPSSIDPrefix: string;
|
|
30
|
+
}
|
|
31
|
+
export interface IConfigResult {
|
|
32
|
+
mac: string;
|
|
33
|
+
productKey: string;
|
|
34
|
+
}
|
|
35
|
+
export interface IRandomCodesResult {
|
|
36
|
+
random_code: string;
|
|
37
|
+
product_key: string;
|
|
38
|
+
mac: string;
|
|
39
|
+
did: string;
|
|
40
|
+
user_id: string;
|
|
41
|
+
timestamp: number;
|
|
42
|
+
type: string;
|
|
43
|
+
wifi_soft_ver: string;
|
|
44
|
+
lan_proto_ver: string;
|
|
45
|
+
}
|
|
46
|
+
interface IBindRemoteDeviceParams {
|
|
47
|
+
productKey: string;
|
|
48
|
+
mac: string;
|
|
49
|
+
beOwner?: boolean;
|
|
50
|
+
alias?: string;
|
|
51
|
+
}
|
|
52
|
+
interface IDeviceStatusNoti {
|
|
53
|
+
device: IDevice;
|
|
54
|
+
connectType: TConnectType;
|
|
55
|
+
}
|
|
56
|
+
interface IDeviceAttrsNoti {
|
|
57
|
+
device: IDevice;
|
|
58
|
+
data: object;
|
|
59
|
+
}
|
|
60
|
+
export interface TListenerType {
|
|
61
|
+
GizDeviceListNotifications: TDeviceListNotifications;
|
|
62
|
+
GizDeviceStatusNotifications: TDeviceStatusNotifications;
|
|
63
|
+
GizDeviceAttrsNotifications: TDeviceAttrsNotifications;
|
|
64
|
+
onScanListChange: OnScanListChange;
|
|
65
|
+
onBleHandleError: OnBleHandleError;
|
|
66
|
+
}
|
|
67
|
+
type TDeviceListNotifications = (devices: IDevice[]) => void;
|
|
68
|
+
type TDeviceStatusNotifications = (data: IDeviceStatusNoti) => void;
|
|
69
|
+
type TDeviceAttrsNotifications = (data: IDeviceAttrsNoti) => void;
|
|
70
|
+
type OnScanListChange = (devices: IDevice[]) => void;
|
|
71
|
+
type OnBleHandleError = (error: IError) => void;
|
|
72
|
+
interface IDeviceSafetyRegisterParams {
|
|
73
|
+
mac: string;
|
|
74
|
+
productKey: string;
|
|
75
|
+
}
|
|
76
|
+
export interface IResult<T> {
|
|
77
|
+
success: boolean;
|
|
78
|
+
data?: T;
|
|
79
|
+
err?: IError;
|
|
80
|
+
}
|
|
81
|
+
interface ICloudServiceInfo {
|
|
82
|
+
openAPIInfo: string;
|
|
83
|
+
aepAPIInfo: string;
|
|
84
|
+
}
|
|
85
|
+
export type TimeoutHandle = ReturnType<typeof setTimeout> | null;
|
|
86
|
+
export type IntervalHandle = ReturnType<typeof setInterval> | null;
|
|
87
|
+
export interface IProductInfo {
|
|
88
|
+
productKey: string;
|
|
89
|
+
productSecret: string;
|
|
90
|
+
}
|
|
91
|
+
interface GizwitsSdkOption {
|
|
92
|
+
appID: string;
|
|
93
|
+
appSecret: string;
|
|
94
|
+
productInfo: IProductInfo[];
|
|
95
|
+
cloudServiceInfo?: ICloudServiceInfo;
|
|
96
|
+
token?: string;
|
|
97
|
+
uid?: string;
|
|
98
|
+
offlineThreshold?: number;
|
|
99
|
+
accessKey?: string;
|
|
100
|
+
secretKey?: string;
|
|
101
|
+
}
|
|
102
|
+
declare class GizwitsMiniSDK {
|
|
103
|
+
private listenerMap;
|
|
104
|
+
private keepScanTimer;
|
|
105
|
+
private _deviceList;
|
|
106
|
+
private get deviceList();
|
|
107
|
+
private set deviceList(value);
|
|
108
|
+
private _bleDevices;
|
|
109
|
+
get bleDevices(): IDevice[];
|
|
110
|
+
set bleDevices(data: IDevice[]);
|
|
111
|
+
private _lanDevices;
|
|
112
|
+
private get lanDevices();
|
|
113
|
+
private set lanDevices(value);
|
|
114
|
+
private get allDevices();
|
|
115
|
+
private get bleScanDevice();
|
|
116
|
+
private productInfo;
|
|
117
|
+
private currentWifiConfigHandle;
|
|
118
|
+
private _bleHandle;
|
|
119
|
+
private _lanHandle;
|
|
120
|
+
private _gizSocket;
|
|
121
|
+
private offlineThreshold?;
|
|
122
|
+
private syncDataCallBack?;
|
|
123
|
+
private syncDataLengthCallback?;
|
|
124
|
+
private syncTotalNum;
|
|
125
|
+
private syncCurrnetNum;
|
|
126
|
+
private syncDataTimoutTimer;
|
|
127
|
+
private SYNC_TIMEOUT;
|
|
128
|
+
private syncDevice?;
|
|
129
|
+
constructor(props: GizwitsSdkOption);
|
|
130
|
+
private get bleHandle();
|
|
131
|
+
private get lanHandle();
|
|
132
|
+
private get socketHandle();
|
|
133
|
+
private init;
|
|
134
|
+
reInit(props: GizwitsSdkOption): void;
|
|
135
|
+
get specialProductKeys(): string[];
|
|
136
|
+
get specialProductKeySecrets(): string[];
|
|
137
|
+
private handleBleError;
|
|
138
|
+
private handleBleDevices;
|
|
139
|
+
handleLanDevices: (devices: IDevice[]) => void;
|
|
140
|
+
private handleLanDeviceData;
|
|
141
|
+
private handleBleDeviceData;
|
|
142
|
+
private handleSocketDeviceData;
|
|
143
|
+
private handleSocketStatus;
|
|
144
|
+
private notiDeviceList;
|
|
145
|
+
private initLan;
|
|
146
|
+
startAutoScan: (services?: string[]) => void;
|
|
147
|
+
stopAutoScan: () => void;
|
|
148
|
+
setDeviceMeta: <K extends keyof IDevice>(curDev: IDevice, key: K, value: IDevice[K], force?: boolean) => void;
|
|
149
|
+
static getVersion: () => {
|
|
150
|
+
success: boolean;
|
|
151
|
+
data: string;
|
|
152
|
+
};
|
|
153
|
+
initBle: () => Promise<ISDKResult<null>>;
|
|
154
|
+
scanBleDevice: (delay: number, services?: string[]) => Promise<ISDKResult<IDevice[]>>;
|
|
155
|
+
write: (device: IDevice, attrs: object) => Promise<any>;
|
|
156
|
+
writeRaw: (device: IDevice, data: number[]) => Promise<any>;
|
|
157
|
+
setDeviceTimeStamp: (device: IDevice) => Promise<any>;
|
|
158
|
+
syncDeviceData: (device: IDevice, callback?: SyncCallBack) => Promise<any>;
|
|
159
|
+
queryNeedSyncDataLength: (device: IDevice) => Promise<ISDKResult<number>>;
|
|
160
|
+
cancelSyncDeviceData: () => Promise<void>;
|
|
161
|
+
private cleanSyncDeviceData;
|
|
162
|
+
getProductConfig: (pk: string) => Promise<ISDKResult<IDataPointConfig>>;
|
|
163
|
+
stopScanBleDevice: () => void;
|
|
164
|
+
login: (openID: string) => Promise<ISDKResult<ILoginRes>>;
|
|
165
|
+
getDeviceStatus: (device: IDevice, attrNames?: string[]) => Promise<any>;
|
|
166
|
+
subscribe: (device: IDevice, connectType?: TConnectType, _autoGetDeviceStatus?: boolean) => Promise<IResult<any> | {
|
|
167
|
+
success: boolean;
|
|
168
|
+
message: string;
|
|
169
|
+
}>;
|
|
170
|
+
unSubscribe: (device: IDevice) => Promise<{
|
|
171
|
+
success: boolean;
|
|
172
|
+
err: any;
|
|
173
|
+
} | {
|
|
174
|
+
success: boolean;
|
|
175
|
+
}>;
|
|
176
|
+
bindRemoteDevice: ({ mac, productKey, alias, beOwner, }: IBindRemoteDeviceParams) => Promise<ISDKResult<IOpenApiDevice>>;
|
|
177
|
+
unbindDevice: ({ devices, }: {
|
|
178
|
+
devices: IDevice[];
|
|
179
|
+
}) => Promise<ISDKResult<IUnbindReturn>>;
|
|
180
|
+
deviceSafetyRegister: ({ mac, productKey, }: IDeviceSafetyRegisterParams) => Promise<ISDKResult<ISafeRegisterReturn>>;
|
|
181
|
+
deviceSafetyUnbind: ({ mac, productKey, }: IDeviceSafetyRegisterParams) => Promise<ISDKResult<ISafeRegisterReturn>>;
|
|
182
|
+
setDeviceOnboardingDeploy: ({ ssid, bssid, password, mode, timeout, isBind, softAPSSIDPrefix, }: ISetDeviceOnboardingDeployProps) => Promise<ISDKResult<IDevice[]>>;
|
|
183
|
+
private setDomain;
|
|
184
|
+
private deviceSafetyApi;
|
|
185
|
+
getBindingList: () => Promise<{}>;
|
|
186
|
+
getDevices: () => Promise<ISDKResult<IDevice[]>>;
|
|
187
|
+
stopDeviceOnboardingDeploy: () => void;
|
|
188
|
+
setLogLevel: (level: TLogType) => {
|
|
189
|
+
success: boolean;
|
|
190
|
+
err: IError;
|
|
191
|
+
};
|
|
192
|
+
renameDevice: (device: IDevice, name: string) => Promise<import("./openApiRequest").IServiceResult<import("./services/devices").IRenamePropsReturn> | {
|
|
193
|
+
success: boolean;
|
|
194
|
+
message: string;
|
|
195
|
+
}>;
|
|
196
|
+
removeEventListener: <K extends keyof TListenerType>(type: K, func: TListenerType[K]) => {
|
|
197
|
+
success: boolean;
|
|
198
|
+
};
|
|
199
|
+
addEventListener: <K extends keyof TListenerType>(type: K, func: TListenerType[K]) => Promise<{
|
|
200
|
+
success: boolean;
|
|
201
|
+
}>;
|
|
202
|
+
destory: () => void;
|
|
203
|
+
}
|
|
204
|
+
export default GizwitsMiniSDK;
|
|
@@ -4,13 +4,14 @@ interface IRejectCallback {
|
|
|
4
4
|
}
|
|
5
5
|
declare class ConfigBase {
|
|
6
6
|
ssid: string;
|
|
7
|
+
bssid: string;
|
|
7
8
|
password: string;
|
|
8
9
|
specialProductKeys: string[];
|
|
9
10
|
disableSearchDevice: boolean;
|
|
10
11
|
specialProductKeySecrets: string[];
|
|
11
12
|
private timeoutHandler;
|
|
12
13
|
private setDeviceOnboardingDeployRej?;
|
|
13
|
-
constructor(ssid: string, password: string, specialProductKeys: string[], specialProductKeySecrets: string[]);
|
|
14
|
+
constructor(ssid: string, bssid: string, password: string, specialProductKeys: string[], specialProductKeySecrets: string[]);
|
|
14
15
|
cleanTimeout: () => void;
|
|
15
16
|
stopDeviceOnboardingDeploy: () => void;
|
|
16
17
|
hasTimeoutHandler: (cb?: IRejectCallback) => boolean;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IConfigResult, IResult } from "../sdk";
|
|
2
2
|
import { BleHandle } from "../handler/ble";
|
|
3
3
|
import ConfigBase from "./ConfigBase";
|
|
4
|
+
interface IVerifyOnlineResult {
|
|
5
|
+
data: {
|
|
6
|
+
status: number;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
4
9
|
interface IArgs {
|
|
5
10
|
bleDeviceId: string;
|
|
6
11
|
arrayBuffer: ArrayBuffer;
|
|
@@ -22,7 +27,7 @@ interface ISetDeviceOnboardingDeployProps {
|
|
|
22
27
|
}
|
|
23
28
|
declare class BLEConfig extends ConfigBase {
|
|
24
29
|
bleHandle: BleHandle;
|
|
25
|
-
constructor(ssid: string, password: string, specialProductKeys: string[], specialProductKeySecrets: string[], bleHandle: BleHandle);
|
|
30
|
+
constructor(ssid: string, bssid: string, password: string, specialProductKeys: string[], specialProductKeySecrets: string[], bleHandle: BleHandle);
|
|
26
31
|
destroy: () => void;
|
|
27
32
|
isValidBleDevice: (bleDevice: WechatMiniprogram.BlueToothDevice, softAPSSIDPrefix?: string) => boolean;
|
|
28
33
|
enableBluetoothDevicesDescovery: () => Promise<{
|
|
@@ -31,6 +36,14 @@ declare class BLEConfig extends ConfigBase {
|
|
|
31
36
|
} | {
|
|
32
37
|
success: true;
|
|
33
38
|
}>;
|
|
39
|
+
getDeviceLastestOnlineTime: ({ productKey, mac }: {
|
|
40
|
+
productKey: string;
|
|
41
|
+
mac: string;
|
|
42
|
+
}) => Promise<import("../aepApi/aepApiRequest").IServiceResult<IVerifyOnlineResult>>;
|
|
43
|
+
verifyDeviceOnline: ({ productKey, mac }: {
|
|
44
|
+
productKey: string;
|
|
45
|
+
mac: string;
|
|
46
|
+
}) => Promise<IResult<IVerifyOnlineResult>>;
|
|
34
47
|
enableAndGetBluetoothDevices: (softAPSSIDPrefix?: string) => Promise<{
|
|
35
48
|
success: false;
|
|
36
49
|
err: IError;
|
|
@@ -39,6 +52,6 @@ declare class BLEConfig extends ConfigBase {
|
|
|
39
52
|
bleDevices?: WechatMiniprogram.BlueToothDevice[];
|
|
40
53
|
}>;
|
|
41
54
|
setDeviceOnboardingDeploy: ({ timeout, isBind, softAPSSIDPrefix, }: ISetDeviceOnboardingDeployProps) => Promise<IResult<IDevice[]>>;
|
|
42
|
-
configBLEDevice: ({ ssid, password, softAPSSIDPrefix, }: configBLEDeviceParams) => Promise<IResult<
|
|
55
|
+
configBLEDevice: ({ ssid, password, softAPSSIDPrefix, }: configBLEDeviceParams) => Promise<IResult<IConfigResult>>;
|
|
43
56
|
}
|
|
44
57
|
export default BLEConfig;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IRandomCodesResult, IResult } from "../../sdk";
|
|
2
|
+
import ConfigBase from "../ConfigBase";
|
|
3
|
+
interface configDeviceParams {
|
|
4
|
+
ssid: string;
|
|
5
|
+
password: string;
|
|
6
|
+
bssid: string;
|
|
7
|
+
address: string;
|
|
8
|
+
}
|
|
9
|
+
interface ISetDeviceOnboardingDeployProps {
|
|
10
|
+
timeout: number;
|
|
11
|
+
isBind: boolean;
|
|
12
|
+
BSSID: string;
|
|
13
|
+
softAPSSIDPrefix: string;
|
|
14
|
+
}
|
|
15
|
+
declare class NFCConfig extends ConfigBase {
|
|
16
|
+
address: string;
|
|
17
|
+
constructor(ssid: string, bssid: string, password: string, specialProductKeys: string[], specialProductKeySecrets: string[], address: string);
|
|
18
|
+
destroy: () => void;
|
|
19
|
+
configDevice: ({ ssid, password, bssid, address }: configDeviceParams) => Promise<IResult<IRandomCodesResult[]>>;
|
|
20
|
+
setDeviceOnboardingDeploy: ({ timeout, isBind, }: ISetDeviceOnboardingDeployProps) => Promise<IResult<IDevice[]>>;
|
|
21
|
+
}
|
|
22
|
+
export default NFCConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function isIncludedCH(str: string): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ssIDToASC: (SSID: string) => Uint8Array;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function stringToGbk(str: string): Uint8Array;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type PageStateProps = {
|
|
2
|
+
store: {};
|
|
3
|
+
};
|
|
4
|
+
interface WifiInfo {
|
|
5
|
+
SSID: string;
|
|
6
|
+
BSSID: string;
|
|
7
|
+
secure: boolean;
|
|
8
|
+
signalStrength: number;
|
|
9
|
+
frequency: number;
|
|
10
|
+
}
|
|
11
|
+
type IDATA = {
|
|
12
|
+
ArrayBuffer_sign: ArrayBuffer;
|
|
13
|
+
ArrayBuffer_others: ArrayBuffer;
|
|
14
|
+
};
|
|
15
|
+
export { PageStateProps, WifiInfo, IDATA };
|
package/package.json
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import request from '../request';
|
|
2
|
+
import { getGlobalData } from "../globalData";
|
|
3
|
+
import errorCode from '../errorCode';
|
|
4
|
+
|
|
5
|
+
interface IResult<T> {
|
|
6
|
+
data: T;
|
|
7
|
+
errMsg: string;
|
|
8
|
+
statusCode: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface IServiceResult<T> {
|
|
12
|
+
success: boolean;
|
|
13
|
+
data?: T;
|
|
14
|
+
err?: IError;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const aepApiRequest = async <T>(url: string, options: any, needToken: boolean = true): Promise<IServiceResult<T>> => {
|
|
18
|
+
const requestOptions = { ...options };
|
|
19
|
+
const headers: any = {
|
|
20
|
+
'Content-Type': 'application/json',
|
|
21
|
+
'accessKey': getGlobalData('accessKey'),
|
|
22
|
+
'secretKey': getGlobalData('secretKey'),
|
|
23
|
+
};
|
|
24
|
+
if (needToken) {
|
|
25
|
+
headers['Authorization'] = getGlobalData('token');
|
|
26
|
+
}
|
|
27
|
+
requestOptions.header = { ...headers, ...options.headers };
|
|
28
|
+
delete requestOptions.headers;
|
|
29
|
+
const aepApiUrl = getGlobalData('cloudServiceInfo').aepAPIInfo;
|
|
30
|
+
console.log('aepApiRequest', aepApiUrl + url, requestOptions);
|
|
31
|
+
const res = await request<IResult<T>>(aepApiUrl + url, requestOptions);
|
|
32
|
+
console.log('aepApiRequest res', res);
|
|
33
|
+
// 统一封装OPEN API的错误码
|
|
34
|
+
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
35
|
+
return {
|
|
36
|
+
success: true,
|
|
37
|
+
data: res.data
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let baseError = {
|
|
42
|
+
success: false,
|
|
43
|
+
err: {
|
|
44
|
+
errorCode: errorCode.GIZ_SDK_HTTP_REQUEST_FAILED.errorCode,
|
|
45
|
+
errorMessage: '',
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
baseError = {
|
|
50
|
+
success: false,
|
|
51
|
+
err: {
|
|
52
|
+
errorCode: (res.data as any).error_code,
|
|
53
|
+
errorMessage: (res.data as any).error_message,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
} catch (error) {
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
return baseError;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export default aepApiRequest;
|
package/src/handler/ble.ts
CHANGED
|
@@ -144,6 +144,7 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
144
144
|
public pks: string[] = [];
|
|
145
145
|
private listenDevOfflineTimer: any = null;
|
|
146
146
|
|
|
147
|
+
private methodQueue: any = Promise.resolve(); // 发送指令的队列
|
|
147
148
|
private boradcastTimer: any;
|
|
148
149
|
private boradcastDataCache: any = {}
|
|
149
150
|
private baseServices: string[] = ['ABF8', 'ABF0', 'F0AB', 'F8AB'];
|
|
@@ -155,6 +156,8 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
155
156
|
private peripheralServer: WechatMiniprogram.BLEPeripheralServer | null = null;
|
|
156
157
|
|
|
157
158
|
private isActive = true; // 小程序是否活跃
|
|
159
|
+
private isInitSuccess = false;
|
|
160
|
+
private isRunInit = false;
|
|
158
161
|
|
|
159
162
|
private _offlineThreshold = null;
|
|
160
163
|
public set offlineThreshold(value) {
|
|
@@ -199,7 +202,10 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
199
202
|
private onBluetoothAdapterStateChange = (res: WechatMiniprogram.OnBluetoothAdapterStateChangeListenerResult) => {
|
|
200
203
|
GizLog.debug("onBluetoothAdapterStateChange", res)
|
|
201
204
|
if (res.available) {
|
|
202
|
-
|
|
205
|
+
if (this.isRunInit && this.isInitSuccess === false) {
|
|
206
|
+
// 重新初始化蓝牙
|
|
207
|
+
this.init();
|
|
208
|
+
}
|
|
203
209
|
} else {
|
|
204
210
|
// 不可用状态
|
|
205
211
|
this.scanList = [];
|
|
@@ -352,6 +358,7 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
352
358
|
};
|
|
353
359
|
|
|
354
360
|
private init = async () => {
|
|
361
|
+
this.isRunInit = true;
|
|
355
362
|
const { platform } = wx.getSystemInfoSync();
|
|
356
363
|
await this.openBluetoothAdapter();
|
|
357
364
|
if (platform === 'ios') {
|
|
@@ -366,6 +373,7 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
366
373
|
GizLog.error('GIZ_SDK: 广播初始化失败', new Error(JSON.stringify(error)))
|
|
367
374
|
}
|
|
368
375
|
const res = await this.getBluetoothAdapterState();
|
|
376
|
+
this.isInitSuccess = true
|
|
369
377
|
return res;
|
|
370
378
|
}
|
|
371
379
|
|
|
@@ -502,7 +510,6 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
502
510
|
if (targetBleDev) {
|
|
503
511
|
// 存在设备,更新ctime 并更新属性
|
|
504
512
|
const newDevice = BTDevice2GDevice(device, this.pks);
|
|
505
|
-
|
|
506
513
|
if (newDevice.productKey && newDevice.mac) {
|
|
507
514
|
// 广播设备没有 bleWorkStatus
|
|
508
515
|
const isChange = this.checkDeviceIsChange(newDevice, targetBleDev);
|
|
@@ -860,24 +867,32 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
860
867
|
|
|
861
868
|
}
|
|
862
869
|
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
870
|
+
write = async (bleDeviceID, value) => {
|
|
871
|
+
const writeMethod = async () => {
|
|
872
|
+
GizLog.log('app => dev:', ab2hex(value));
|
|
873
|
+
const targetDevice = this.getTargetDevice(bleDeviceID);
|
|
874
|
+
if (targetDevice.serviceId && targetDevice.characteristicId) {
|
|
875
|
+
const unpackRes = await unpackWriteBLECharacteristicValue(
|
|
876
|
+
bleDeviceID,
|
|
877
|
+
targetDevice.serviceId,
|
|
878
|
+
targetDevice.characteristicId,
|
|
879
|
+
value
|
|
880
|
+
);
|
|
881
|
+
return unpackRes;
|
|
882
|
+
}
|
|
883
|
+
return {
|
|
884
|
+
success: false,
|
|
885
|
+
message: 'send cmd error',
|
|
886
|
+
};
|
|
878
887
|
};
|
|
888
|
+
|
|
889
|
+
// 将当前方法添加到方法队列中,并等待前一个方法执行完成后再执行
|
|
890
|
+
this.methodQueue = this.methodQueue.then(writeMethod);
|
|
891
|
+
|
|
892
|
+
return this.methodQueue;
|
|
879
893
|
};
|
|
880
894
|
|
|
895
|
+
|
|
881
896
|
/**
|
|
882
897
|
* @description 断开设备连接
|
|
883
898
|
*/
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import ProtocolBase from "./ProtocolBase";
|
|
2
|
+
import { arrayToString } from "./tool";
|
|
3
|
+
|
|
4
|
+
type IStatus = 0 | 1;
|
|
5
|
+
class Reset extends ProtocolBase {
|
|
6
|
+
status: IStatus = 0; // 0 没有进入重置 1 进入了重置状态
|
|
7
|
+
constructor(data: number[]) {
|
|
8
|
+
super(data);
|
|
9
|
+
this.status = this.content[0] as IStatus;
|
|
10
|
+
}
|
|
11
|
+
static pack = () => {
|
|
12
|
+
return [0,0,0,3,3,0,0,0x61];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default Reset;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import ProtocolBase from "./ProtocolBase";
|
|
2
|
+
import { arrayToString } from "./tool";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
type IStatus = 0 | 1;
|
|
6
|
+
class SetReset extends ProtocolBase {
|
|
7
|
+
status: IStatus = 0; // 0 没有进入重置 1 进入了重置状态
|
|
8
|
+
static pack = (status: IStatus) => {
|
|
9
|
+
return [0,0,0,3,3,0,0,0x63, status];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default SetReset;
|