mini_program_gizwits_sdk 3.4.6-beta → 3.4.7-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 +4 -4
- package/dist/src/aepApi/aepApiRequest.d.ts +7 -0
- package/dist/src/sdk.d.ts +11 -7
- package/dist/src/wifiConfig/ble.d.ts +15 -2
- package/package.json +2 -2
- package/src/aepApi/aepApiRequest.ts +62 -0
- package/src/handler/ble.ts +0 -1
- package/src/protocol/dataPoint.ts +18 -18
- package/src/sdk.ts +56 -32
- package/src/utils.ts +15 -5
- package/src/wifiConfig/ConfigBase.ts +2 -1
- package/src/wifiConfig/ble.ts +82 -22
package/src/wifiConfig/ble.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import errorCode from "../errorCode";
|
|
2
|
-
import {
|
|
2
|
+
import { IConfigResult, IResult } from "../sdk";
|
|
3
3
|
import { ab2hex, advertisData2PkAndMac, isWXDevicesResult } from '../utils';
|
|
4
4
|
|
|
5
5
|
import GizLog from "../GizLog";
|
|
@@ -11,6 +11,14 @@ import {
|
|
|
11
11
|
notifyBLECharacteristicValueChange, retryConnect, startBluetoothDevicesDiscovery, unpackWriteBLECharacteristicValue
|
|
12
12
|
} from '../wechatApi';
|
|
13
13
|
import ConfigBase from "./ConfigBase";
|
|
14
|
+
import aepApiRequest from "../aepApi/aepApiRequest";
|
|
15
|
+
|
|
16
|
+
interface IVerifyOnlineResult {
|
|
17
|
+
data: {
|
|
18
|
+
status: number; // 2表示离线 3表示在线
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
14
22
|
|
|
15
23
|
interface IArgs {
|
|
16
24
|
bleDeviceId: string;
|
|
@@ -260,6 +268,52 @@ class BLEConfig extends ConfigBase {
|
|
|
260
268
|
return { success: true };
|
|
261
269
|
};
|
|
262
270
|
|
|
271
|
+
getDeviceLastestOnlineTime = async ({ productKey, mac }:
|
|
272
|
+
{ productKey: string, mac: string }) => {
|
|
273
|
+
GizLog.debug('GIZ_SDK: getDeviceLastestOnlineTime', mac);
|
|
274
|
+
const res = await aepApiRequest<IVerifyOnlineResult>(`applet/device/getDeviceInfo/${(mac ?? '')}`, { method: 'get' });
|
|
275
|
+
GizLog.debug('GIZ_SDK: 请求结果', res);
|
|
276
|
+
return res;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// 配网后确认设备是否上线
|
|
280
|
+
verifyDeviceOnline = ({ productKey, mac }: { productKey: string, mac: string }) => {
|
|
281
|
+
return new Promise<IResult<IVerifyOnlineResult>>((res, rej) => {
|
|
282
|
+
GizLog.debug('GIZ_SDK: 开始确认设备上线')
|
|
283
|
+
const query = async () => {
|
|
284
|
+
|
|
285
|
+
if (!this.hasTimeoutHandler()) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
try {
|
|
290
|
+
await sleep(2000);
|
|
291
|
+
const data = await this.getDeviceLastestOnlineTime({ productKey, mac })
|
|
292
|
+
GizLog.debug('GIZ_SDK: 确认到设备是否在线', data.data.data.status);
|
|
293
|
+
if (data.success && data.data && data.data.data && data.data.data.status == 3) {
|
|
294
|
+
// 确认设备最后一次上线时间有更新
|
|
295
|
+
GizLog.debug('GIZ_SDK: 确认到设备是在线的', data);
|
|
296
|
+
res({
|
|
297
|
+
success: true,
|
|
298
|
+
data: data.data,
|
|
299
|
+
});
|
|
300
|
+
} else {
|
|
301
|
+
// 重新请求
|
|
302
|
+
GizLog.debug('GIZ_SDK: 未确认到设备是在线');
|
|
303
|
+
await sleep(1500);
|
|
304
|
+
!this.disableSearchDevice && query();
|
|
305
|
+
}
|
|
306
|
+
} catch (error) {
|
|
307
|
+
// 重新请求
|
|
308
|
+
await sleep(3000);
|
|
309
|
+
!this.disableSearchDevice && query();
|
|
310
|
+
// GizLog.debug('GIZ_SDK: random codes error', error);
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
query();
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
|
|
263
317
|
|
|
264
318
|
enableAndGetBluetoothDevices = async (
|
|
265
319
|
softAPSSIDPrefix?: string
|
|
@@ -304,19 +358,20 @@ class BLEConfig extends ConfigBase {
|
|
|
304
358
|
softAPSSIDPrefix,
|
|
305
359
|
});
|
|
306
360
|
|
|
307
|
-
const newData: IDevice[] =
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
}
|
|
361
|
+
const newData: IDevice[] = [result.data as IDevice];
|
|
362
|
+
// const newData: IDevice[] = (result.data || []).map(item => {
|
|
363
|
+
// return {
|
|
364
|
+
// mac: item.mac,
|
|
365
|
+
// productKey: item.product_key,
|
|
366
|
+
// did: item.did,
|
|
367
|
+
// name: '',
|
|
368
|
+
// isBind: false,
|
|
369
|
+
// connectType: 'NONE',
|
|
370
|
+
// isBleOnline: false,
|
|
371
|
+
// isLanOnline: false,
|
|
372
|
+
// isOnline: false,
|
|
373
|
+
// }
|
|
374
|
+
// })
|
|
320
375
|
if (isBind) {
|
|
321
376
|
res(await this.bindDevices(newData));
|
|
322
377
|
} else {
|
|
@@ -344,7 +399,7 @@ class BLEConfig extends ConfigBase {
|
|
|
344
399
|
password,
|
|
345
400
|
softAPSSIDPrefix,
|
|
346
401
|
}: configBLEDeviceParams) => {
|
|
347
|
-
|
|
402
|
+
return new Promise<IResult<IConfigResult>>(async (res, rej) => {
|
|
348
403
|
GizLog.debug('GIZ_SDK: start config ble device');
|
|
349
404
|
const enableAndGetRes = await this.enableAndGetBluetoothDevices(
|
|
350
405
|
softAPSSIDPrefix
|
|
@@ -383,12 +438,13 @@ class BLEConfig extends ConfigBase {
|
|
|
383
438
|
wx.onBluetoothDeviceFound(handleFoundDevices);
|
|
384
439
|
|
|
385
440
|
const uint8Array = WifiConfig.pack(ssid,password);
|
|
441
|
+
const bleDevice = bleDevices.shift();
|
|
442
|
+
const { productKey, mac } = advertisData2PkAndMac(bleDevice.advertisData, this.specialProductKeys)
|
|
386
443
|
const startConfigDevice = async () => {
|
|
387
444
|
GizLog.debug('GIZ_SDK: startConfigDevice');
|
|
388
445
|
if (!this.hasTimeoutHandler()) {
|
|
389
446
|
return;
|
|
390
447
|
}
|
|
391
|
-
const bleDevice = bleDevices.shift();
|
|
392
448
|
if (bleDevice) {
|
|
393
449
|
GizLog.debug('GIZ_SDK: startConfigDevice, target device: ', bleDevice);
|
|
394
450
|
}
|
|
@@ -413,19 +469,23 @@ class BLEConfig extends ConfigBase {
|
|
|
413
469
|
GizLog.debug("GIZ_SDK: offBluetoothDeviceFound ready search device")
|
|
414
470
|
wx.offBluetoothDeviceFound(() => {});
|
|
415
471
|
};
|
|
472
|
+
await startConfigDevice();
|
|
416
473
|
|
|
417
|
-
//
|
|
474
|
+
// 开始确认设备是否上线
|
|
418
475
|
try {
|
|
419
476
|
// const devicesReturn = await this.searchDevice({ ssid, password });
|
|
420
|
-
this.searchDevice({ ssid, password }).then(devicesReturn => {
|
|
421
|
-
|
|
422
|
-
})
|
|
477
|
+
// this.searchDevice({ ssid, password }).then(devicesReturn => {
|
|
478
|
+
// res(devicesReturn);
|
|
479
|
+
// })
|
|
480
|
+
await sleep(5000);
|
|
481
|
+
// const devicesReturn = await this.searchDevice({ ssid, password });
|
|
482
|
+
this.verifyDeviceOnline({ productKey, mac }).then(devicesReturn => {
|
|
483
|
+
res({ ...devicesReturn, data: { ...devicesReturn.data.data, mac, productKey } });
|
|
484
|
+
});
|
|
423
485
|
} catch (error) {
|
|
424
486
|
rej(error);
|
|
425
487
|
GizLog.error("GIZ_SDK: searchDevice error", new Error(JSON.stringify(error)))
|
|
426
488
|
}
|
|
427
|
-
|
|
428
|
-
await startConfigDevice();
|
|
429
489
|
});
|
|
430
490
|
};
|
|
431
491
|
}
|