mini_program_gizwits_sdk 3.7.0-kuka → 3.7.0

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.
Files changed (63) hide show
  1. package/README.md +96 -25
  2. package/{index.ts → dist/index.d.ts} +3 -3
  3. package/dist/index.js +5 -5
  4. package/global.d.ts +3 -19
  5. package/package.json +5 -5
  6. package/yarn-error.log +34 -34
  7. package/src/GizLog.ts +0 -51
  8. package/src/aepApi/aepApiRequest.ts +0 -61
  9. package/src/crc/calculators/crc16modbus.ts +0 -36
  10. package/src/crc/calculators/crc32.ts +0 -47
  11. package/src/crc/crc16modbus.ts +0 -3
  12. package/src/crc/crc32.ts +0 -4
  13. package/src/crc/create_buffer.ts +0 -7
  14. package/src/crc/define_crc.ts +0 -9
  15. package/src/crc/index.ts +0 -10
  16. package/src/crc/package.json +0 -3
  17. package/src/crc/types.ts +0 -10
  18. package/src/errorCode.ts +0 -84
  19. package/src/global.d.ts +0 -53
  20. package/src/globalData.ts +0 -9
  21. package/src/handler/EventListener.ts +0 -44
  22. package/src/handler/ble.ts +0 -1485
  23. package/src/handler/lan.ts +0 -409
  24. package/src/handler/socket.ts +0 -625
  25. package/src/openApiRequest.ts +0 -62
  26. package/src/productConfigFileManage.ts +0 -58
  27. package/src/protocol/Bind.ts +0 -22
  28. package/src/protocol/DeviceInfo.ts +0 -36
  29. package/src/protocol/DiscoverUDP.ts +0 -80
  30. package/src/protocol/GetDeviceStatus.ts +0 -63
  31. package/src/protocol/Login.ts +0 -43
  32. package/src/protocol/Ntp.ts +0 -13
  33. package/src/protocol/OTA/AwaitNoti.ts +0 -14
  34. package/src/protocol/OTA/CheckCanOTA.ts +0 -23
  35. package/src/protocol/OTA/OTAPackPackage.ts +0 -36
  36. package/src/protocol/OTA/OtaComplete.ts +0 -17
  37. package/src/protocol/OTA/PreOTA.ts +0 -47
  38. package/src/protocol/OTA/ResetPosition.ts +0 -14
  39. package/src/protocol/OffLineData.ts +0 -81
  40. package/src/protocol/ProtocolBase.ts +0 -54
  41. package/src/protocol/Reset.ts +0 -15
  42. package/src/protocol/SetReset.ts +0 -11
  43. package/src/protocol/WifiConfig.ts +0 -42
  44. package/src/protocol/dataPoint.ts +0 -769
  45. package/src/protocol/thirdProtocol/YunZhiMianBleProtocolBase.ts +0 -39
  46. package/src/protocol/tool.ts +0 -147
  47. package/src/randomCode.ts +0 -36
  48. package/src/request.ts +0 -22
  49. package/src/sdk.ts +0 -1472
  50. package/src/sentry.ts +0 -55
  51. package/src/services/devices.ts +0 -309
  52. package/src/services/login.ts +0 -15
  53. package/src/services/ota.ts +0 -30
  54. package/src/services/tool.ts +0 -10
  55. package/src/services/uploadP0.ts +0 -56
  56. package/src/sleep.ts +0 -2
  57. package/src/types/index.ts +0 -48
  58. package/src/utils.ts +0 -419
  59. package/src/wechatApi.ts +0 -210
  60. package/src/wifiConfig/ConfigBase.ts +0 -185
  61. package/src/wifiConfig/ap.ts +0 -192
  62. package/src/wifiConfig/ble.ts +0 -436
  63. package/src/wifiConfig/ble_ailCloud.ts +0 -554
