mini_program_gizwits_sdk 3.2.4 → 3.2.6

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.
@@ -0,0 +1,5 @@
1
+ import ProtocolBase from "./ProtocolBase";
2
+ declare class Ntp extends ProtocolBase {
3
+ static pack: () => number[];
4
+ }
5
+ export default Ntp;
@@ -0,0 +1,23 @@
1
+ import ProtocolBase from "./ProtocolBase";
2
+ export declare class RequestSync extends ProtocolBase {
3
+ state: number;
4
+ len: number;
5
+ constructor(data: number[]);
6
+ static pack: () => number[];
7
+ }
8
+ export declare class SyncPackage extends ProtocolBase {
9
+ id: number;
10
+ timestemp: number;
11
+ payloadLen: number;
12
+ payload: number[];
13
+ constructor(data: number[]);
14
+ static pack: (id: number) => number[];
15
+ }
16
+ export declare class DeletePackage extends ProtocolBase {
17
+ static pack: (id: number) => number[];
18
+ }
19
+ export declare class CancelSync extends ProtocolBase {
20
+ state: number;
21
+ constructor(data: number[]);
22
+ pack: () => number[];
23
+ }
@@ -1,4 +1,5 @@
1
1
  declare const checkHeader: (data: any) => number | false;
2
+ export declare const completeBlock: (cmd: string) => number[];
2
3
  declare const getProtocolLen: (data: any) => number;
3
4
  declare function arrayToString(arr: number[]): string;
4
5
  declare const fillString: (string: string, num: number, foot?: boolean) => string;
package/dist/src/sdk.d.ts CHANGED
@@ -2,6 +2,14 @@ import { TLogType } from './GizLog';
2
2
  import { ILoginRes } from './services/login';
3
3
  import { IOpenApiDevice, ISafeRegisterReturn, IUnbindReturn } from './services/devices';
4
4
  import { IDataPointConfig } from './protocol/DataPoint';
