mini_program_gizwits_sdk 3.2.7 → 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.
- package/README.md +8 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/src/{handler/ble.d.ts → ble.d.ts} +27 -47
- package/dist/src/productConfigFileManage.d.ts +0 -1
- package/dist/src/protocol/DataPoint.d.ts +2 -17
- package/dist/src/protocol/tool.d.ts +1 -3
- package/dist/src/sdk.d.ts +20 -54
- package/dist/src/{handler/socket.d.ts → socket.d.ts} +10 -26
- package/dist/src/utils.d.ts +1 -18
- package/dist/src/wechatApi.d.ts +1 -4
- package/dist/src/wifiConfig/ble.d.ts +1 -5
- package/package.json +2 -2
- package/src/handler/ble.ts +29 -29
- package/src/protocol/Ntp.ts +3 -3
- package/src/protocol/OffLineData.ts +9 -6
- package/src/protocol/WifiConfig.ts +1 -0
- package/src/sdk.ts +46 -13
- package/src/services/uploadP0.ts +31 -3
- package/dist/src/GizLog.d.ts +0 -18
- package/dist/src/handler/EventListener.d.ts +0 -9
- package/dist/src/handler/lan.d.ts +0 -93
- package/dist/src/protocol/DiscoverUdp.d.ts +0 -17
- package/dist/src/protocol/Ntp.d.ts +0 -5
- package/dist/src/protocol/OffLineData.d.ts +0 -23
- package/dist/src/sentry.d.ts +0 -2
- package/dist/src/services/uploadP0.d.ts +0 -12
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
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
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({
|
|
@@ -481,8 +505,12 @@ class GizwitsMiniSDK {
|
|
|
481
505
|
GizLog.debug("查询新数据:", syncPackageData.id + 1)
|
|
482
506
|
await this.bleHandle.write(curDevice.deviceId, numberArray2Uint8Array(SyncPackage.pack(syncPackageData.id + 1)).buffer)
|
|
483
507
|
} else {
|
|
484
|
-
//
|
|
485
|
-
GizLog.debug("sync
|
|
508
|
+
// 结束同步
|
|
509
|
+
GizLog.debug("send cancel sync to device")
|
|
510
|
+
this.bleHandle.write(curDevice.deviceId, numberArray2Uint8Array(CancelSync.pack()).buffer)
|
|
511
|
+
this.syncDataCallBack({
|
|
512
|
+
event: "SYNC_END",
|
|
513
|
+
})
|
|
486
514
|
}
|
|
487
515
|
break
|
|
488
516
|
}
|
|
@@ -929,8 +957,13 @@ class GizwitsMiniSDK {
|
|
|
929
957
|
// 连接BLE
|
|
930
958
|
const data = await this.bleHandle.connectDevice(target.bleDeviceID);
|
|
931
959
|
if (data.success) {
|
|
960
|
+
|
|
932
961
|
// 蓝牙设备比较特殊,在get 里面从bleHandle里找到连接的设备,再把connectType 设置成BLE,所以这里更新metaData 要强制更新并推送
|
|
933
962
|
this.setDeviceMeta(target, 'connectType', 'BLE', true);
|
|
963
|
+
setTimeout(() => {
|
|
964
|
+
// 蓝牙设备连接成功之后默认设置一次ntp
|
|
965
|
+
this.setDeviceTimeStamp(target)
|
|
966
|
+
}, 250)
|
|
934
967
|
setTimeout(() => {
|
|
935
968
|
this.getDeviceStatus(target);
|
|
936
969
|
}, 500);
|
package/src/services/uploadP0.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import openApiRequest from "../openApiRequest";
|
|
2
|
+
import { enc, AES, mode, pad } from 'crypto-js';
|
|
2
3
|
|
|
3
4
|
export interface IUploadRes {
|
|
4
5
|
}
|
|
@@ -11,9 +12,19 @@ interface IData {
|
|
|
11
12
|
interface IProps {
|
|
12
13
|
device: IDevice;
|
|
13
14
|
data: IData[];
|
|
15
|
+
productSecret: string;
|
|
14
16
|
}
|
|
15
|
-
export async function uploadP0 ({device, data}: IProps) {
|
|
17
|
+
export async function uploadP0 ({device, data, productSecret}: IProps) {
|
|
16
18
|
const path = `/v2/products/${device.productKey}/devices/offline-data`;
|
|
19
|
+
|
|
20
|
+
let passCode = device.passcode
|
|
21
|
+
|
|
22
|
+
const key = enc.Hex.parse(productSecret);
|
|
23
|
+
const iv = enc.Hex.parse('');
|
|
24
|
+
const srcs = enc.Utf8.parse(passCode);
|
|
25
|
+
const encrypted = AES.encrypt(srcs, key, { iv: iv, mode: mode.ECB, padding: pad.Pkcs7 });
|
|
26
|
+
passCode = encrypted.ciphertext.toString().toUpperCase();
|
|
27
|
+
|
|
17
28
|
return openApiRequest<IUploadRes>(path, {
|
|
18
29
|
data: {
|
|
19
30
|
data,
|
|
@@ -22,7 +33,24 @@ export async function uploadP0 ({device, data}: IProps) {
|
|
|
22
33
|
method: 'POST',
|
|
23
34
|
headers: {
|
|
24
35
|
'X-Gizwits-Device-Id': device.did,
|
|
25
|
-
'X-Gizwits-Device-passcode':
|
|
36
|
+
'X-Gizwits-Device-passcode': passCode,
|
|
26
37
|
},
|
|
27
38
|
}, false)
|
|
28
|
-
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// setTimeout(() => {
|
|
42
|
+
// uploadP0({
|
|
43
|
+
// device: {
|
|
44
|
+
// productKey: "8da73e49a9c74d6e9321b4383b44e4e9",
|
|
45
|
+
// did: "SlJJzMGa0MDOmhUTt0PIul",
|
|
46
|
+
// passcode: "1234567890",
|
|
47
|
+
// },
|
|
48
|
+
// data: [
|
|
49
|
+
// {
|
|
50
|
+
// raw: "00000003",
|
|
51
|
+
// created_at: parseInt(`${Date.now() / 1000}`, 10)
|
|
52
|
+
// }
|
|
53
|
+
// ],
|
|
54
|
+
// productSecret: "bf5df28e904b455f85fa5be1805945ad"
|
|
55
|
+
// })
|
|
56
|
+
// }, 3000)
|
package/dist/src/GizLog.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export declare type TLogType = 'debug' | 'info' | 'warn' | 'error';
|
|
2
|
-
declare class Log {
|
|
3
|
-
logMap: {
|
|
4
|
-
id: string;
|
|
5
|
-
}[];
|
|
6
|
-
console: any;
|
|
7
|
-
debug: (...data: any[]) => void;
|
|
8
|
-
info: (...data: any[]) => void;
|
|
9
|
-
log: (...data: any[]) => void;
|
|
10
|
-
warn: (...data: any[]) => void;
|
|
11
|
-
error: (info: string, error: Error) => void;
|
|
12
|
-
setLogLevel: (type: TLogType) => {
|
|
13
|
-
success: boolean;
|
|
14
|
-
err: IError;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
declare const _default: Log;
|
|
18
|
-
export default _default;
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import DiscoverUDP from "../protocol/DiscoverUdp";
|
|
2
|
-
import { IResult } from "../sdk";
|
|
3
|
-
import EventListener from "./EventListener";
|
|
4
|
-
interface ConnectDevice {
|
|
5
|
-
mac: string;
|
|
6
|
-
productKey: string;
|
|
7
|
-
socketHandle: TCPHandler;
|
|
8
|
-
}
|
|
9
|
-
interface ILanDevice extends IDevice {
|
|
10
|
-
expandData: DiscoverUDP;
|
|
11
|
-
ip: string;
|
|
12
|
-
}
|
|
13
|
-
declare type GizLanDeviceListNotifications = (devices: IDevice[]) => void;
|
|
14
|
-
declare type GizLanDeviceDataNotifications = (mac: string, data: string) => void;
|
|
15
|
-
export interface TLanHandleEvent {
|
|
16
|
-
GizLanDeviceList: GizLanDeviceListNotifications;
|
|
17
|
-
GizLanDeviceData: GizLanDeviceDataNotifications;
|
|
18
|
-
}
|
|
19
|
-
export declare class LanHandle extends EventListener<TLanHandleEvent> {
|
|
20
|
-
connectedList: ConnectDevice[];
|
|
21
|
-
private pks;
|
|
22
|
-
scanList: ILanDevice[];
|
|
23
|
-
private boradcastTimer;
|
|
24
|
-
private UDPSocket;
|
|
25
|
-
private deviceUDPPort;
|
|
26
|
-
private appUDPPort;
|
|
27
|
-
private offlineThreshold;
|
|
28
|
-
private isActive;
|
|
29
|
-
private listenDevOfflineTimer;
|
|
30
|
-
constructor({ pks }: {
|
|
31
|
-
pks: any;
|
|
32
|
-
});
|
|
33
|
-
init: () => void;
|
|
34
|
-
private onAppShow;
|
|
35
|
-
private onAppHide;
|
|
36
|
-
private listenDevOffline;
|
|
37
|
-
private notifyDevices;
|
|
38
|
-
private notifyDeviceData;
|
|
39
|
-
isSameDevice: (deviceA: IDevice, deviceB: IDevice) => boolean;
|
|
40
|
-
disConnectDevice: (target: IDevice) => {
|
|
41
|
-
success: boolean;
|
|
42
|
-
err?: undefined;
|
|
43
|
-
} | {
|
|
44
|
-
success: boolean;
|
|
45
|
-
err: any;
|
|
46
|
-
};
|
|
47
|
-
onData: (mac: string, hexString: string) => void;
|
|
48
|
-
connectDevice: (device: any) => Promise<IResult<any>>;
|
|
49
|
-
onError: (err: any) => void;
|
|
50
|
-
isMatchPk: (pk: any) => boolean;
|
|
51
|
-
onMessage: (res: WechatMiniprogram.UDPSocketOnMessageCallbackResult) => void;
|
|
52
|
-
onDeviceClose: ({ productKey, mac }: {
|
|
53
|
-
productKey: any;
|
|
54
|
-
mac: any;
|
|
55
|
-
}) => void;
|
|
56
|
-
write: (device: IDevice, value: ArrayBuffer) => Promise<{
|
|
57
|
-
success: boolean;
|
|
58
|
-
} | {
|
|
59
|
-
success: boolean;
|
|
60
|
-
message: string;
|
|
61
|
-
}>;
|
|
62
|
-
updateDevice: (updateDevice: DiscoverUDP, ip: string) => void;
|
|
63
|
-
sendBoradCast: () => void;
|
|
64
|
-
private startDiscover;
|
|
65
|
-
destory: () => void;
|
|
66
|
-
}
|
|
67
|
-
interface ITCPHandlerProps {
|
|
68
|
-
ip: string;
|
|
69
|
-
mac: string;
|
|
70
|
-
productKey: string;
|
|
71
|
-
onClose: (ip: any) => void;
|
|
72
|
-
onData: (mac: string, data: string) => void;
|
|
73
|
-
}
|
|
74
|
-
declare class TCPHandler {
|
|
75
|
-
private deviceTCPPort;
|
|
76
|
-
private ip;
|
|
77
|
-
private productKey;
|
|
78
|
-
private mac;
|
|
79
|
-
private tcpHandler;
|
|
80
|
-
private onData;
|
|
81
|
-
private onCloseListener;
|
|
82
|
-
constructor({ ip, onClose, mac, productKey, onData }: ITCPHandlerProps);
|
|
83
|
-
connect: () => Promise<IResult<any>>;
|
|
84
|
-
write: (data: ArrayBuffer) => {
|
|
85
|
-
success: boolean;
|
|
86
|
-
};
|
|
87
|
-
onMessage: (message: any) => void;
|
|
88
|
-
onError: () => void;
|
|
89
|
-
onClose: () => void;
|
|
90
|
-
initListener: () => void;
|
|
91
|
-
destory: () => void;
|
|
92
|
-
}
|
|
93
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import ProtocolBase from "./ProtocolBase";
|
|
2
|
-
declare type TDecodeType = 'ASCII' | 'HEX';
|
|
3
|
-
declare class DiscoverUDP extends ProtocolBase {
|
|
4
|
-
did: string;
|
|
5
|
-
mac: string;
|
|
6
|
-
productKey: string;
|
|
7
|
-
deviceType: number;
|
|
8
|
-
apiUrl: string;
|
|
9
|
-
protocolVersion: string;
|
|
10
|
-
mcuVersion: string;
|
|
11
|
-
moduleVersion: string;
|
|
12
|
-
constructor(data: number[]);
|
|
13
|
-
parseEndChat: (index: any, key: any) => any;
|
|
14
|
-
baseParse: (index: any, key: any, type?: TDecodeType) => any;
|
|
15
|
-
static pack: () => Uint8Array;
|
|
16
|
-
}
|
|
17
|
-
export default DiscoverUDP;
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/src/sentry.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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 {};
|