mini_program_gizwits_sdk 3.2.9 → 3.2.10-kuka

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.
@@ -1,19 +1,5 @@
1
- import { wrapErrorInfo } from '../utils';
2
- import EventListener from './EventListener';
3
- declare type GizBleDeviceListotifications = (devices: IDevice[]) => void;
4
- declare type GizBleDeviceDataNotifications = (curDevice: WechatMiniprogram.OnBLECharacteristicValueChangeCallbackResult, hexString: string) => void;
5
- declare type GizBleErrorNotifications = (err: {
6
- errCode: number;
7
- errMsg: string;
8
- }) => void;
9
- export interface TBleHandleEvent {
10
- GizBleDeviceData: GizBleDeviceDataNotifications;
11
- GizBleDeviceList: GizBleDeviceListotifications;
12
- GizBleError: GizBleErrorNotifications;
13
- }
14
- export interface GizwitsWxBlueToothDevice extends WechatMiniprogram.BlueToothDevice {
15
- communicationType: 'BLE_BROADCAST' | 'BLE';
16
- }
1
+ import { wrapErrorInfo } from './utils';
2
+ import Sdk from './Sdk';
17
3
  interface BleHandleParams {
18
4
  serviceUUIDSuffix: string;
19
5
  characteristicUUIDSuffix: string;
@@ -32,34 +18,26 @@ interface ConnectDevice {
32
18
  interface ConstructorParams {
33
19
  pks: string[];
34
20
  bleHandleParams?: BleHandleParams;
21
+ globalListenerMap: object;
22
+ gizSdk: Sdk;
35
23
  offlineThreshold?: number;
36
24
  }
37
- export declare class BleHandle extends EventListener<TBleHandleEvent> {
25
+ export declare class BleHandle {
38
26
  private serviceUUIDSuffix;
39
27
  connectedList: ConnectDevice[];
40
- private connectingDevId;
41
28
  private pks;
42
- private listenDevOfflineTimer;
43
- private boradcastTimer;
44
- private boradcastDataCache;
45
29
  private tmpBleData;
46
30
  private tmpDataNum;
47
- private disableScanFlag;
48
- private peripheralServer;
49
- private isActive;
31
+ private listenerMap;
32
+ private globalListenerMap;
50
33
  scanList: IDevice[];
51
- constructor({ pks, bleHandleParams, offlineThreshold, }: ConstructorParams);
52
- private onBluetoothAdapterStateChange;
53
- private onAppShow;
54
- private onAppHide;
34
+ private gizSdk;
35
+ constructor({ pks, bleHandleParams, globalListenerMap, gizSdk, offlineThreshold, }: ConstructorParams);
55
36
  private listenDevOffline;
56
37
  private openBluetoothAdapter;
57
38
  private handleOnBLECharacteristicValueChange;
58
- private notiDeviceDataToSdk;
59
39
  private notifyError;
60
- private notifyDevices;
61
40
  private listenConnection;
62
- private init;
63
41
  checkPermission: () => Promise<{
64
42
  data: {
65
43
  discovering: boolean;
@@ -71,40 +49,43 @@ export declare class BleHandle extends EventListener<TBleHandleEvent> {
71
49
  success: boolean;
72
50
  }>;
73
51
  private getBluetoothAdapterState;
74
- getDeviceStatus: (deviceId: string, productKey: string, gwDid?: string, attrNames?: string[]) => Promise<import("../wechatApi").IWechatResult | {
52
+ getDeviceStatus: (deviceId: string, productKey: string, gwDid?: string, attrNames?: string[]) => Promise<import("./wechatApi").IWechatResult | {
75
53
  success: boolean;
76
54
  message: string;
55
+ errbody: {
56
+ serviceId: string;
57
+ characteristicId: string;
58
+ };
77
59
  } | {
78
60
  success: boolean;
79
61
  }>;
80
- private updateDevice;
81
- private updateCtime;
82
- private checkDeviceIsChange;
83
62
  private handleBluetoothDeviceFound;
84
63
  startScan: (onScanDevice: OnScanDevice, delay?: number) => Promise<IStartScanResult>;
85
- stopScan: () => Promise<any>;
86
- disableScan: () => Promise<WechatMiniprogram.BluetoothError>;
87
- enableScan: () => void;
64
+ stopScan: () => Promise<{
65
+ errMsg: string;
66
+ errCode: number;
67
+ }>;
88
68
  connectDevice: (deviceId: string) => Promise<{
89
69
  success: boolean;
90
70
  message: any;
91
71
  }>;
92
72
  private handleBindReq;
93
73
  private handleLoginReq;
94
- watchBleDevice: (deviceId: any, func: any) => Promise<{
95
- success: boolean;
74
+ removeDeviceListener: (deviceId: string, onDeviceStatusChange: any) => {
96
75
  message: string;
97
- }>;
98
- writeBoradcast: (bleDeviceID: string, value: number[]) => Promise<{
99
76
  success: boolean;
100
- message: string;
101
- } | {
77
+ };
78
+ addDeviceListener: (deviceId: any, onDeviceStatusChange: (curDevice: WechatMiniprogram.OnBLECharacteristicValueChangeCallbackResult, hexString: string) => void) => Promise<{
102
79
  success: boolean;
103
- message?: undefined;
80
+ message: string;
104
81
  }>;
105
- write: (bleDeviceID: string, value: ArrayBuffer) => Promise<import("../wechatApi").IWechatResult | {
82
+ write: (deviceId: string, value: ArrayBuffer) => Promise<import("./wechatApi").IWechatResult | {
106
83
  success: boolean;
107
84
  message: string;
85
+ errbody: {
86
+ serviceId: string;
87
+ characteristicId: string;
88
+ };
108
89
  }>;
109
90
  disConnectDevice: (deviceId: string) => Promise<{
110
91
  err: string;
@@ -112,6 +93,5 @@ export declare class BleHandle extends EventListener<TBleHandleEvent> {
112
93
  }>;
113
94
  private removeDevById;
114
95
  private getTargetDevice;
115
- destory: () => void;
116
96
  }
117
97
  export {};
@@ -7,7 +7,6 @@ declare class ProductConfigFileManage {
7
7
  key: string;
8
8
  init: () => Promise<void>;
9
9
  getConfigFile: (pk: string) => Promise<IDataPointConfig>;
10
- getAttrItem: (pk: string, key: string) => Promise<import("./protocol/DataPoint").IDataPointAttr>;
11
10
  }
12
11
  declare const productConfigFileManage: ProductConfigFileManage;
13
12
  export default productConfigFileManage;
@@ -48,20 +48,5 @@ declare const unpack: (data: number[], pk: string) => Promise<{
48
48
  message: string;
49
49
  messageType: messageType;
50
50
  }>;
51
- declare const pack: (data: object, pk: string) => Promise<{
52
- data: number[];
53
- raw: {
54
- header: number[];
55
- flag: number[];
56
- len: number[];
57
- headerCmd: number[];
58
- sn: number[];
59
- cmd: number[];
60
- };
61
- }>;
62
- declare const padBoradcastData: (data: number[]) => string;
63
- declare type TargetType = 'int' | 'string';
64
- declare const formatEnum: (attrs: any, pk: string, targetType: TargetType) => Promise<any>;
65
- declare type BTargetType = 'string' | 'object';
66
- declare const formatBinary: (attrs: any, pk: string, targetType: BTargetType) => Promise<any>;
67
- export { pack, unpack, padBoradcastData, formatEnum, formatBinary };
51
+ declare const pack: (data: object, pk: string) => Promise<number[]>;
52
+ export { pack, unpack };
@@ -1,5 +1,4 @@
1
1
  declare const checkHeader: (data: any) => number | false;
2
- export declare const completeBlock: (cmd: string) => number[];
3
2
  declare const getProtocolLen: (data: any) => number;
4
3
  declare function arrayToString(arr: number[]): string;
5
4
  declare const fillString: (string: string, num: number, foot?: boolean) => string;
@@ -7,5 +6,4 @@ declare const string2Bytes: (str: string) => number[];
7
6
  declare const hexStrint2byte: (str: string) => number[];
8
7
  declare const formatCode: (str: any) => number[];
9
8
  declare const formatCodesFromStr: (str: string) => number[][];
10
- declare const arrayToUint8: (config: number[]) => Uint8Array;
11
- export { checkHeader, getProtocolLen, arrayToString, fillString, string2Bytes, hexStrint2byte, formatCodesFromStr, formatCode, arrayToUint8 };
9
+ export { checkHeader, getProtocolLen, arrayToString, fillString, string2Bytes, hexStrint2byte, formatCodesFromStr, formatCode };
package/dist/src/sdk.d.ts CHANGED
@@ -1,15 +1,6 @@
1
- import { TLogType } from './GizLog';
2
1
  import { ILoginRes } from './services/login';
3
2
  import { IOpenApiDevice, ISafeRegisterReturn, IUnbindReturn } from './services/devices';
4
3
  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;
13
4
  interface ISDKResult<T> {
14
5
  data?: T;
15
6
  err?: IError;
@@ -90,82 +81,57 @@ interface GizwitsSdkOption {
90
81
  uid?: string;
91
82
  offlineThreshold?: number;
92
83
  }
93
- declare class GizwitsMiniSDK {
84
+ declare class SDK {
94
85
  private version;
95
86
  private listenerMap;
96
- private keepScanTimer;
97
87
  private _deviceList;
98
88
  private get deviceList();
99
89
  private set deviceList(value);
100
90
  private _bleDevices;
101
91
  get bleDevices(): IDevice[];
102
92
  set bleDevices(data: IDevice[]);
103
- private _lanDevices;
104
- private get lanDevices();
105
- private set lanDevices(value);
93
+ private _udpDevices;
94
+ private get udpDevices();
95
+ private set udpDevices(value);
106
96
  private get allDevices();
97
+ private set allDevice(value);
107
98
  private get bleScanDevice();
108
99
  private productInfo;
109
100
  private currentWifiConfigHandle;
110
101
  private _bleHandle;
111
- private _lanHandle;
102
+ private autoScanInterval;
112
103
  private _gizSocket;
113
104
  private offlineThreshold?;
114
- private syncDataCallBack?;
115
- private syncTotalNum;
116
- private syncCurrnetNum;
117
- private syncDataTimoutTimer;
118
- private SYNC_TIMEOUT;
119
- private syncDevice?;
120
105
  constructor({ appID, appSecret, productInfo, cloudServiceInfo, token, uid, offlineThreshold, }: GizwitsSdkOption);
121
106
  private get bleHandle();
122
- private get lanHandle();
123
107
  private get socketHandle();
124
108
  get specialProductKeys(): string[];
125
109
  get specialProductKeySecrets(): string[];
126
- private handleBleError;
127
- private handleBleDevices;
128
- handleLanDevices: (devices: IDevice[]) => void;
129
- private handleLanDeviceData;
130
110
  private handleBleDeviceData;
131
111
  private handleSocketDeviceData;
132
112
  private handleSocketStatus;
133
113
  private notiDeviceList;
134
- private initLan;
135
114
  startAutoScan: () => void;
136
115
  stopAutoScan: () => 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;
116
+ setDeviceMeta: <K extends "name" | "mac" | "productKey" | "did" | "bleWorkStatus" | "isBind" | "rootDeviceId" | "bleDeviceID" | "remark" | "connectType" | "isOnline" | "isLanOnline" | "isBleOnline" | "host" | "wss_port" | "ctime">(curDev: IDevice, key: K, value: IDevice[K]) => void;
138
117
  getVersion: () => {
139
118
  success: boolean;
140
119
  data: string;
141
120
  };
142
121
  initBle: () => Promise<ISDKResult<null>>;
143
122
  scanBleDevice: (delay: number) => Promise<ISDKResult<IDevice[]>>;
144
- write: (device: IDevice, attrs: object) => Promise<import("./wechatApi").IWechatResult | {
145
- success: boolean;
146
- message: string;
147
- } | {
148
- success: boolean;
149
- message?: undefined;
150
- }>;
151
- writeRaw: (device: IDevice, data: number[]) => Promise<IError | import("./wechatApi").IWechatResult | {
152
- success: boolean;
153
- }>;
154
- setDeviceTimeStamp: (device: IDevice) => Promise<import("./wechatApi").IWechatResult | {
155
- success: boolean;
156
- message: string;
157
- }>;
158
- syncDeviceData: (device: IDevice, callback: SyncCallBack) => Promise<import("./wechatApi").IWechatResult | {
123
+ write: (device: IDevice, attrs: object) => Promise<{
159
124
  success: boolean;
160
125
  message: string;
161
126
  }>;
162
- cancelSyncDeviceData: () => Promise<void>;
163
- private cleanSyncDeviceData;
164
127
  getProductConfig: (pk: string) => Promise<ISDKResult<IDataPointConfig>>;
165
128
  stopScanBleDevice: () => void;
166
129
  login: (openID: string) => Promise<ISDKResult<ILoginRes>>;
167
130
  getDeviceStatus: (device: IDevice, attrNames?: string[]) => Promise<import("./wechatApi").IWechatResult | {
168
131
  success: boolean;
132
+ } | {
133
+ success: boolean;
134
+ message: string;
169
135
  }>;
170
136
  subscribe: (device: IDevice, connectType?: TConnectType, _autoGetDeviceStatus?: boolean) => Promise<{
171
137
  success: boolean;
@@ -173,8 +139,13 @@ declare class GizwitsMiniSDK {
173
139
  } | {
174
140
  success: boolean;
175
141
  errorCode: IError;
176
- } | IResult<any>>;
142
+ } | {
143
+ success: boolean;
144
+ }>;
177
145
  unSubscribe: (device: IDevice) => Promise<{
146
+ err: string;
147
+ success: boolean;
148
+ } | {
178
149
  success: boolean;
179
150
  }>;
180
151
  bindRemoteDevice: ({ mac, productKey, alias, beOwner, }: IBindRemoteDeviceParams) => Promise<ISDKResult<IOpenApiDevice>>;
@@ -189,16 +160,11 @@ declare class GizwitsMiniSDK {
189
160
  getBindingList: () => Promise<import("./openApiRequest").IServiceResult<IDevice[]>>;
190
161
  getDevices: () => Promise<ISDKResult<IDevice[]>>;
191
162
  stopDeviceOnboardingDeploy: () => void;
192
- setLogLevel: (level: TLogType) => {
193
- success: boolean;
194
- err: IError;
195
- };
196
- removeEventListener: <K extends "GizDeviceListNotifications" | "GizDeviceStatusNotifications" | "GizDeviceAttrsNotifications" | "onScanListChange" | "onBleHandleError">(type: K, func: TListenerType[K]) => {
163
+ removeEventListener: <K extends "onBleHandleError" | "GizDeviceListNotifications" | "GizDeviceStatusNotifications" | "GizDeviceAttrsNotifications" | "onScanListChange">(type: K, func: TListenerType[K]) => {
197
164
  success: boolean;
198
165
  };
199
- addEventListener: <K extends "GizDeviceListNotifications" | "GizDeviceStatusNotifications" | "GizDeviceAttrsNotifications" | "onScanListChange" | "onBleHandleError">(type: K, func: TListenerType[K]) => Promise<{
166
+ addEventListener: <K extends "onBleHandleError" | "GizDeviceListNotifications" | "GizDeviceStatusNotifications" | "GizDeviceAttrsNotifications" | "onScanListChange">(type: K, func: TListenerType[K]) => Promise<{
200
167
  success: boolean;
201
168
  }>;
202
- destory: () => void;
203
169
  }
204
- export default GizwitsMiniSDK;
170
+ export default SDK;
@@ -1,10 +1,6 @@
1
1
  interface IRespError {
2
2
  err?: IError;
3
3
  }
4
- interface IWriteRes {
5
- success: boolean;
6
- message: string;
7
- }
8
4
  interface ICommonProps {
9
5
  appID: string;
10
6
  token: string;
@@ -29,11 +25,7 @@ export default class GizwitsWS {
29
25
  _onBindingChanged?: IEmptyFn;
30
26
  constructor({ appID, token, uid, limitSocketNum, }: IGWSProps);
31
27
  init(): Promise<IError>;
32
- updateToken: ({ token, uid }: {
33
- token: any;
34
- uid: any;
35
- }) => void;
36
- _getDevice: (did: string) => IDevice | IError;
28
+ _getDevice: (did: string) => IError | IDevice;
37
29
  _getConnect: (device: IDevice) => Connection;
38
30
  _getDeviceAndConnect: (did: string) => IError | [IDevice, Connection];
39
31
  connectDevice: (device: IDevice) => {
@@ -43,20 +35,17 @@ export default class GizwitsWS {
43
35
  success: boolean;
44
36
  errorCode?: undefined;
45
37
  };
46
- disConnectDevice: (device: IDevice) => {
47
- success: boolean;
48
- };
49
38
  connect: (did: string) => IError;
50
- send: (did: string, raw: number[]) => IError | Promise<IWriteRes>;
51
- writeData: (device: IDevice, attrs: ICommonObj) => Promise<IWriteRes> | {
39
+ send: (did: string, raw: Uint8Array[]) => IError | Promise<WechatMiniprogram.GeneralCallbackResult>;
40
+ writeData: (device: IDevice, attrs: ICommonObj) => {
52
41
  success: boolean;
53
42
  };
54
- write: (did: string, attrs: ICommonObj) => IError | Promise<IWriteRes>;
43
+ write: (did: string, attrs: ICommonObj) => IError | Promise<WechatMiniprogram.GeneralCallbackResult>;
55
44
  readStatus: (device: IDevice, names?: string[]) => {
56
45
  success: boolean;
57
46
  };
58
- read: (did: string, names?: string[]) => IError | Promise<IWriteRes>;
59
- destory: () => void;
47
+ read: (did: string, names?: string[]) => IError | Promise<WechatMiniprogram.GeneralCallbackResult>;
48
+ close: () => void;
60
49
  subscribeDeviceStatus: (cb: IOnDeviceStatusChanged) => void;
61
50
  subscribeBindingChanged: (cb: IEmptyFn) => void;
62
51
  subscribeSocketStatus: (cb: IOnSocketStatusChanged) => void;
@@ -94,17 +83,13 @@ export declare class Connection {
94
83
  _onBindingChanged?: IEmptyFn;
95
84
  _onSocketStatusChanged?: IOnSocketStatusChanged;
96
85
  _waitSends: object[];
97
- _checkConnectTimerId?: any;
98
86
  constructor({ appID, token, uid, wsInfo, onDeviceStatusChanged, onBindingChanged, onSocketStatusChanged, }: IConnectProps);
99
- destory: () => void;
100
- _networkChange: (res: WechatMiniprogram.OnNetworkStatusChangeCallbackResult) => Promise<void>;
101
- _appShow: () => Promise<void>;
87
+ _networkChange: (res: WechatMiniprogram.OnNetworkStatusChangeCallbackResult) => void;
88
+ _appShow: () => void;
102
89
  _addSubDid: (did: any) => void;
103
- _removeSubDid: (did: any) => void;
104
90
  _connectWS: () => void;
105
91
  _subDevices: (dids: string[]) => void;
106
- _unSubDevices: (dids: string[]) => void;
107
- _send: (data: object, forced?: boolean) => Promise<IWriteRes>;
92
+ _send: (data: object, forced?: boolean) => Promise<WechatMiniprogram.GeneralCallbackResult>;
108
93
  close: () => void;
109
94
  handleClose: (res: {
110
95
  code: number;
@@ -132,8 +117,7 @@ export declare class Connection {
132
117
  }) => void;
133
118
  _rawChangedResp: (data: IDeviceRawStatusChangedProps) => void;
134
119
  _statusChangedResp: (data: IDeviceStatusChangedProps) => void;
135
- _isSub: (did: string) => boolean;
136
120
  _invalidMsgResp: (data: any) => void;
137
- _bindingChangedResp: (data: any) => void;
121
+ _bindingChangedResp: () => void;
138
122
  }
139
123
  export {};
@@ -1,5 +1,4 @@
1
1
  import { IProductInfo } from './sdk';
2
- import { GizwitsWxBlueToothDevice } from './handler/ble';
3
2
  export declare function ab2hex(buffer: ArrayBuffer): any;
4
3
  export declare function compareWXSDKVersion(v1: string, v2: string): 0 | 1 | -1;
5
4
  export declare const isError: (err: unknown) => err is IError;
@@ -23,25 +22,9 @@ export declare const advertisData2PkAndMac: (advertisData: ArrayBuffer, pks: str
23
22
  export declare const isSameDevice: (deviceA: IDevice, deviceB: IDevice) => boolean;
24
23
  export declare const merageBleLocalDevices: (mainDevice: IDevice[], localDevice: IDevice[]) => IDevice[];
25
24
  export declare const merageLanLocalDevices: (mainDevice: IDevice[], localDevice: IDevice[]) => IDevice[];
26
- export declare const BTDevice2GDevice: (BTDevice: GizwitsWxBlueToothDevice, pks: string[]) => IDevice;
25
+ export declare const BTDevice2GDevice: (BTDevice: WechatMiniprogram.BlueToothDevice, pks: string[]) => IDevice;
27
26
  export declare const getFirstConnectType: (device: IDevice, type?: TConnectType) => TConnectType;
28
27
  export declare const getProductInfoThroughPK: (pk: string, productInfos: IProductInfo[]) => IProductInfo;
29
28
  export declare const mergeObject: (obj1: any, obj2: any) => any;
30
29
  export declare function hex2ab(str: any): Uint8Array;
31
- declare type BroadcastCmd = 0x19 | 0x94;
32
- declare type TBoradcastRes = {
33
- mac: string;
34
- cmd: BroadcastCmd;
35
- data: string[];
36
- };
37
- export declare function parseBroadcastData(data: number[]): TBoradcastRes;
38
- export declare function ab2numbers(buffer: ArrayBuffer): any;
39
- export declare function encrypt(uuids: number[], key: number): string[];
40
- export declare const convertToServiceUuids: ({ len, data, index, mac }: {
41
- len?: any;
42
- data?: any;
43
- index?: number;
44
- mac: any;
45
- }) => any;
46
- export declare function convertToUuids(mac: number, sn: number, data: number[]): string[];
47
30
  export {};
@@ -6,13 +6,10 @@ export interface IWechatResult {
6
6
  errMsg: string;
7
7
  errCode: number;
8
8
  }
9
- export declare function retryConnect(deviceId: string, timeout?: number): Promise<IWechatResult | {
10
- success: boolean;
11
- }>;
12
9
  export declare function openBluetoothAdapter(): Promise<IWechatResult>;
13
10
  export declare function closeBluetoothAdapter(): Promise<IWechatResult>;
14
11
  export declare function getBluetoothAdapterState(): Promise<IBluetoothAdapterStateResult>;
15
- export declare function startBluetoothDevicesDiscovery(allowDuplicatesKey?: boolean): Promise<IWechatResult>;
12
+ export declare function startBluetoothDevicesDiscovery(): Promise<IWechatResult>;
16
13
  export declare function getBluetoothDevices(): Promise<WechatMiniprogram.BlueToothDevice[]>;
17
14
  export declare function createBLEConnection(deviceId: string, timeout: number): Promise<IWechatResult>;
18
15
  interface IBLEService {
@@ -1,14 +1,12 @@
1
1
  import { IRandomCodesResult, IResult } from "../sdk";
2
2
  import ConfigBase from "./ConfigBase";
3
- import { BleHandle } from "../handler/ble";
4
3
  interface IArgs {
5
4
  bleDeviceId: string;
6
5
  arrayBuffer: ArrayBuffer;
7
6
  serviceUUIDSuffix?: string;
8
7
  characteristicUUIDSuffix?: string;
9
- bleHandle: BleHandle;
10
8
  }
11
- export declare function sendBLEConfigCmd({ bleDeviceId, arrayBuffer, serviceUUIDSuffix, characteristicUUIDSuffix, bleHandle }: IArgs): Promise<boolean | void>;
9
+ export declare function sendBLEConfigCmd({ bleDeviceId, arrayBuffer, serviceUUIDSuffix, characteristicUUIDSuffix, }: IArgs): Promise<boolean | void>;
12
10
  interface configBLEDeviceParams {
13
11
  ssid: string;
14
12
  password: string;
@@ -21,8 +19,6 @@ interface ISetDeviceOnboardingDeployProps {
21
19
  softAPSSIDPrefix: string;
22
20
  }
23
21
  declare class BLEConfig extends ConfigBase {
24
- bleHandle: BleHandle;
25
- constructor(ssid: string, password: string, specialProductKeys: string[], specialProductKeySecrets: string[], bleHandle: BleHandle);
26
22
  destroy: () => void;
27
23
  isValidBleDevice: (bleDevice: WechatMiniprogram.BlueToothDevice, softAPSSIDPrefix?: string) => boolean;
28
24
  enableBluetoothDevicesDescovery: () => Promise<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mini_program_gizwits_sdk",
3
- "version": "3.2.9",
3
+ "version": "3.2.10-kuka",
4
4
  "description": "增加离线数据同步",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -91,8 +91,8 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
91
91
  constructor({
92
92
  pks = [],
93
93
  bleHandleParams = {
94
- serviceUUIDSuffix: 'abf0',
95
- characteristicUUIDSuffix: 'abf7',
94
+ serviceUUIDSuffix: 'fe60',
95
+ characteristicUUIDSuffix: 'fe61',
96
96
  },
97
97
  offlineThreshold,
98
98
  }: ConstructorParams) {
@@ -195,7 +195,6 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
195
195
  if (!curDevice.value) {
196
196
  return;
197
197
  }
198
- console.log('handleOnBLECharacteristicValueChange', curDevice)
199
198
  const hexString = ab2hex(curDevice.value);
200
199
  try {
201
200
  const data = new ProtocolBase(hexStrint2byte(hexString));
@@ -469,7 +468,8 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
469
468
 
470
469
  GizLog.debug("GIZ_SDK: start scan", delay);
471
470
  await wx.startBluetoothDevicesDiscovery({
472
- services: ['ABF8', 'ABF0', 'F0AB', 'F8AB'],
471
+ services: [],
472
+
473
473
  powerLevel: 'high',
474
474
  allowDuplicatesKey: true,
475
475
  interval: 200,
@@ -576,31 +576,31 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
576
576
  })
577
577
  .catch((err) => this.notifyError(err));
578
578
 
579
- this.write(deviceId, numberArray2Uint8Array(Bind.pack()).buffer);
580
- const data = await this.handleBindReq(deviceId);
581
- GizLog.log('handleBindReq', data);
582
-
583
- if (data.success) {
584
- this.write(
585
- deviceId,
586
- numberArray2Uint8Array(Login.pack({ passcode: data.data })).buffer
587
- );
588
- const loginData = (await this.handleLoginReq(deviceId).catch((err) =>
589
- this.notifyError(err)
590
- )) as any;
591
- if (loginData?.success) {
592
-
593
- return {
594
- success: true,
595
- message: 'ok',
596
- };
597
- }
598
- }
599
-
600
- // 绑定失败,异常退出断开蓝牙
601
- await wx.closeBLEConnection({
602
- deviceId,
603
- });
579
+ // this.write(deviceId, numberArray2Uint8Array(Bind.pack()).buffer);
580
+ // const data = await this.handleBindReq(deviceId);
581
+ // GizLog.log('handleBindReq', data);
582
+
583
+ // if (data.success) {
584
+ // this.write(
585
+ // deviceId,
586
+ // numberArray2Uint8Array(Login.pack({ passcode: data.data })).buffer
587
+ // );
588
+ // const loginData = (await this.handleLoginReq(deviceId).catch((err) =>
589
+ // this.notifyError(err)
590
+ // )) as any;
591
+ // if (loginData?.success) {
592
+
593
+ // return {
594
+ // success: true,
595
+ // message: 'ok',
596
+ // };
597
+ // }
598
+ // }
599
+
600
+ // // 绑定失败,异常退出断开蓝牙
601
+ // await wx.closeBLEConnection({
602
+ // deviceId,
603
+ // });
604
604
 
605
605
  return {
606
606
  success: false,
package/src/sdk.ts CHANGED
@@ -404,6 +404,26 @@ class GizwitsMiniSDK {
404
404
  case '0094':
405
405
  case '0090':
406
406
  case '0091': {
407
+ // 设备上报的指令,上传给后台
408
+ console.debug('handleBleDeviceData', hexString, target)
409
+ if (target.passcode) {
410
+ const productConfig = this.productInfo.find(item => item.productKey === target.productKey)
411
+ if (productConfig) {
412
+ uploadP0({
413
+ device: target,
414
+ data: [
415
+ {
416
+ raw: hexString,
417
+ created_at: parseInt(`${Date.now() / 1000}`, 10)
418
+ }
419
+ ],
420
+ productSecret: productConfig.productSecret,
421
+ }).then(data => {
422
+ console.debug('uploadP0 res', data)
423
+ })
424
+ }
425
+
426
+ }
407
427
  const data = await unpack(hexStrint2byte(hexString), target.productKey);
408
428
  // 如果有kydata 则上报
409
429
  if (data?.kvData && this.listenerMap['GizDeviceAttrsNotifications']) {
@@ -454,17 +474,21 @@ class GizwitsMiniSDK {
454
474
  GizLog.debug("设备上报离线数据:payload", syncPackageData.payload)
455
475
  GizLog.debug("设备上报离线数据:timestemp", syncPackageData.timestemp)
456
476
 
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)
477
+ const productConfig = this.productInfo.find(item => item.productKey === this.syncDevice.productKey)
478
+ if(productConfig) {
479
+ const uploadRes = await uploadP0({
480
+ device: this.syncDevice,
481
+ data: [
482
+ {
483
+ raw: arrayToString(syncPackageData.payload),
484
+ created_at: syncPackageData.timestemp
485
+ }
486
+ ],
487
+ productSecret: productConfig.productSecret
488
+ })
489
+ GizLog.debug("上传离线数据结果", uploadRes)
490
+ }
491
+
468
492
  this.syncCurrnetNum += 1;
469
493
  // 通知设备删除
470
494
  this.syncDataCallBack({
@@ -933,8 +957,13 @@ class GizwitsMiniSDK {
933
957
  // 连接BLE
934
958
  const data = await this.bleHandle.connectDevice(target.bleDeviceID);
935
959
  if (data.success) {
960
+
936
961
  // 蓝牙设备比较特殊,在get 里面从bleHandle里找到连接的设备,再把connectType 设置成BLE,所以这里更新metaData 要强制更新并推送
937
962
  this.setDeviceMeta(target, 'connectType', 'BLE', true);
963
+ setTimeout(() => {
964
+ // 蓝牙设备连接成功之后默认设置一次ntp
965
+ this.setDeviceTimeStamp(target)
966
+ }, 250)
938
967
  setTimeout(() => {
939
968
  this.getDeviceStatus(target);
940
969
  }, 500);