@@ -1,554 +0,0 @@
1
- import errorCode from '../errorCode';
2
- import { IResult } from '../sdk';
3
- import { ab2hex, advertisData2PkAndMac, isWXDevicesResult } from '../utils';
4
-
5
- import {
6
- getBluetoothAdapterState,
7
- startBluetoothDevicesDiscovery,
8
- getBluetoothDevices,
9
- notifyBLECharacteristicValueChange,
10
- unpackWriteBLECharacteristicValue,
11
- getBLEDeviceServices,
12
- getBLEDeviceCharacteristics,
13
- retryConnect,
14
- } from '../wechatApi';
15
- import sleep from '../sleep';
16
- import ConfigBase from './ConfigBase';
17
- import WifiConfig from '../protocol/WifiConfig';
18
- import GizLog from '../GizLog';
19
- import { BleHandle } from '../handler/ble';
20
- import aepApiRequest from '../aepApi/aepApiRequest';
21
-
22
- const productKeyMap = {
23
- 'a57a49b9b265421ca337219cd66a6701': 'icgsfwJZDFX',
24
- '67a95f560e464453be079c5723a4a85c': 'icgshOaLCG5',
25
- '0b58c73f12064eb897aa005cf43d6a1b': 'icgs4Yuoa16',
26
- '5a64ca1f742942edacd09a17e3c4a7f2': 'icgsbR0xeRj',
27
- 'a83ce02518944076aa3a4e949acc71a2': 'icgsBZbJtsl',
28
- '4b286229884f4711bcdbaefdfb5f76b9': 'icgs0cyLT3e',
29
- '8c71d805031a41f2870aa9cd8680d579': 'icgsobrRgsz',
30
- 'b7a77f535a774c1592a6146b03e14a7d': 'icgsQMsZFS9',
31
- 'aff644f2b33c47fe8a557473a29ef7c1': 'icgsiBVdr5P',
32
- 'ccfeacd9296f47f7ad3598cc5e4d0843': 'icgs4eOiCOU',
33
- '7c735620d8fa48329ce2d6af68abd41b': 'icgsb2Y7InK',
34
- 'a7bca53587744b00bb76da2a7ed66e00': 'icgst4qDGSv',
35
- 'fe1c263c41ea481ca70789783c8488ee': 'icgst8DYtI6',
36
- '1ff67b6ef3394024b15e38f2d0b511b9': 'icgs8Cv3lIH',
37
- '7f240f94172446988e8f3febdd722e04': 'icgsoHk7c19', // 智能床PTN2F系列经典款
38
- '21732bba93b64203b24ea1e8b71f30e3': 'icgsUEJjCU0', // 智能软床
39
- 'b038229fed814ac2b07383e281047a0a': 'icgsrp4M0QN', // 顾家智能底床Pro
40
- '5816516a5f6a4a628c3df602e769ced3': 'icgsioLXjiC', // 顾家智能床垫Pro
41
- };
42
-
43
- interface IVerifyOnlineResult {
44
- data: {
45
- mac: string;
46
- onlineStatus: number;
47
- lastOnlineTime: string;
48
- };
49
- }
50
-
51
- interface IConfigResult {
52
- mac: string;
53
- productKey: string;
54
- }
55
-
56
- interface IArgs {
57
- bleDeviceId: string;
58
- arrayBuffer: ArrayBuffer;
59
- serviceUUIDSuffix?: string;
60
- characteristicUUIDSuffix?: string;
61
- bleHandle: BleHandle;
62
- }
63
-
64
- const configAck = '0000000303000002';
65
-
66
- export function sendBLEConfigCmd({
67
- bleDeviceId,
68
- arrayBuffer,
69
- serviceUUIDSuffix = 'fe60',
70
- characteristicUUIDSuffix = 'fe61',
71
- bleHandle,
72
- }: IArgs) {
73
- let sendInterval = null;
74
- let closeTimeout = null;
75
- let serviceUUIDSuffix2 = 'abf0';
76
- let characteristicUUIDSuffix2 = 'abf7';
77
-
78
- const checkInterrupt = () => {
79
- if (closeTimeout === null) {
80
- sendInterval && clearInterval(sendInterval);
81
- return true;
82
- }
83
- return false;
84
- };
85
-
86
- return new Promise<boolean>(async (resolve, reject) => {
87
- try {
88
- GizLog.debug('GIZ_SDK: ssid info: ', arrayBuffer);
89
- // 设置超时
90
- closeTimeout = setTimeout(() => {
91
- sendInterval && clearInterval(sendInterval);
92
- // 发送超时 返回失败
93
- closeTimeout = null;
94
- resolve(false);
95
- }, 5 * 1000);
96
- GizLog.debug('GIZ_SDK: createBLEConnection start: ', bleDeviceId);
97
- await bleHandle.disableScan();
98
-
99
- const connectData = await retryConnect(bleDeviceId, 10 * 1000);
100
- bleHandle.enableScan();
101
-
102
- GizLog.debug('GIZ_SDK: createBLEConnection end, res:', connectData);
103
- GizLog.debug('GIZ_SDK: getBLEDeviceServices start, res:', serviceUUIDSuffix);
104
- const services = await getBLEDeviceServices(bleDeviceId);
105
- GizLog.debug('GIZ_SDK: getBLEDeviceServices end, res:', services);
106
- const service = services.find(
107
- s =>
108
- s.uuid.split('-')[0].toLowerCase().endsWith(serviceUUIDSuffix) ||
109
- s.uuid.split('-')[0].toLowerCase().endsWith(serviceUUIDSuffix2)
110
- );
111
- if (!service) {
112
- // 获取蓝牙设备服务异常
113
- GizLog.debug('GIZ_SDK: get ble device services fail', bleDeviceId, services);
114
- resolve(false);
115
- return;
116
- }
117
-
118
- const characteristics = await getBLEDeviceCharacteristics(bleDeviceId, service.uuid);
119
- GizLog.debug('GIZ_SDK: getBLEDeviceCharacteristics end, res:', characteristics);
120
- const characteristic = characteristics.find(
121
- c =>
122
- c.uuid.split('-')[0].toLowerCase().endsWith(characteristicUUIDSuffix) ||
123
- c.uuid.split('-')[0].toLowerCase().endsWith(characteristicUUIDSuffix2)
124
- );
125
- if (!characteristic) {
126
- // 获取蓝牙设备特征值异常
127
- GizLog.debug('GIZ_SDK: get ble device characteristics fail', bleDeviceId, characteristics);
128
- resolve(false);
129
- return;
130
- }
131
-
132
- if (!characteristic.properties.notify && !characteristic.properties.indicate) {
133
- GizLog.debug(
134
- 'GIZ_SDK: the ble device characteristic not support notify or indicate',
135
- bleDeviceId,
136
- characteristic
137
- );
138
- // 该设备不支持 notify & indicate 操作
139
- resolve(false);
140
- return;
141
- }
142
-
143
- GizLog.debug('GIZ_SDK: check characteristic and service success');
144
-
145
- await notifyBLECharacteristicValueChange(bleDeviceId, service.uuid, characteristic.uuid);
146
-
147
- // 这里有个问题,模组好像不一定每次都会回
148
- const handleBLECharacteristicValueChange = (
149
- res: WechatMiniprogram.OnBLECharacteristicValueChangeCallbackResult
150
- ) => {
151
- const hexString = ab2hex(res.value);
152
- GizLog.debug('GIZ_SDK: 收到设备返回ack', hexString);
153
- if (hexString === configAck) {
154
- // 发送成功
155
- bleHandle.removeEventListener('GizBleDeviceData', handleBLECharacteristicValueChange);
156
- resolve(true);
157
- }
158
- };
159
-
160
- bleHandle.addEventListener('GizBleDeviceData', handleBLECharacteristicValueChange);
161
-
162
- // 订阅特征值变化
163
- // wx.onBLECharacteristicValueChange(handleBLECharacteristicValueChange);
164
-
165
- GizLog.debug('GIZ_SDK: on notifyBLECharacteristicValueChange success');
166
-
167
- if (checkInterrupt()) return;
168
-
169
- await unpackWriteBLECharacteristicValue(bleDeviceId, service.uuid, characteristic.uuid, arrayBuffer);
170
- sendInterval = setInterval(() => {
171
- if (checkInterrupt()) return;
172
- unpackWriteBLECharacteristicValue(bleDeviceId, service.uuid, characteristic.uuid, arrayBuffer);
173
- }, 2000);
174
-
175
- // if (res.errCode === 0) {
176
- // resolve(true);
177
- // } else{
178
- // resolve(false);
179
- // }
180
- GizLog.debug('GIZ_SDK: unpackWriteBLECharacteristicValue end');
181
- } catch (error) {
182
- reject(false);
183
- GizLog.debug('GIZ_SDK: sendBLEConfigCmd error', error);
184
- }
185
- })
186
- .catch(error => {
187
- GizLog.debug('GIZ_SDK: sendBLEConfigCmd error', error);
188
- })
189
- .finally(() => {
190
- // 关闭连接
191
- closeTimeout && clearTimeout(closeTimeout);
192
- sendInterval && clearInterval(sendInterval);
193
- wx.closeBLEConnection({ deviceId: bleDeviceId });
194
- });
195
- }
196
-
197
- interface configBLEDeviceParams {
198
- ssid: string;
199
- password: string;
200
- softAPSSIDPrefix?: string;
201
- timeout: number;
202
- productKeys?: string[];
203
- }
204
-
205
- interface ISetDeviceOnboardingDeployProps {
206
- timeout: number;
207
- isBind: boolean;
208
- softAPSSIDPrefix: string;
209
- productKeys?: string[];
210
- }
211
-
212
- interface IOnlieTimeMap {
213
- [key: string]: string;
214
- }
215
-
216
- // 阿里云 蓝牙配网
217
- class BLEAliCloudConfig extends ConfigBase {
218
- bleHandle: BleHandle;
219
- lastestOnlineTimeMap: IOnlieTimeMap = {};
220
-
221
- constructor(
222
- ssid: string,
223
- password: string,
224
- specialProductKeys: string[],
225
- specialProductKeySecrets: string[],
226
- bleHandle: BleHandle
227
- ) {
228
- super(ssid, password, specialProductKeys, specialProductKeySecrets);
229
- this.bleHandle = bleHandle;
230
- }
231
- destroy = () => {
232
- this.cleanTimeout();
233
- };
234
- isValidBleDevice = (
235
- bleDevice: WechatMiniprogram.BlueToothDevice,
236
- softAPSSIDPrefix?: string,
237
- productKeys?: string[]
238
- ) => {
239
- if (!bleDevice || !bleDevice.advertisData) {
240
- // 无效蓝牙设备或者蓝牙设备广播数据为空,返回失败
241
- return false;
242
- }
243
-
244
- const { productKey, mac, bleWorkStatus } = advertisData2PkAndMac(bleDevice.advertisData, this.specialProductKeys);
245
- // GizLog.debug(`GIZ_SDK: 蓝牙广播配网标志位 ${bleWorkStatus} `);
246
-
247
- // bleWorkStatus为0 表示配网标志位为0 不可配网 直接return
248
- if (bleWorkStatus === 0) return false;
249
- if (!this.specialProductKeys.includes(productKey)) {
250
- // 不在PK列表
251
- return false;
252
- }
253
- if (productKeys && productKeys.length > 0) {
254
- if (!productKeys.includes(productKey)) {
255
- // 不在PK列表
256
- return false;
257
- }
258
- }
259
- GizLog.debug(`GIZ_SDK: isValidBleDevice mac: ${mac} pk: ${productKey} name: ${bleDevice.name}`);
260
- GizLog.debug(
261
- `GIZ_SDK: softAPSSIDPrefix: ${softAPSSIDPrefix} ismatch : ${
262
- bleDevice.name && bleDevice.name.startsWith(softAPSSIDPrefix)
263
- }`
264
- );
265
- return !softAPSSIDPrefix || (bleDevice.name && bleDevice.name.startsWith(softAPSSIDPrefix));
266
- };
267
-
268
- enableBluetoothDevicesDescovery = async (): Promise<{ success: false; err: IError } | { success: true }> => {
269
- // try {
270
- // await closeBluetoothAdapter();
271
- // await openBluetoothAdapter();
272
- // } catch (error) {
273
-
274
- // }
275
- const stateRes = await getBluetoothAdapterState();
276
- if (!stateRes.available) {
277
- return {
278
- success: false,
279
- err: {
280
- errorCode: errorCode.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON.errorCode,
281
- errorMessage: '蓝牙状态不可用',
282
- },
283
- };
284
- }
285
-
286
- await startBluetoothDevicesDiscovery();
287
- return { success: true };
288
- };
289
-
290
- enableAndGetBluetoothDevices = async (
291
- softAPSSIDPrefix?: string,
292
- productKeys?: string[]
293
- ): Promise<{ success: false; err: IError } | { success: true; bleDevices?: WechatMiniprogram.BlueToothDevice[] }> => {
294
- const discoveryRes = await this.enableBluetoothDevicesDescovery();
295
- if (!discoveryRes.success) {
296
- return discoveryRes;
297
- }
298
- GizLog.debug('GIZ_SDK: start enableAndGetBluetoothDevices');
299
-
300
- const bleDevices: WechatMiniprogram.BlueToothDevice[] = (await getBluetoothDevices()).filter(d =>
301
- this.isValidBleDevice(d, softAPSSIDPrefix, productKeys)
302
- );
303
- GizLog.debug('GIZ_SDK: getBluetoothDevices success', bleDevices);
304
- // 由于有.advertisData undefined的错误,这里安全拷贝一份
305
- const arr: WechatMiniprogram.BlueToothDevice[] = [];
306
- bleDevices.forEach(item => {
307
- if (item && item.advertisData) {
308
- arr.push({ ...item });
309
- }
310
- });
311
- return {
312
- success: true,
313
- bleDevices: arr,
314
- };
315
- };
316
-
317
- setDeviceOnboardingDeploy = ({
318
- timeout,
319
- isBind = true,
320
- softAPSSIDPrefix,
321
- productKeys,
322
- }: ISetDeviceOnboardingDeployProps) => {
323
- return new Promise<IResult<IDevice[]>>(async (res, rej) => {
324
- const ssid = this.ssid;
325
- const password = this.password;
326
- this.destroy();
327
- this.initDeviceOnboardingDeploy(res, rej);
328
- this.startTimeoutTimer(timeout);
329
-
330
- try {
331
- const result = await this.configBLEDevice({
332
- ssid,
333
- password,
334
- timeout: timeout * 1000,
335
- softAPSSIDPrefix,
336
- productKeys,
337
- });
338
-
339
- const newData: IDevice[] = [result.data as IDevice];
340
- // const newData: IDevice[] = (result.data || []).map(item => {
341
- // return {
342
- // mac: item.mac,
343
- // productKey: item.product_key,
344
- // did: item.did,
345
- // name: '',
346
- // isBind: false,
347
- // connectType: 'NONE',
348
- // isBleOnline: false,
349
- // isLanOnline: false,
350
- // isOnline: false,
351
- // }
352
- // })
353
- if (isBind) {
354
- res(await this.bindDevices(newData));
355
- } else {
356
- // 不需要绑定 直接返回成功
357
- res({
358
- success: true,
359
- data: newData,
360
- });
361
- }
362
- } catch (error) {
363
- res({
364
- success: false,
365
- data: error,
366
- });
367
- } finally {
368
- this.destroy();
369
- }
370
- });
371
- };
372
-
373
- getDeviceLastestOnlineTime = async ({ productKey, mac }: { productKey: string; mac: string }) => {
374
- // lastOnlineTime
375
- let realKey = productKeyMap[productKey];
376
- if (!realKey) {
377
- realKey = productKey;
378
- }
379
- GizLog.debug('GIZ_SDK: getDeviceLastestOnlineTime', realKey, mac, productKey);
380
- const res = await aepApiRequest<IVerifyOnlineResult>(
381
- `app/device/deviceInfo/${realKey}/${(mac ?? '').toLocaleLowerCase()}`,
382
- { method: 'post' }
383
- );
384
- GizLog.debug('GIZ_SDK: 请求结果', res);
385
- return res;
386
- };
387
-
388
- // 配网后确认设备是否上线
389
- verifyDeviceOnline = ({ productKey, mac }: { productKey: string; mac: string }) => {
390
- return new Promise<IResult<IVerifyOnlineResult>>((res, rej) => {
391
- GizLog.debug('GIZ_SDK: 开始确认设备上线');
392
- const query = async () => {
393
- if (!this.hasTimeoutHandler()) {
394
- return;
395
- }
396
-
397
- try {
398
- await sleep(2000);
399
- const data = await this.getDeviceLastestOnlineTime({
400
- productKey,
401
- mac,
402
- });
403
- // if (data.err?.errorCode === errorCode.GIZ_OPENAPI_TOKEN_INVALID.errorCode) {
404
- // // token 失效
405
- // rej({
406
- // success: false,
407
- // err: errorCode.GIZ_OPENAPI_TOKEN_INVALID,
408
- // });
409
- // return;
410
- // }
411
- GizLog.debug('GIZ_SDK: 确认到设备是否在线', data.data?.data?.onlineStatus);
412
- if (data.success && data.data && data.data.data && data.data.data.onlineStatus == 1) {
413
- // 确认设备最后一次上线时间有更新
414
- GizLog.debug('GIZ_SDK: 确认到设备是在线的', data);
415
- res({
416
- success: true,
417
- data: data.data,
418
- });
419
- } else {
420
- // 重新请求
421
- GizLog.debug('GIZ_SDK: 未确认到设备是在线');
422
- await sleep(1500);
423
- !this.disableSearchDevice && query();
424
- }
425
-
426
- // if (data.err || data.data) {
427
- // // 重新请求
428
- // GizLog.debug('GIZ_SDK: 未确认到设备上线时间');
429
- // await sleep(1500);
430
- // !this.disableSearchDevice && query();
431
- // } else {
432
- // // 搜索到设备
433
- // GizLog.debug('GIZ_SDK: 大循环搜索到设备', data);
434
- // res({
435
- // success: true,
436
- // data: data.data,
437
- // });
438
- // }
439
- } catch (error) {
440
- // 重新请求
441
- await sleep(3000);
442
- !this.disableSearchDevice && query();
443
- // GizLog.debug('GIZ_SDK: random codes error', error);
444
- }
445
- };
446
- query();
447
- });
448
- };
449
-
450
- /**
451
- * 负责发蓝牙设备指令
452
- */
453
- configBLEDevice = ({ ssid, password, softAPSSIDPrefix, productKeys }: configBLEDeviceParams) => {
454
- return new Promise<IResult<IConfigResult>>(async (res, rej) => {
455
- GizLog.debug('GIZ_SDK: start config ble device');
456
- const enableAndGetRes = await this.enableAndGetBluetoothDevices(softAPSSIDPrefix, productKeys).catch(error => {
457
- return {
458
- success: false,
459
- err: {
460
- errorCode: errorCode.WECHAT_ERROR.errorCode,
461
- errorMessage: JSON.stringify(error),
462
- },
463
- };
464
- });
465
-
466
- if (!isWXDevicesResult(enableAndGetRes)) {
467
- // 开启获取蓝牙失败
468
- return rej(enableAndGetRes);
469
- }
470
-
471
- const { bleDevices } = enableAndGetRes;
472
-
473
- GizLog.debug('GIZ_SDK: enableAndGetBluetoothDevices success, target devices: ', bleDevices);
474
-
475
- const handleFoundDevices = async ({ devices }: { devices: WechatMiniprogram.BlueToothDevice[] }) => {
476
- this.hasTimeoutHandler()
477
- ? Array.prototype.push.apply(
478
- bleDevices,
479
- devices.filter(d => this.isValidBleDevice(d, softAPSSIDPrefix, productKeys))
480
- )
481
- : wx.offBluetoothDeviceFound(handleFoundDevices);
482
- };
483
-
484
- wx.onBluetoothDeviceFound(handleFoundDevices);
485
-
486
- const uint8Array = WifiConfig.pack(ssid, password);
487
-
488
- const bleDevice = bleDevices.shift();
489
-
490
- const startConfigDevice = async bleDevice => {
491
- GizLog.debug('GIZ_SDK: startConfigDevice');
492
- if (!this.hasTimeoutHandler()) {
493
- return;
494
- }
495
-
496
- if (bleDevice) {
497
- GizLog.debug('GIZ_SDK: startConfigDevice, target device: ', bleDevice);
498
- }
499
-
500
- const success =
501
- bleDevice &&
502
- (await sendBLEConfigCmd({
503
- bleDeviceId: bleDevice.deviceId,
504
- arrayBuffer: uint8Array.buffer,
505
- bleHandle: this.bleHandle,
506
- }));
507
-
508
- if (!success) {
509
- // 如果校验设备或者发送不成功,重试下一个设备
510
- await sleep(500);
511
- await startBluetoothDevicesDiscovery();
512
- await startConfigDevice(bleDevice);
513
- return;
514
- }
515
-
516
- // 如果有一个设备发送成功,则不再发现新设备
517
- GizLog.debug('GIZ_SDK: offBluetoothDeviceFound ready search device');
518
- wx.offBluetoothDeviceFound(handleFoundDevices);
519
- };
520
-
521
- // 开始大循环搜索
522
-
523
- // try {
524
- // // const devicesReturn = await this.searchDevice({ ssid, password });
525
- // this.searchDevice({ ssid, password }).then(devicesReturn => {
526
- // res(devicesReturn);
527
- // })
528
- // } catch (error) {
529
- // rej(error);
530
- // GizLog.error("GIZ_SDK: searchDevice error", new Error(JSON.stringify(error)))
531
- // }
532
- const { productKey, mac } = advertisData2PkAndMac((bleDevice ?? {}).advertisData, this.specialProductKeys);
533
- // const result = await this.getDeviceLastestOnlineTime({ productKey, mac });
534
- // GizLog.log("GIZ_SDK: 初始设备上线时间 ", result);
535
- // if (result.success && result.data && result.data.data) {
536
- // this.lastestOnlineTimeMap[`${productKey}${mac}`] = result.data.data.lastOnlineTime;
537
- // GizLog.log("GIZ_SDK: 初始设备上线时间 lastestOnlineTimeMap ", this.lastestOnlineTimeMap);
538
- // }
539
- startConfigDevice(bleDevice);
540
- try {
541
- await sleep(5000);
542
- // const devicesReturn = await this.searchDevice({ ssid, password });
543
- this.verifyDeviceOnline({ productKey, mac }).then(devicesReturn => {
544
- res({ ...devicesReturn, data: { ...devicesReturn.data.data, productKey } });
545
- });
546
- } catch (error) {
547
- rej(error);
548
- GizLog.error('GIZ_SDK: searchDevice error', new Error(JSON.stringify(error)));
549
- }
550
- });
551
- };
552
- }
553
-
554
- export default BLEAliCloudConfig;