mini_program_gizwits_sdk 3.6.1 → 3.6.3
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.d.ts +1 -0
- package/dist/index.js +3 -3
- package/dist/src/GizLog.d.ts +1 -1
- package/dist/src/errorCode.d.ts +1 -3
- package/dist/src/handler/ble.d.ts +5 -66
- package/dist/src/handler/lan.d.ts +3 -18
- package/dist/src/handler/socket.d.ts +1 -0
- package/dist/src/openApiRequest.d.ts +1 -5
- package/dist/src/productConfigFileManage.d.ts +3 -6
- package/dist/src/protocol/OTA/CheckCanOTA.d.ts +1 -1
- package/dist/src/protocol/{DataPoint.d.ts → dataPoint.d.ts} +0 -34
- package/dist/src/randomCode.d.ts +1 -5
- package/dist/src/sdk.d.ts +9 -104
- package/dist/src/services/devices.d.ts +1 -17
- package/dist/src/services/login.d.ts +2 -6
- package/dist/src/services/monitor.d.ts +2 -1
- package/dist/src/services/ota.d.ts +2 -6
- package/dist/src/services/uploadP0.d.ts +2 -1
- package/dist/src/types/index.d.ts +360 -0
- package/dist/src/utils.d.ts +1 -6
- package/dist/src/wechatApi.d.ts +1 -22
- package/dist/src/wifiConfig/ConfigBase.d.ts +2 -9
- package/dist/src/wifiConfig/ap.d.ts +1 -11
- package/dist/src/wifiConfig/ble.d.ts +2 -8
- package/dist/src/wifiConfig/nfc/index.d.ts +2 -2
- package/global.d.ts +3 -19
- package/index.ts +2 -1
- package/package.json +2 -2
- package/src/errorCode.ts +3 -3
- package/src/handler/ble.ts +4 -79
- package/src/handler/lan.ts +3 -24
- package/src/handler/socket.ts +3 -0
- package/src/openApiRequest.ts +2 -14
- package/src/productConfigFileManage.ts +3 -5
- package/src/protocol/OTA/AwaitNoti.ts +0 -2
- package/src/protocol/OTA/CheckCanOTA.ts +1 -2
- package/src/protocol/OTA/OTAPackPackage.ts +1 -1
- package/src/protocol/OTA/PreOTA.ts +2 -3
- package/src/protocol/OTA/ResetPosition.ts +1 -2
- package/src/protocol/dataPoint.ts +1 -42
- package/src/randomCode.ts +1 -12
- package/src/sdk.ts +11 -114
- package/src/services/devices.ts +2 -22
- package/src/services/login.ts +1 -5
- package/src/services/monitor.ts +1 -0
- package/src/services/ota.ts +1 -5
- package/src/services/uploadP0.ts +1 -0
- package/src/types/index.ts +455 -0
- package/src/utils.ts +1 -6
- package/src/wechatApi.ts +1 -22
- package/src/wifiConfig/ConfigBase.ts +2 -10
- package/src/wifiConfig/ap.ts +1 -13
- package/src/wifiConfig/ble.ts +2 -9
- package/src/wifiConfig/nfc/index.ts +1 -4
- package/src/global.d.ts +0 -52
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { TCPHandler } from "../handler/lan";
|
|
2
|
+
import DiscoverUDP from "../protocol/DiscoverUDP";
|
|
3
|
+
import { wrapErrorInfo } from "../utils";
|
|
4
|
+
export type TUtf8 = {
|
|
5
|
+
toBytes: (data: any) => any;
|
|
6
|
+
};
|
|
7
|
+
export type TUtils = {
|
|
8
|
+
utf8: TUtf8;
|
|
9
|
+
};
|
|
10
|
+
export interface ecb {
|
|
11
|
+
new (data: any): any;
|
|
12
|
+
}
|
|
13
|
+
export type TModeOfOperation = {
|
|
14
|
+
ecb: ecb;
|
|
15
|
+
};
|
|
16
|
+
export interface IError {
|
|
17
|
+
errorCode: number;
|
|
18
|
+
errorMessage?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ICommonObj {
|
|
21
|
+
[key: string]: any;
|
|
22
|
+
}
|
|
23
|
+
export interface IDeviceStatusChangedProps {
|
|
24
|
+
did: string;
|
|
25
|
+
attrs: ICommonObj;
|
|
26
|
+
}
|
|
27
|
+
export interface IDeviceRawStatusChangedProps {
|
|
28
|
+
did: string;
|
|
29
|
+
raw: Uint8Array;
|
|
30
|
+
}
|
|
31
|
+
export interface IOnDeviceStatusChanged {
|
|
32
|
+
(data: IDeviceStatusChangedProps | IDeviceRawStatusChangedProps): void;
|
|
33
|
+
}
|
|
34
|
+
export interface IOnSocketStatusChanged {
|
|
35
|
+
(dids: string[], enabled: boolean): void;
|
|
36
|
+
}
|
|
37
|
+
export interface IEmptyFn {
|
|
38
|
+
(): void;
|
|
39
|
+
}
|
|
40
|
+
export interface IDevice {
|
|
41
|
+
mac: string;
|
|
42
|
+
productKey: string;
|
|
43
|
+
did: string;
|
|
44
|
+
bleWorkStatus?: number;
|
|
45
|
+
name: string;
|
|
46
|
+
isBind: boolean;
|
|
47
|
+
rootDeviceId?: string;
|
|
48
|
+
bleDeviceID?: string;
|
|
49
|
+
remark?: string;
|
|
50
|
+
passcode?: string;
|
|
51
|
+
connectType: TConnectType;
|
|
52
|
+
isOnline: boolean;
|
|
53
|
+
isLanOnline: boolean;
|
|
54
|
+
isBleOnline: boolean;
|
|
55
|
+
host?: string;
|
|
56
|
+
wss_port?: number;
|
|
57
|
+
ctime?: number;
|
|
58
|
+
}
|
|
59
|
+
export type TConnectType = 'BLE' | 'BLE_BROADCAST' | 'LAN' | 'WAN' | 'NONE';
|
|
60
|
+
export interface IBluetoothAdapterStateResult {
|
|
61
|
+
discovering: boolean;
|
|
62
|
+
available: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface IWechatResult {
|
|
65
|
+
errMsg: string;
|
|
66
|
+
errCode: number;
|
|
67
|
+
}
|
|
68
|
+
export interface IWXDevicesResult {
|
|
69
|
+
success: true;
|
|
70
|
+
bleDevices: WechatMiniprogram.BlueToothDevice[];
|
|
71
|
+
}
|
|
72
|
+
export interface SyncCallBackParams {
|
|
73
|
+
event: TSyncEvnet;
|
|
74
|
+
currentNum?: number;
|
|
75
|
+
totalNum?: number;
|
|
76
|
+
message?: string;
|
|
77
|
+
}
|
|
78
|
+
export type TSyncEvnet = 'SYNC_START' | 'SYNC_END' | 'SYNC_FAIL' | 'SYNC_CANCEL' | 'SYNC_PROGRESS';
|
|
79
|
+
export type SyncCallBack = (data: SyncCallBackParams) => void;
|
|
80
|
+
export type IOTAType = 'MCU' | 'MODULE';
|
|
81
|
+
export interface ISDKResult<T> {
|
|
82
|
+
data?: T;
|
|
83
|
+
err?: IError;
|
|
84
|
+
message?: string;
|
|
85
|
+
success: boolean;
|
|
86
|
+
}
|
|
87
|
+
export interface ISetCommonDeviceOnboardingDeployProps {
|
|
88
|
+
ssid: string;
|
|
89
|
+
bssid?: string;
|
|
90
|
+
password: string;
|
|
91
|
+
timeout: number;
|
|
92
|
+
isBind?: boolean;
|
|
93
|
+
mode?: 0 | 3 | 5;
|
|
94
|
+
softAPSSIDPrefix?: string;
|
|
95
|
+
}
|
|
96
|
+
export interface ISetDeviceOnboardingDeployProps extends ISetCommonDeviceOnboardingDeployProps {
|
|
97
|
+
softAPSSIDPrefix: string;
|
|
98
|
+
eventCallBack: (event: ConfigEventData) => void;
|
|
99
|
+
}
|
|
100
|
+
export interface IRandomCodesResult {
|
|
101
|
+
random_code: string;
|
|
102
|
+
product_key: string;
|
|
103
|
+
mac: string;
|
|
104
|
+
did: string;
|
|
105
|
+
user_id: string;
|
|
106
|
+
timestamp: number;
|
|
107
|
+
type: string;
|
|
108
|
+
wifi_soft_ver: string;
|
|
109
|
+
lan_proto_ver: string;
|
|
110
|
+
}
|
|
111
|
+
export interface IBindRemoteDeviceParams {
|
|
112
|
+
productKey: string;
|
|
113
|
+
mac: string;
|
|
114
|
+
beOwner?: boolean;
|
|
115
|
+
alias?: string;
|
|
116
|
+
}
|
|
117
|
+
export interface IDeviceStatusNoti {
|
|
118
|
+
device: IDevice;
|
|
119
|
+
connectType: TConnectType;
|
|
120
|
+
}
|
|
121
|
+
export interface IDeviceAttrsNoti {
|
|
122
|
+
device: IDevice;
|
|
123
|
+
data: object;
|
|
124
|
+
}
|
|
125
|
+
export interface TListenerType {
|
|
126
|
+
GizDeviceListNotifications: TDeviceListNotifications;
|
|
127
|
+
GizDeviceStatusNotifications: TDeviceStatusNotifications;
|
|
128
|
+
GizDeviceAttrsNotifications: TDeviceAttrsNotifications;
|
|
129
|
+
onScanListChange: OnScanListChange;
|
|
130
|
+
onBleHandleError: OnBleHandleError;
|
|
131
|
+
}
|
|
132
|
+
export type TDeviceListNotifications = (devices: IDevice[]) => void;
|
|
133
|
+
export type TDeviceStatusNotifications = (data: IDeviceStatusNoti) => void;
|
|
134
|
+
export type TDeviceAttrsNotifications = (data: IDeviceAttrsNoti) => void;
|
|
135
|
+
export type OnScanListChange = (devices: IDevice[]) => void;
|
|
136
|
+
export type OnBleHandleError = (error: IError) => void;
|
|
137
|
+
export interface IDeviceSafetyRegisterParams {
|
|
138
|
+
mac: string;
|
|
139
|
+
productKey: string;
|
|
140
|
+
}
|
|
141
|
+
export interface IDeviceSafetyParams extends IDeviceSafetyRegisterParams {
|
|
142
|
+
isReset: boolean;
|
|
143
|
+
}
|
|
144
|
+
export interface IResult<T> {
|
|
145
|
+
success: boolean;
|
|
146
|
+
data?: T;
|
|
147
|
+
err?: IError;
|
|
148
|
+
}
|
|
149
|
+
export interface ICloudServiceInfo {
|
|
150
|
+
openAPIInfo: string;
|
|
151
|
+
}
|
|
152
|
+
export type TimeoutHandle = ReturnType<typeof setTimeout> | null;
|
|
153
|
+
export type IntervalHandle = ReturnType<typeof setInterval> | null;
|
|
154
|
+
export interface IProductInfo {
|
|
155
|
+
productKey: string;
|
|
156
|
+
productSecret: string;
|
|
157
|
+
}
|
|
158
|
+
export interface GizwitsSdkOption {
|
|
159
|
+
appID: string;
|
|
160
|
+
appSecret: string;
|
|
161
|
+
productInfo: IProductInfo[];
|
|
162
|
+
cloudServiceInfo?: ICloudServiceInfo;
|
|
163
|
+
token?: string;
|
|
164
|
+
uid?: string;
|
|
165
|
+
offlineThreshold?: number;
|
|
166
|
+
}
|
|
167
|
+
export interface IRejectCallback {
|
|
168
|
+
(result: IResult<unknown>): void;
|
|
169
|
+
}
|
|
170
|
+
export type TConfigEvent = 'GIZ_CONFIG_START' | 'GIZ_DISCOVER_SUCCESS' | 'GIZ_CONNECT_SUCCESS' | 'GIZ_CONFIG_SEND_SUCCESS' | 'GIZ_CONFIG_RECV_SUCCESS' | 'GIZ_CONFIG_SUCCESS';
|
|
171
|
+
export interface ConfigEventData {
|
|
172
|
+
event: TConfigEvent;
|
|
173
|
+
deviceID?: string;
|
|
174
|
+
}
|
|
175
|
+
export interface IOpenApiDevice {
|
|
176
|
+
product_key: string;
|
|
177
|
+
did: string;
|
|
178
|
+
mac: string;
|
|
179
|
+
passcode: string;
|
|
180
|
+
is_online: boolean;
|
|
181
|
+
host: string;
|
|
182
|
+
port: string;
|
|
183
|
+
port_s: string;
|
|
184
|
+
ws_port: number;
|
|
185
|
+
wss_port: number;
|
|
186
|
+
dev_alias: string;
|
|
187
|
+
remark: string;
|
|
188
|
+
type: 'normal' | 'center_control' | 'sub_dev';
|
|
189
|
+
}
|
|
190
|
+
export interface IDeviceRes {
|
|
191
|
+
devices: IOpenApiDevice[];
|
|
192
|
+
}
|
|
193
|
+
export interface IErrorCode {
|
|
194
|
+
[key: string]: IError;
|
|
195
|
+
}
|
|
196
|
+
export interface IWechatApiResult<T> {
|
|
197
|
+
data: T;
|
|
198
|
+
errMsg: string;
|
|
199
|
+
statusCode: number;
|
|
200
|
+
}
|
|
201
|
+
export interface IServiceResult<T> {
|
|
202
|
+
success: boolean;
|
|
203
|
+
data?: T;
|
|
204
|
+
err?: IError;
|
|
205
|
+
}
|
|
206
|
+
export interface IGetRandomCodes {
|
|
207
|
+
SSID: string;
|
|
208
|
+
password: string;
|
|
209
|
+
pks: string[];
|
|
210
|
+
}
|
|
211
|
+
export interface IGetRandomCode {
|
|
212
|
+
SSID: string;
|
|
213
|
+
password: string;
|
|
214
|
+
pk: string;
|
|
215
|
+
}
|
|
216
|
+
export interface IProductConfigData {
|
|
217
|
+
[key: string]: IDataPointConfig;
|
|
218
|
+
}
|
|
219
|
+
export interface IDataPointConfig {
|
|
220
|
+
name: string;
|
|
221
|
+
protocolType: 'var_len' | 'standard';
|
|
222
|
+
entities: IDataPointEntitie[];
|
|
223
|
+
}
|
|
224
|
+
export interface IDataPointEntitie {
|
|
225
|
+
display_name: string;
|
|
226
|
+
attrs: IDataPointAttr[];
|
|
227
|
+
}
|
|
228
|
+
export interface IDataPointPosition {
|
|
229
|
+
byte_offset: number;
|
|
230
|
+
unit: 'bit' | 'byte';
|
|
231
|
+
len: number;
|
|
232
|
+
bit_offset: number;
|
|
233
|
+
}
|
|
234
|
+
export type TDataType = 'bool' | 'uint8' | 'uint16' | 'uint32' | 'binary' | 'enum' | 'number';
|
|
235
|
+
export interface IUnitSpec {
|
|
236
|
+
addition: number;
|
|
237
|
+
max: number;
|
|
238
|
+
ratio: number;
|
|
239
|
+
min: number;
|
|
240
|
+
}
|
|
241
|
+
export type TDataOptionType = 'status_writable' | 'status_readonly' | 'alert' | 'fault' | 'ALL';
|
|
242
|
+
export interface IDataPointAttr {
|
|
243
|
+
display_name: string;
|
|
244
|
+
uint_spec: IUnitSpec;
|
|
245
|
+
name: string;
|
|
246
|
+
data_type: TDataType;
|
|
247
|
+
position: IDataPointPosition;
|
|
248
|
+
type: TDataOptionType;
|
|
249
|
+
id: number;
|
|
250
|
+
enum: string[];
|
|
251
|
+
desc: string;
|
|
252
|
+
}
|
|
253
|
+
export type GizBleDeviceListotifications = (devices: IDevice[]) => void;
|
|
254
|
+
export type GizBleDeviceDataNotifications = (curDevice: WechatMiniprogram.OnBLECharacteristicValueChangeListenerResult, hexString: string) => void;
|
|
255
|
+
export type GizBleErrorNotifications = (err: {
|
|
256
|
+
errCode: number;
|
|
257
|
+
errMsg: string;
|
|
258
|
+
}) => void;
|
|
259
|
+
export type TBleDataListener<T> = (_curDevice: WechatMiniprogram.OnBLECharacteristicValueChangeListenerResult, hexString: string) => T | null | undefined;
|
|
260
|
+
export interface CheckOTAParams {
|
|
261
|
+
device: IDevice;
|
|
262
|
+
type: IOTAType;
|
|
263
|
+
}
|
|
264
|
+
export type OTAEventCode = 'GizOTAEventPretreatment' | 'GizOTAEventDownload' | 'GizOTAEventTransmit' | 'GizOTAEventReboot' | 'GizOTAEventFinish';
|
|
265
|
+
export interface OTAEvent {
|
|
266
|
+
code: OTAEventCode;
|
|
267
|
+
}
|
|
268
|
+
export interface OTAProgressEvent {
|
|
269
|
+
firmwareSize: number;
|
|
270
|
+
packageMaxLen: number;
|
|
271
|
+
currentNumber: number;
|
|
272
|
+
currentProgress: number;
|
|
273
|
+
}
|
|
274
|
+
export type OTAProgressEventCallback = (event: OTAProgressEvent) => void;
|
|
275
|
+
export type OTAEventCallback = (event: OTAEvent) => void;
|
|
276
|
+
export interface StartUpgradeParams extends CheckOTAParams {
|
|
277
|
+
onProgress: OTAProgressEventCallback;
|
|
278
|
+
onEvent: OTAEventCallback;
|
|
279
|
+
productKey: string;
|
|
280
|
+
}
|
|
281
|
+
export interface TBleHandleEvent {
|
|
282
|
+
GizBleDeviceData: GizBleDeviceDataNotifications;
|
|
283
|
+
GizBleDeviceList: GizBleDeviceListotifications;
|
|
284
|
+
GizBleError: GizBleErrorNotifications;
|
|
285
|
+
}
|
|
286
|
+
export interface GizwitsWxBlueToothDevice extends WechatMiniprogram.BlueToothDevice {
|
|
287
|
+
communicationType: 'BLE_BROADCAST' | 'BLE';
|
|
288
|
+
}
|
|
289
|
+
export interface BleHandleParams {
|
|
290
|
+
serviceUUIDSuffix: string;
|
|
291
|
+
characteristicUUIDSuffix: string;
|
|
292
|
+
}
|
|
293
|
+
export interface IStartScanResult {
|
|
294
|
+
scanList: IDevice[];
|
|
295
|
+
err?: ReturnType<typeof wrapErrorInfo>;
|
|
296
|
+
}
|
|
297
|
+
export interface IDeviceReq<T> {
|
|
298
|
+
success: boolean;
|
|
299
|
+
data: T;
|
|
300
|
+
}
|
|
301
|
+
export type OnScanDevice = (scanList: IDevice[]) => void;
|
|
302
|
+
export interface BleConnectDevice {
|
|
303
|
+
deviceId?: string;
|
|
304
|
+
serviceId?: string;
|
|
305
|
+
characteristicId?: string;
|
|
306
|
+
errMsg?: string;
|
|
307
|
+
}
|
|
308
|
+
export interface BleConstructorParams {
|
|
309
|
+
pks: string[];
|
|
310
|
+
bleHandleParams?: BleHandleParams;
|
|
311
|
+
offlineThreshold?: number;
|
|
312
|
+
}
|
|
313
|
+
export interface LanConnectDevice {
|
|
314
|
+
mac: string;
|
|
315
|
+
productKey: string;
|
|
316
|
+
socketHandle: TCPHandler;
|
|
317
|
+
}
|
|
318
|
+
export interface ILanDevice extends IDevice {
|
|
319
|
+
expandData: DiscoverUDP;
|
|
320
|
+
ip: string;
|
|
321
|
+
}
|
|
322
|
+
export type GizLanDeviceListNotifications = (devices: IDevice[]) => void;
|
|
323
|
+
export type GizLanDeviceDataNotifications = (mac: string, data: string) => void;
|
|
324
|
+
export interface TLanHandleEvent {
|
|
325
|
+
GizLanDeviceList: GizLanDeviceListNotifications;
|
|
326
|
+
GizLanDeviceData: GizLanDeviceDataNotifications;
|
|
327
|
+
}
|
|
328
|
+
export interface IBLEService {
|
|
329
|
+
uuid: string;
|
|
330
|
+
isPrimary: boolean;
|
|
331
|
+
}
|
|
332
|
+
export interface IBLECharacteristic {
|
|
333
|
+
uuid: string;
|
|
334
|
+
properties: {
|
|
335
|
+
read: boolean;
|
|
336
|
+
write: boolean;
|
|
337
|
+
notify: boolean;
|
|
338
|
+
indicate: boolean;
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
export interface ILoginRes {
|
|
342
|
+
expire_at: number;
|
|
343
|
+
token: string;
|
|
344
|
+
uid: string;
|
|
345
|
+
}
|
|
346
|
+
export interface OTARes {
|
|
347
|
+
download_url: string;
|
|
348
|
+
soft_ver: string;
|
|
349
|
+
}
|
|
350
|
+
export interface configDeviceParams {
|
|
351
|
+
ssid: string;
|
|
352
|
+
password: string;
|
|
353
|
+
softAPSSIDPrefix: string;
|
|
354
|
+
}
|
|
355
|
+
export interface configBLEDeviceParams {
|
|
356
|
+
ssid: string;
|
|
357
|
+
password: string;
|
|
358
|
+
softAPSSIDPrefix?: string;
|
|
359
|
+
timeout: number;
|
|
360
|
+
}
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="crypto-js" />
|
|
2
2
|
import { lib } from "crypto-js/core";
|
|
3
|
-
import { IProductInfo } from
|
|
4
|
-
import { GizwitsWxBlueToothDevice } from './handler/ble';
|
|
3
|
+
import { IDevice, IError, IWXDevicesResult, TConnectType, IProductInfo, GizwitsWxBlueToothDevice } from "./types";
|
|
5
4
|
export declare function ab2hex(buffer: ArrayBuffer): any;
|
|
6
5
|
export declare function compareWXSDKVersion(v1: string, v2: string): 0 | 1 | -1;
|
|
7
6
|
export declare const isError: (err: unknown) => err is IError;
|
|
@@ -10,10 +9,6 @@ export declare const wrapErrorInfo: (errorMessage: string) => {
|
|
|
10
9
|
errorMessage: string;
|
|
11
10
|
};
|
|
12
11
|
export declare const unionBy: <T>(array: T[], key: string) => T[];
|
|
13
|
-
interface IWXDevicesResult {
|
|
14
|
-
success: true;
|
|
15
|
-
bleDevices: WechatMiniprogram.BlueToothDevice[];
|
|
16
|
-
}
|
|
17
12
|
export declare function isWXDevicesResult(res: unknown): res is IWXDevicesResult;
|
|
18
13
|
export declare function str2Buf(arr: string): ArrayBuffer;
|
|
19
14
|
export declare const numberArray2Uint8Array: (numArr: number[]) => Uint8Array;
|
package/dist/src/wechatApi.d.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
discovering: boolean;
|
|
3
|
-
available: boolean;
|
|
4
|
-
}
|
|
5
|
-
export interface IWechatResult {
|
|
6
|
-
errMsg: string;
|
|
7
|
-
errCode: number;
|
|
8
|
-
}
|
|
1
|
+
import { IBluetoothAdapterStateResult, IWechatResult, IBLEService, IBLECharacteristic } from "./types";
|
|
9
2
|
export declare function retryConnect(deviceId: string, timeout?: number): Promise<IWechatResult | {
|
|
10
3
|
success: boolean;
|
|
11
4
|
}>;
|
|
@@ -15,20 +8,7 @@ export declare function getBluetoothAdapterState(): Promise<IBluetoothAdapterSta
|
|
|
15
8
|
export declare function startBluetoothDevicesDiscovery(allowDuplicatesKey?: boolean): Promise<IWechatResult>;
|
|
16
9
|
export declare function getBluetoothDevices(): Promise<WechatMiniprogram.BlueToothDevice[]>;
|
|
17
10
|
export declare function createBLEConnection(deviceId: string, timeout: number): Promise<IWechatResult>;
|
|
18
|
-
interface IBLEService {
|
|
19
|
-
uuid: string;
|
|
20
|
-
isPrimary: boolean;
|
|
21
|
-
}
|
|
22
11
|
export declare function getBLEDeviceServices(deviceId: string): Promise<IBLEService[]>;
|
|
23
|
-
interface IBLECharacteristic {
|
|
24
|
-
uuid: string;
|
|
25
|
-
properties: {
|
|
26
|
-
read: boolean;
|
|
27
|
-
write: boolean;
|
|
28
|
-
notify: boolean;
|
|
29
|
-
indicate: boolean;
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
12
|
export declare function getBLEDeviceCharacteristics(deviceId: string, serviceId: string): Promise<IBLECharacteristic[]>;
|
|
33
13
|
export declare function notifyBLECharacteristicValueChange(deviceId: string, serviceId: string, characteristicId: string, state?: boolean): Promise<IWechatResult>;
|
|
34
14
|
export declare function writeBLECharacteristicValue(deviceId: string, serviceId: string, characteristicId: string, value: ArrayBuffer): Promise<IWechatResult>;
|
|
@@ -37,4 +17,3 @@ export declare function downloadFile({ url }: {
|
|
|
37
17
|
url: any;
|
|
38
18
|
}): Promise<unknown>;
|
|
39
19
|
export declare function setMtu(mtu: number, deviceId: string): Promise<unknown>;
|
|
40
|
-
export {};
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import { IRandomCodesResult, IResult, TimeoutHandle } from "../
|
|
2
|
-
|
|
3
|
-
(result: IResult<unknown>): void;
|
|
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
|
-
}
|
|
1
|
+
import { IRandomCodesResult, IRejectCallback, IResult, TimeoutHandle } from "../types";
|
|
2
|
+
import { ConfigEventData, IDevice } from "../types";
|
|
10
3
|
declare class ConfigBase {
|
|
11
4
|
ssid: string;
|
|
12
5
|
bssid: string;
|
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
import { IRandomCodesResult, IResult } from "../
|
|
1
|
+
import { IDevice, IRandomCodesResult, IResult, configDeviceParams, ISetDeviceOnboardingDeployProps } from "../types";
|
|
2
2
|
import ConfigBase from "./ConfigBase";
|
|
3
|
-
interface configDeviceParams {
|
|
4
|
-
ssid: string;
|
|
5
|
-
password: string;
|
|
6
|
-
softAPSSIDPrefix: string;
|
|
7
|
-
}
|
|
8
|
-
interface ISetDeviceOnboardingDeployProps {
|
|
9
|
-
timeout: number;
|
|
10
|
-
isBind: boolean;
|
|
11
|
-
softAPSSIDPrefix: string;
|
|
12
|
-
}
|
|
13
3
|
declare class ApConfig extends ConfigBase {
|
|
14
4
|
disableSendUDP: boolean;
|
|
15
5
|
private sendMessageInterval;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IRandomCodesResult, IResult } from "../sdk";
|
|
2
1
|
import { BleHandle } from "../handler/ble";
|
|
3
|
-
import ConfigBase
|
|
2
|
+
import ConfigBase from "./ConfigBase";
|
|
3
|
+
import { IDevice, IError, ConfigEventData, IRandomCodesResult, IResult, configBLEDeviceParams } from "../types";
|
|
4
4
|
type EnableAndGetBluetoothDevicesRes = Promise<{
|
|
5
5
|
success: false;
|
|
6
6
|
err: IError;
|
|
@@ -16,12 +16,6 @@ interface IArgs {
|
|
|
16
16
|
bleHandle: BleHandle;
|
|
17
17
|
eventCallBack: (event: ConfigEventData) => void;
|
|
18
18
|
}
|
|
19
|
-
interface configBLEDeviceParams {
|
|
20
|
-
ssid: string;
|
|
21
|
-
password: string;
|
|
22
|
-
softAPSSIDPrefix?: string;
|
|
23
|
-
timeout: number;
|
|
24
|
-
}
|
|
25
19
|
interface ISetDeviceOnboardingDeployProps {
|
|
26
20
|
timeout: number;
|
|
27
21
|
isBind: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IRandomCodesResult, IResult } from "../../sdk";
|
|
2
1
|
import ConfigBase from "../ConfigBase";
|
|
2
|
+
import { IDevice, IResult } from '../../types';
|
|
3
3
|
interface configDeviceParams {
|
|
4
4
|
ssid: string;
|
|
5
5
|
password: string;
|
|
@@ -16,7 +16,7 @@ declare class NFCConfig extends ConfigBase {
|
|
|
16
16
|
address: string;
|
|
17
17
|
constructor(ssid: string, bssid: string, password: string, specialProductKeys: string[], specialProductKeySecrets: string[], address: string);
|
|
18
18
|
destroy: () => void;
|
|
19
|
-
configDevice: ({ ssid, password, bssid, address }: configDeviceParams) => Promise<IResult<IRandomCodesResult[]>>;
|
|
19
|
+
configDevice: ({ ssid, password, bssid, address }: configDeviceParams) => Promise<IResult<import("../../types").IRandomCodesResult[]>>;
|
|
20
20
|
setDeviceOnboardingDeploy: ({ timeout, isBind, }: ISetDeviceOnboardingDeployProps) => Promise<IResult<IDevice[]>>;
|
|
21
21
|
}
|
|
22
22
|
export default NFCConfig;
|
package/global.d.ts
CHANGED
|
@@ -6,23 +6,7 @@ declare namespace md5 {
|
|
|
6
6
|
|
|
7
7
|
declare function md5(data: any): any;
|
|
8
8
|
|
|
9
|
-
type TUtf8 = {
|
|
10
|
-
toBytes: (data: any) => any
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
type TUtils = {
|
|
14
|
-
utf8: TUtf8;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface ecb {
|
|
18
|
-
new(data: any): any;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type TModeOfOperation = {
|
|
22
|
-
ecb: ecb;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
9
|
declare namespace aesjs {
|
|
26
|
-
const utils:
|
|
27
|
-
const ModeOfOperation:
|
|
28
|
-
}
|
|
10
|
+
const utils: any;
|
|
11
|
+
const ModeOfOperation: any;
|
|
12
|
+
}
|
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mini_program_gizwits_sdk",
|
|
3
|
-
"version": "3.6.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "3.6.3",
|
|
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/errorCode.ts
CHANGED
package/src/handler/ble.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import GizLog from '../GizLog';
|
|
2
2
|
import Bind from '../protocol/Bind';
|
|
3
|
-
import { padBoradcastData } from '../protocol/
|
|
3
|
+
import { padBoradcastData } from '../protocol/dataPoint';
|
|
4
4
|
import GetDeviceStatus from '../protocol/GetDeviceStatus';
|
|
5
5
|
import Login from '../protocol/Login';
|
|
6
6
|
import ProtocolBase from '../protocol/ProtocolBase';
|
|
@@ -22,7 +22,6 @@ import {
|
|
|
22
22
|
} from '../utils';
|
|
23
23
|
import { downloadFile, retryConnect, unpackWriteBLECharacteristicValue } from '../wechatApi';
|
|
24
24
|
import EventListener from './EventListener';
|
|
25
|
-
import { IOTAType, IResult } from '../sdk';
|
|
26
25
|
import { checkUpdate } from '../services/ota';
|
|
27
26
|
import errorCode from '../errorCode';
|
|
28
27
|
import DeviceInfo from '../protocol/DeviceInfo';
|
|
@@ -32,82 +31,8 @@ import ResetPosition from '../protocol/OTA/ResetPosition';
|
|
|
32
31
|
import OTAPackPackage from '../protocol/OTA/OTAPackPackage';
|
|
33
32
|
import AwaitNoti from '../protocol/OTA/AwaitNoti';
|
|
34
33
|
import OtaComplete from '../protocol/OTA/OtaComplete';
|
|
34
|
+
import { BleConnectDevice, IDevice, IOTAType, IResult, TBleHandleEvent, BleConstructorParams, GizwitsWxBlueToothDevice, IStartScanResult, TBleDataListener, IDeviceReq, StartUpgradeParams, CheckOTAParams } from '../types';
|
|
35
35
|
|
|
36
|
-
type GizBleDeviceListotifications = (devices: IDevice[]) => void;
|
|
37
|
-
type GizBleDeviceDataNotifications = (
|
|
38
|
-
curDevice: WechatMiniprogram.OnBLECharacteristicValueChangeListenerResult,
|
|
39
|
-
hexString: string
|
|
40
|
-
) => void;
|
|
41
|
-
type GizBleErrorNotifications = (err: { errCode: number; errMsg: string }) => void;
|
|
42
|
-
// 返回true 代表放弃监听
|
|
43
|
-
type TBleDataListener<T> = (_curDevice: WechatMiniprogram.OnBLECharacteristicValueChangeListenerResult,
|
|
44
|
-
hexString: string) => T | null | undefined;
|
|
45
|
-
|
|
46
|
-
interface CheckOTAParams {
|
|
47
|
-
device: IDevice;
|
|
48
|
-
type: IOTAType;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
type OTAEventCode = 'GizOTAEventPretreatment' | 'GizOTAEventDownload' | 'GizOTAEventTransmit' | 'GizOTAEventReboot' | 'GizOTAEventFinish'
|
|
52
|
-
interface OTAEvent {
|
|
53
|
-
code: OTAEventCode; //
|
|
54
|
-
};
|
|
55
|
-
interface OTAProgressEvent {
|
|
56
|
-
firmwareSize: number;
|
|
57
|
-
packageMaxLen: number;
|
|
58
|
-
currentNumber: number;
|
|
59
|
-
currentProgress: number; // 0 ~ 100
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export type OTAProgressEventCallback = (event: OTAProgressEvent) => void;
|
|
63
|
-
export type OTAEventCallback = (event: OTAEvent) => void;
|
|
64
|
-
interface StartUpgradeParams extends CheckOTAParams {
|
|
65
|
-
onProgress: OTAProgressEventCallback
|
|
66
|
-
onEvent: OTAEventCallback
|
|
67
|
-
productKey: string
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
export interface TBleHandleEvent {
|
|
72
|
-
GizBleDeviceData: GizBleDeviceDataNotifications;
|
|
73
|
-
GizBleDeviceList: GizBleDeviceListotifications;
|
|
74
|
-
GizBleError: GizBleErrorNotifications;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export interface GizwitsWxBlueToothDevice extends WechatMiniprogram.BlueToothDevice {
|
|
78
|
-
communicationType: 'BLE_BROADCAST' | 'BLE';
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
interface BleHandleParams {
|
|
82
|
-
serviceUUIDSuffix: string;
|
|
83
|
-
characteristicUUIDSuffix: string;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export interface IStartScanResult {
|
|
87
|
-
scanList: IDevice[];
|
|
88
|
-
err?: ReturnType<typeof wrapErrorInfo>;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
interface IDeviceReq<T> {
|
|
92
|
-
success: boolean;
|
|
93
|
-
data: T;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// export type BleHandle = ReturnType<typeof createBleHandle>;
|
|
97
|
-
|
|
98
|
-
export type OnScanDevice = (scanList: IDevice[]) => void;
|
|
99
|
-
interface ConnectDevice {
|
|
100
|
-
deviceId?: string;
|
|
101
|
-
serviceId?: string;
|
|
102
|
-
characteristicId?: string;
|
|
103
|
-
errMsg?: string;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
interface ConstructorParams {
|
|
107
|
-
pks: string[];
|
|
108
|
-
bleHandleParams?: BleHandleParams;
|
|
109
|
-
offlineThreshold?: number;
|
|
110
|
-
}
|
|
111
36
|
|
|
112
37
|
function createUUID32() {
|
|
113
38
|
let dt = new Date().getTime();
|
|
@@ -180,7 +105,7 @@ function reportConnectEvent(
|
|
|
180
105
|
export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
181
106
|
private serviceUUIDSuffix: string;
|
|
182
107
|
// private characteristicUUIDSuffix: string;
|
|
183
|
-
public connectedList:
|
|
108
|
+
public connectedList: BleConnectDevice[] = [];
|
|
184
109
|
private connectingDevId: string | null = null;
|
|
185
110
|
public pks: string[] = [];
|
|
186
111
|
private listenDevOfflineTimer: any = null;
|
|
@@ -219,7 +144,7 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
219
144
|
characteristicUUIDSuffix: 'abf7',
|
|
220
145
|
},
|
|
221
146
|
offlineThreshold,
|
|
222
|
-
}:
|
|
147
|
+
}: BleConstructorParams) {
|
|
223
148
|
super();
|
|
224
149
|
const { serviceUUIDSuffix } = bleHandleParams;
|
|
225
150
|
this.serviceUUIDSuffix = serviceUUIDSuffix;
|