5
+ interface SyncCallBackParams {
6
+ event: TSyncEvnet;
7
+ currentNum?: number;
8
+ totalNum?: number;
9
+ message?: string;
10
+ }
11
+ declare type TSyncEvnet = 'SYNC_START' | 'SYNC_END' | 'SYNC_FAIL' | 'SYNC_CANCEL' | 'SYNC_PROGRESS';
12
+ export declare type SyncCallBack = (data: SyncCallBackParams) => void;
5
13
  interface ISDKResult<T> {
6
14
  data?: T;
7
15
  err?: IError;
@@ -103,6 +111,12 @@ declare class GizwitsMiniSDK {
103
111
  private _lanHandle;
104
112
  private _gizSocket;
105
113
  private offlineThreshold?;
114
+ private syncDataCallBack?;
115
+ private syncTotalNum;
116
+ private syncCurrnetNum;
117
+ private syncDataTimoutTimer;
118
+ private SYNC_TIMEOUT;
119
+ private syncDevice?;
106
120
  constructor({ appID, appSecret, productInfo, cloudServiceInfo, token, uid, offlineThreshold, }: GizwitsSdkOption);
107
121
  private get bleHandle();
108
122
  private get lanHandle();
@@ -120,23 +134,33 @@ declare class GizwitsMiniSDK {
120
134
  private initLan;
121
135
  startAutoScan: () => void;
122
136
  stopAutoScan: () => void;
123
- setDeviceMeta: <K extends "did" | "mac" | "productKey" | "bleWorkStatus" | "name" | "isBind" | "rootDeviceId" | "bleDeviceID" | "remark" | "connectType" | "isOnline" | "isLanOnline" | "isBleOnline" | "host" | "wss_port" | "ctime">(curDev: IDevice, key: K, value: IDevice[K], force?: boolean) => void;
137
+ setDeviceMeta: <K extends "did" | "mac" | "productKey" | "bleWorkStatus" | "name" | "isBind" | "rootDeviceId" | "bleDeviceID" | "remark" | "passcode" | "connectType" | "isOnline" | "isLanOnline" | "isBleOnline" | "host" | "wss_port" | "ctime">(curDev: IDevice, key: K, value: IDevice[K], force?: boolean) => void;
124
138
  getVersion: () => {
125
139
  success: boolean;
126
140
  data: string;
127
141
  };
128
142
  initBle: () => Promise<ISDKResult<null>>;
129
143
  scanBleDevice: (delay: number) => Promise<ISDKResult<IDevice[]>>;
130
- write: (device: IDevice, attrs: object) => Promise<{
144
+ write: (device: IDevice, attrs: object) => Promise<import("./wechatApi").IWechatResult | {
145
+ success: boolean;
146
+ message: string;
147
+ } | {
131
148
  success: boolean;
132
149
  message?: undefined;
133
- } | import("./wechatApi").IWechatResult | {
150
+ }>;
151
+ writeRaw: (device: IDevice, data: number[]) => Promise<IError | import("./wechatApi").IWechatResult | {
152
+ success: boolean;
153
+ }>;
154
+ setDeviceTimeStamp: (device: IDevice) => Promise<import("./wechatApi").IWechatResult | {
134
155
  success: boolean;
135
156
  message: string;
136
157
  }>;
137
- writeRaw: (device: IDevice, data: number[]) => Promise<IError | import("./wechatApi").IWechatResult | {
158
+ syncDeviceData: (device: IDevice, callback: SyncCallBack) => Promise<import("./wechatApi").IWechatResult | {
138
159
  success: boolean;
160
+ message: string;
139
161
  }>;
162
+ cancelSyncDeviceData: () => Promise<void>;
163
+ private cleanSyncDeviceData;
140
164
  getProductConfig: (pk: string) => Promise<ISDKResult<IDataPointConfig>>;
141
165
  stopScanBleDevice: () => void;
142
166
  login: (openID: string) => Promise<ISDKResult<ILoginRes>>;
@@ -0,0 +1,12 @@
1
+ export interface IUploadRes {
2
+ }
3
+ interface IData {
4
+ raw: string;
5
+ created_at: number;
6
+ }
7
+ interface IProps {
8
+ device: IDevice;
9
+ data: IData[];
10
+ }
11
+ export declare function uploadP0({ device, data }: IProps): Promise<import("../openApiRequest").IServiceResult<IUploadRes>>;
12
+ export {};
package/global.d.ts CHANGED
@@ -25,4 +25,4 @@ type TModeOfOperation = {
25
25
  declare namespace aesjs {
26
26
  const utils: TUtils;
27
27
  const ModeOfOperation: TModeOfOperation;
28
- }
28
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mini_program_gizwits_sdk",
3
- "version": "3.2.4",
3
+ "version": "3.2.6",
4
4
  "description": "优化扫描策略,根据UUID过滤,数据包也更新蓝牙设备的ctime",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
package/src/global.d.ts CHANGED
@@ -39,6 +39,7 @@ interface IDevice {
39
39
  rootDeviceId?: string;
40
40
  bleDeviceID?: string;
41
41
  remark?: string;
42
+ passcode?: string;
42
43
  connectType: TConnectType;
43
44
  isOnline: boolean; // 代表大循环在线
44
45
  isLanOnline: boolean; // 代表小循环在线
@@ -14,7 +14,6 @@ import { hexStrint2byte } from '../protocol/tool';
14
14
  import ProtocolBase from '../protocol/ProtocolBase';
15
15
  import Login from '../protocol/Login';
16
16
  import GetDeviceStatus from '../protocol/GetDeviceStatus';
17
- import Sdk from '../Sdk';
18
17
  import { padBoradcastData } from '../protocol/DataPoint';
19
18
  import GizLog from '../GizLog';
20
19
  import EventListener from './EventListener';
@@ -189,7 +188,7 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
189
188
  });
190
189
  };
191
190
 
192
- private handleOnBLECharacteristicValueChange = (
191
+ private handleOnBLECharacteristicValueChange = async (
193
192
  curDevice: WechatMiniprogram.OnBLECharacteristicValueChangeCallbackResult
194
193
  ) => {
195
194
  // 不存在数据
@@ -470,7 +469,7 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
470
469
 
471
470
  GizLog.debug("GIZ_SDK: start scan", delay);
472
471
  await wx.startBluetoothDevicesDiscovery({
473
- services: ['ABF8', 'ABF0'],
472
+ services: ['ABF8', 'ABF0', 'F0AB', 'F8AB'],
474
473
  powerLevel: 'high',
475
474
  allowDuplicatesKey: true,
476
475
  interval: 200,
@@ -0,0 +1,13 @@
1
+ import ProtocolBase from "./ProtocolBase";
2
+ import { completeBlock } from "./tool";
3
+
4
+ class Ntp extends ProtocolBase {
5
+ static pack = () => {
6
+ const time = parseInt(`${Date.now() / 1000}`, 10);
7
+ const timeString = time.toString(2)
8
+
9
+ return [0,0,0,3,11,0,0,89].concat(completeBlock(timeString));
10
+ }
11
+ }
12
+
13
+ export default Ntp;
@@ -0,0 +1,78 @@
1
+ import ProtocolBase from "./ProtocolBase";
2
+ import { arrayToString, completeBlock, fillString, hexStrint2byte } from "./tool";
3
+
4
+ export class RequestSync extends ProtocolBase {
5
+ state: number = 0; // 0 允许同步 1 没有数据 2其他
6
+ len: number = 0; // 需要同步的数据长度
7
+ constructor(data: number[]) {
8
+ super(data);
9
+ let index = 0
10
+ this.state = this.content[0];
11
+ index += 1
12
+ this.len = parseInt(arrayToString(this.content.slice(index, index + 2)), 16);
13
+ }
14
+ static pack = () => {
15
+ return [0,0,0,3,3,0,0,81];
16
+ }
17
+ }
18
+
19
+
20
+ export class SyncPackage extends ProtocolBase {
21
+ id: number = 0;
22
+ timestemp: number = 0;
23
+ payloadLen: number = 0;
24
+ payload: number[] = [];
25
+ constructor(data: number[]) {
26
+ super(data);
27
+
28
+ let index = 0;
29
+ this.id = parseInt(arrayToString(this.content.slice(index, index + 4)), 16);
30
+
31
+ index += 4;
32
+
33
+ this.timestemp = parseInt(arrayToString(this.content.slice(index, index + 5)), 16);
34
+ index += 5;
35
+
36
+ this.payloadLen = parseInt(arrayToString(this.content.slice(index, index + 2)), 16);
37
+ index += 2;
38
+
39
+ this.payload = this.content.slice(index, this.content.length)
40
+ }
41
+ static pack = (id: number) => {
42
+ let stringData = id.toString(2)
43
+ stringData = fillString(stringData, 8 * 2)
44
+ const packageData = [0,0,0,3, 5].concat([0,0,83]).concat(completeBlock(stringData))
45
+ return packageData;
46
+ }
47
+ }
48
+
49
+ // 删除数据
50
+ export class DeletePackage extends ProtocolBase {
51
+ static pack = (id: number) => {
52
+ let stringData = id.toString(2)
53
+ stringData = fillString(stringData, 8 * 2)
54
+ const packageData = [0,0,0,3,5].concat([0,0,85]).concat(completeBlock(stringData))
55
+ return packageData;
56
+ }
57
+ }
58
+ // let time = 1669711410;
59
+ // let timeBytes: any = time.toString(16)
60
+ // timeBytes = fillString(timeBytes, 10)
61
+ // timeBytes = hexStrint2byte(timeBytes)
62
+ // console.log(timeBytes)
63
+
64
+ // const syncPackage = new SyncPackage([0,0,0,3,15 ,0, 0, 83,1,1,1,1].concat(timeBytes).concat([0, 1, 1]))
65
+ // console.log(syncPackage)
66
+
67
+
68
+ export class CancelSync extends ProtocolBase {
69
+ state: number = 0; // 0 同步完成 01 异常 02 其他
70
+ constructor(data: number[]) {
71
+ super(data);
72
+ this.state = this.content[0];
73
+ }
74
+ pack = () => {
75
+ const packageData = [0,0,0,3, 2, 0, 0, 87]
76
+ return packageData;
77
+ }
78
+ }
@@ -1,5 +1,5 @@
1
1
  import productConfigFileManage from "../productConfigFileManage";
2
- import { arrayToString, checkHeader, fillString, getProtocolLen, hexStrint2byte } from "./tool";
2
+ import { arrayToString, checkHeader, fillString, getProtocolLen, hexStrint2byte, completeBlock} from "./tool";
3
3
 
4
4
  export interface IDataPointConfig {
5
5
  name: string;
@@ -44,16 +44,6 @@ export interface IDataPointAttr {
44
44
  desc: string;
45
45
  }
46
46
 
47
- // 从协议计算一个区块的数据
48
- const completeBlock = (cmd: string) => {
49
- // 补0到8的倍数
50
- const newCmd = fillString(cmd, Math.ceil(cmd.length / 8) * 8);
51
- const data: number[] = [];
52
- for (let i = 0; i < newCmd.length; i += 8) {
53
- data.push(parseInt(newCmd.substring(i, i + 8), 2));
54
- }
55
- return data;
56
- };
57
47
  const fixType = (type: TDataType) => {
58
48
  return type.indexOf('uint') !== -1 ? 'number' : type;
59
49
  };
@@ -284,15 +274,6 @@ const DataPointToP = ({ config, data, isAdaptiveDatapoint }: IDataPointToP0Param
284
274
  }
285
275
  };
286
276
  };
287
-
288
- /**
289
- * p0 转json
290
- * @param {*} config
291
- * @param {*} data
292
- * 设备到app
293
- * header len flag cmd sn action data
294
- * action 0x04定长上报 0x05定长下发 0x11变长下发 0x14变长上报 0x12变长下发读数据点 0x02定长读数据点
295
- */
296
277
 
297
278
  interface IPToDataPointParams {
298
279
  config: IDataPointAttr[];
@@ -323,6 +304,14 @@ function getVariableLength(data: number[]) {
323
304
  return lengthArr;
324
305
  }
325
306
 
307
+ /**
308
+ * p0 转json
309
+ * @param {*} config
310
+ * @param {*} data
311
+ * 设备到app
312
+ * header len flag cmd sn action data
313
+ * action 0x04定长上报 0x05定长下发 0x11变长下发 0x14变长上报 0x12变长下发读数据点 0x02定长读数据点
314
+ */
326
315
  function PToDataPoint({ config = [], data }: IPToDataPointParams) {
327
316
  let action: number;
328
317
  let message = '';
@@ -9,6 +9,17 @@ const checkHeader = (data) => {
9
9
  return pointer;
10
10
  };
11
11
 
12
+ // 从2进制,转换成10进制数组
13
+ export const completeBlock = (cmd: string) => {
14
+ // 补0到8的倍数
15
+ const newCmd = fillString(cmd, Math.ceil(cmd.length / 8) * 8);
16
+ const data: number[] = [];
17
+ for (let i = 0; i < newCmd.length; i += 8) {
18
+ data.push(parseInt(newCmd.substring(i, i + 8), 2));
19
+ }
20
+ return data;
21
+ };
22
+
12
23
  const getProtocolLen = (data) => {
13
24
  /**
14
25
  * 插入len
package/src/sdk.ts CHANGED
@@ -26,8 +26,23 @@ import {
26
26
  } from './utils';
27
27
  import productConfigFileManage from './productConfigFileManage';
28
28
  import { formatEnum, IDataPointConfig, pack, unpack } from './protocol/DataPoint';
29
- import { hexStrint2byte } from './protocol/tool';
29
+ import { arrayToString, hexStrint2byte } from './protocol/tool';
30
30
  import { LanHandle } from './handler/lan';
31
+ import ProtocolBase from './protocol/ProtocolBase';
32
+ import { CancelSync, DeletePackage, RequestSync, SyncPackage } from './protocol/OffLineData';
33
+ import { uploadP0 } from './services/uploadP0';
34
+ import sleep from './sleep';
35
+ import Ntp from './protocol/Ntp';
36
+
37
+ interface SyncCallBackParams {
38
+ event: TSyncEvnet;
39
+ currentNum?: number;
40
+ totalNum?: number;
41
+ message?: string;
42
+ }
43
+ type TSyncEvnet = 'SYNC_START' | 'SYNC_END' | 'SYNC_FAIL' | 'SYNC_CANCEL' | 'SYNC_PROGRESS';
44
+ export type SyncCallBack = (data: SyncCallBackParams) => void
45
+
31
46
 
32
47
  // 接口返回格式
33
48
  interface ISDKResult<T> {
@@ -240,6 +255,14 @@ class GizwitsMiniSDK {
240
255
  private _gizSocket: GizwitsWS;
241
256
  private offlineThreshold?: number;
242
257
 
258
+ // 离线同步
259
+ private syncDataCallBack?: SyncCallBack = null
260
+ private syncTotalNum: number = 0
261
+ private syncCurrnetNum: number = 0
262
+ private syncDataTimoutTimer: any = null;
263
+ private SYNC_TIMEOUT: number = 4 * 60 * 1000
264
+ private syncDevice?: IDevice;
265
+
243
266
  constructor({
244
267
  appID,
245
268
  appSecret,
@@ -271,6 +294,22 @@ class GizwitsMiniSDK {
271
294
  * 初始化sdk的时候就要开始扫描设备
272
295
  */
273
296
  this.initLan();
297
+
298
+
299
+ // uploadP0({
300
+ // device: {
301
+ // productKey: "8915df8a1f074d52a38bd074d6da5ce1",
302
+ // did: "7NHzru2BxYL5lamNHxfEbe",
303
+ // passcode: "1234567890",
304
+ // },
305
+ // data: [
306
+ // {
307
+ // raw: "A",
308
+ // created_at: 1669791627
309
+ // }
310
+ // ]
311
+ // })
312
+
274
313
  }
275
314
 
276
315
  private get bleHandle() {
@@ -358,15 +397,120 @@ class GizwitsMiniSDK {
358
397
  (item) => item.bleDeviceID === curDevice.deviceId
359
398
  );
360
399
  if (target) {
361
- const data = await unpack(hexStrint2byte(hexString), target.productKey);
362
- // 如果有kydata 则上报
363
- if (data?.kvData && this.listenerMap['GizDeviceAttrsNotifications']) {
364
- this.listenerMap['GizDeviceAttrsNotifications'].map((item) => {
365
- item({
366
- device: target,
367
- data: data?.kvData,
368
- });
369
- });
400
+ const bleBytesData = hexStrint2byte(hexString)
401
+ const parseData = new ProtocolBase(bleBytesData);
402
+ switch (parseData.cmd) {
403
+ case '0093':
404
+ case '0094':
405
+ case '0090':
406
+ case '0091': {
407
+ const data = await unpack(hexStrint2byte(hexString), target.productKey);
408
+ // 如果有kydata 则上报
409
+ if (data?.kvData && this.listenerMap['GizDeviceAttrsNotifications']) {
410
+ this.listenerMap['GizDeviceAttrsNotifications'].map((item) => {
411
+ item({
412
+ device: target,
413
+ data: data?.kvData,
414
+ });
415
+ });
416
+ }
417
+ break
418
+ }
419
+ case '0052': {
420
+ // 设备回复是否允许同步数据
421
+ if (!this.syncDataCallBack) break;
422
+ const requestSyncData = new RequestSync(bleBytesData)
423
+ GizLog.debug("设备回复是否允许同步, state:" , requestSyncData.state)
424
+
425
+ if (requestSyncData.state === 0) {
426
+ // 开始同步
427
+ this.syncCurrnetNum = 0;
428
+ this.syncTotalNum = requestSyncData.len;
429
+ this.syncDataCallBack({
430
+ event: 'SYNC_START',
431
+ totalNum: this.syncTotalNum,
432
+ currentNum: this.syncCurrnetNum
433
+ })
434
+ // 读取第0条
435
+ GizLog.debug("查询第一条离线数据")
436
+ await this.bleHandle.write(curDevice.deviceId, numberArray2Uint8Array(SyncPackage.pack(0)).buffer)
437
+ } else {
438
+ GizLog.debug("设备返回状态为1,同步失败")
439
+
440
+ // 同步失败
441
+ this.syncDataCallBack({
442
+ event: 'SYNC_FAIL',
443
+ })
444
+ }
445
+ break
446
+ }
447
+ case '0054': {
448
+ if (!this.syncDataCallBack) break;
449
+ // 设备上报需要同步的数据
450
+ GizLog.debug("设备上报离线数据")
451
+
452
+ const syncPackageData = new SyncPackage(bleBytesData)
453
+ const deletePackageCmd = DeletePackage.pack(syncPackageData.id)
454
+ GizLog.debug("设备上报离线数据:payload", syncPackageData.payload)
455
+ GizLog.debug("设备上报离线数据:timestemp", syncPackageData.timestemp)
456
+
457
+ const uploadRes = await uploadP0({
458
+ device: this.syncDevice,
459
+ data: [
460
+ {
461
+ raw: arrayToString(syncPackageData.payload),
462
+ created_at: syncPackageData.timestemp
463
+ }
464
+ ]
465
+ })
466
+
467
+ GizLog.debug("上传离线数据结果", uploadRes)
468
+ this.syncCurrnetNum += 1;
469
+ // 通知设备删除
470
+ this.syncDataCallBack({
471
+ event: "SYNC_PROGRESS",
472
+ totalNum: this.syncTotalNum,
473
+ currentNum: this.syncCurrnetNum
474
+ })
475
+
476
+ GizLog.debug("通知设备删除:", syncPackageData.id)
477
+ await this.bleHandle.write(curDevice.deviceId, numberArray2Uint8Array(deletePackageCmd).buffer)
478
+ await sleep(100)
479
+ // 查询新数据
480
+ if (syncPackageData.id < this.syncTotalNum - 1) {
481
+ GizLog.debug("查询新数据:", syncPackageData.id + 1)
482
+ await this.bleHandle.write(curDevice.deviceId, numberArray2Uint8Array(SyncPackage.pack(syncPackageData.id + 1)).buffer)
483
+ } else {
484
+ // 已经同步完数据,等设备回掉
485
+ GizLog.debug("sync success wait device callback")
486
+ }
487
+ break
488
+ }
489
+ case '0058': {
490
+ if (!this.syncDataCallBack) break;
491
+ // 设备上报停止同步
492
+
493
+ const cancelData = new CancelSync(bleBytesData)
494
+ GizLog.debug("设备上报停止同步 state:", cancelData.state )
495
+
496
+ if (cancelData.state === 0) {
497
+ // 同步完成
498
+ this.syncDataCallBack({
499
+ event: "SYNC_END",
500
+ })
501
+ } else {
502
+ this.syncDataCallBack({
503
+ event: "SYNC_FAIL",
504
+ })
505
+ }
506
+ // 清除相关数据
507
+ this.cleanSyncDeviceData();
508
+ break
509
+ }
510
+ case '0060': {
511
+ // NTP回复
512
+ break
513
+ }
370
514
  }
371
515
  }
372
516
  };
@@ -618,6 +762,78 @@ class GizwitsMiniSDK {
618
762
  };
619
763
  };
620
764
 
765
+ // 设置设备的时间戳
766
+ setDeviceTimeStamp = async (device: IDevice) => {
767
+ const target = this.allDevices.find((item) => isSameDevice(item, device));
768
+ if (!target) {
769
+ return { success: false, message: 'target is undefind' };
770
+ }
771
+
772
+ const data = Ntp.pack()
773
+
774
+ switch (target.connectType) {
775
+ case 'BLE': {
776
+ return this.bleHandle.write(device.bleDeviceID, numberArray2Uint8Array(data).buffer)
777
+ }
778
+ }
779
+ return {
780
+ success: false,
781
+ message: 'the connectType not support set timestamp'
782
+ }
783
+ }
784
+
785
+ // 同步蓝牙设备的离线数据
786
+ syncDeviceData =async (device: IDevice, callback: SyncCallBack) => {
787
+ const target = this.allDevices.find((item) => isSameDevice(item, device));
788
+ if (!target) {
789
+ return { success: false, message: 'target is undefind' };
790
+ }
791
+ if (!target.isBind) {
792
+ return { success: false, message: 'Only the bound devices are supported' };
793
+ }
794
+
795
+ switch (target.connectType) {
796
+ case 'BLE': {
797
+ GizLog.debug("start syncDeviceData", device);
798
+ this.syncDataCallBack = callback;
799
+ this.syncDataTimoutTimer = setTimeout(() => {
800
+ this.syncDataCallBack({
801
+ event: 'SYNC_FAIL',
802
+ message: 'sync timeout'
803
+ })
804
+ this.cleanSyncDeviceData();
805
+ }, this.SYNC_TIMEOUT)
806
+ // 设置超时
807
+ const data = RequestSync.pack();
808
+ // 发送开始同步的指令
809
+ this.syncDevice = {...target}
810
+ GizLog.debug("sent RequestSync data");
811
+ return this.bleHandle.write(device.bleDeviceID, numberArray2Uint8Array(data).buffer)
812
+ }
813
+ }
814
+ return {
815
+ success: false,
816
+ message: 'the connectType not support sync data'
817
+ }
818
+ }
819
+
820
+ public cancelSyncDeviceData =async () => {
821
+ this.cleanSyncDeviceData();
822
+ }
823
+
824
+ private cleanSyncDeviceData = () => {
825
+ if (this.syncDataCallBack) {
826
+ this.syncDataCallBack({
827
+ event: 'SYNC_CANCEL'
828
+ })
829
+ this.syncDataCallBack = null;
830
+ }
831
+ this.syncCurrnetNum = 0;
832
+ this.syncTotalNum = 0;
833
+ this.syncDevice = null;
834
+ this.syncDataTimoutTimer && clearTimeout(this.syncDataTimoutTimer)
835
+ }
836
+
621
837
  getProductConfig = async (
622
838
  pk: string
623
839
  ): Promise<ISDKResult<IDataPointConfig>> => {
@@ -1038,5 +1254,4 @@ class GizwitsMiniSDK {
1038
1254
  this.keepScanTimer && clearInterval(this.keepScanTimer);
1039
1255
  };
1040
1256
  }
1041
-
1042
- export default GizwitsMiniSDK;
1257
+ export default GizwitsMiniSDK;
@@ -45,6 +45,7 @@ export const getBindingList = async (): Promise<IServiceResult<IDevice[]>> => {
45
45
  port: item.port,
46
46
  ws_port: item.ws_port,
47
47
  wss_port: item.wss_port,
48
+ passcode: item.passcode,
48
49
  isBleOnline: false,
49
50
  isLanOnline: false,
50
51
  connectType: 'NONE',
@@ -0,0 +1,28 @@
1
+ import openApiRequest from "../openApiRequest";
2
+
3
+ export interface IUploadRes {
4
+ }
5
+
6
+ interface IData {
7
+ raw: string;
8
+ created_at: number;
9
+ }
10
+
11
+ interface IProps {
12
+ device: IDevice;
13
+ data: IData[];
14
+ }
15
+ export async function uploadP0 ({device, data}: IProps) {
16
+ const path = `/v2/products/${device.productKey}/devices/offline-data`;
17
+ return openApiRequest<IUploadRes>(path, {
18
+ data: {
19
+ data,
20
+ encoding: 'hex',
21
+ },
22
+ method: 'POST',
23
+ headers: {
24
+ 'X-Gizwits-Device-Id': device.did,
25
+ 'X-Gizwits-Device-passcode': device.passcode,
26
+ },
27
+ }, false)
28
+ }