mini_program_gizwits_sdk 3.4.3 → 3.4.5-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/handler/ble.d.ts +2 -0
- package/dist/src/sdk.d.ts +11 -7
- package/dist/src/wifiConfig/ConfigBase.d.ts +1 -0
- 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 +19 -2
- package/src/protocol/dataPoint.ts +18 -18
- package/src/sdk.ts +75 -47
- package/src/utils.ts +15 -5
- package/src/wifiConfig/ConfigBase.ts +44 -0
- package/src/wifiConfig/ap.ts +3 -1
- package/src/wifiConfig/ble.ts +86 -23
- package/src/wifiConfig/timeZoneName.json +1 -0
|
@@ -103,6 +103,8 @@ export declare class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
103
103
|
errorMessage: string;
|
|
104
104
|
};
|
|
105
105
|
success: boolean;
|
|
106
|
+
} | {
|
|
107
|
+
success: boolean;
|
|
106
108
|
}>;
|
|
107
109
|
private getBluetoothAdapterState;
|
|
108
110
|
getDeviceStatus: (deviceId: string, productKey: string, gwDid?: string, attrNames?: string[]) => Promise<any>;
|
package/dist/src/sdk.d.ts
CHANGED
|
@@ -30,6 +30,10 @@ export interface ISetCommonDeviceOnboardingDeployProps {
|
|
|
30
30
|
export interface ISetDeviceOnboardingDeployProps extends ISetCommonDeviceOnboardingDeployProps {
|
|
31
31
|
softAPSSIDPrefix: string;
|
|
32
32
|
}
|
|
33
|
+
export interface IConfigResult {
|
|
34
|
+
mac: string;
|
|
35
|
+
productKey: string;
|
|
36
|
+
}
|
|
33
37
|
export interface IRandomCodesResult {
|
|
34
38
|
random_code: string;
|
|
35
39
|
product_key: string;
|
|
@@ -78,6 +82,7 @@ export interface IResult<T> {
|
|
|
78
82
|
}
|
|
79
83
|
interface ICloudServiceInfo {
|
|
80
84
|
openAPIInfo: string;
|
|
85
|
+
aepAPIInfo: string;
|
|
81
86
|
}
|
|
82
87
|
export type TimeoutHandle = ReturnType<typeof setTimeout> | null;
|
|
83
88
|
export type IntervalHandle = ReturnType<typeof setInterval> | null;
|
|
@@ -93,6 +98,8 @@ interface GizwitsSdkOption {
|
|
|
93
98
|
token?: string;
|
|
94
99
|
uid?: string;
|
|
95
100
|
offlineThreshold?: number;
|
|
101
|
+
accessKey?: string;
|
|
102
|
+
secretKey?: string;
|
|
96
103
|
}
|
|
97
104
|
declare class GizwitsMiniSDK {
|
|
98
105
|
private listenerMap;
|
|
@@ -159,17 +166,14 @@ declare class GizwitsMiniSDK {
|
|
|
159
166
|
login: (openID: string) => Promise<ISDKResult<ILoginRes>>;
|
|
160
167
|
getDeviceStatus: (device: IDevice, attrNames?: string[]) => Promise<any>;
|
|
161
168
|
subscribe: (device: IDevice, connectType?: TConnectType, _autoGetDeviceStatus?: boolean) => Promise<IResult<any> | {
|
|
162
|
-
success: boolean;
|
|
163
|
-
errorCode: IError;
|
|
164
|
-
} | {
|
|
165
|
-
success: boolean;
|
|
166
|
-
errorCode?: undefined;
|
|
167
|
-
} | {
|
|
168
169
|
success: boolean;
|
|
169
170
|
message: string;
|
|
170
171
|
}>;
|
|
171
172
|
unSubscribe: (device: IDevice) => Promise<{
|
|
172
173
|
success: boolean;
|
|
174
|
+
err: any;
|
|
175
|
+
} | {
|
|
176
|
+
success: boolean;
|
|
173
177
|
}>;
|
|
174
178
|
bindRemoteDevice: ({ mac, productKey, alias, beOwner, }: IBindRemoteDeviceParams) => Promise<ISDKResult<IOpenApiDevice>>;
|
|
175
179
|
checkUpdate: ({ device, type }: {
|
|
@@ -193,7 +197,7 @@ declare class GizwitsMiniSDK {
|
|
|
193
197
|
setDeviceOnboardingDeploy: ({ ssid, bssid, password, mode, timeout, isBind, softAPSSIDPrefix, }: ISetDeviceOnboardingDeployProps) => Promise<ISDKResult<IDevice[]>>;
|
|
194
198
|
private setDomain;
|
|
195
199
|
private deviceSafetyApi;
|
|
196
|
-
getBindingList: () => Promise<
|
|
200
|
+
getBindingList: () => Promise<{}>;
|
|
197
201
|
getDevices: () => Promise<ISDKResult<IDevice[]>>;
|
|
198
202
|
stopDeviceOnboardingDeploy: () => void;
|
|
199
203
|
setLogLevel: (level: TLogType) => {
|
|
@@ -14,6 +14,7 @@ declare class ConfigBase {
|
|
|
14
14
|
constructor(ssid: string, bssid: string, password: string, specialProductKeys: string[], specialProductKeySecrets: string[]);
|
|
15
15
|
cleanTimeout: () => void;
|
|
16
16
|
stopDeviceOnboardingDeploy: () => void;
|
|
17
|
+
appendExtendData: (key: string) => string;
|
|
17
18
|
hasTimeoutHandler: (cb?: IRejectCallback) => boolean;
|
|
18
19
|
handleTimeout: () => void;
|
|
19
20
|
protected searchDevice: ({ ssid, password }: {
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IConfigResult, IResult } from "../sdk";
|
|
2
2
|
import { BleHandle } from "../handler/ble";
|
|
3
3
|
import ConfigBase from "./ConfigBase";
|
|
4
|
+
interface IVerifyOnlineResult {
|
|
5
|
+
data: {
|
|
6
|
+
status: number;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
4
9
|
interface IArgs {
|
|
5
10
|
bleDeviceId: string;
|
|
6
11
|
arrayBuffer: ArrayBuffer;
|
|
@@ -31,6 +36,14 @@ declare class BLEConfig extends ConfigBase {
|
|
|
31
36
|
} | {
|
|
32
37
|
success: true;
|
|
33
38
|
}>;
|
|
39
|
+
getDeviceLastestOnlineTime: ({ productKey, mac }: {
|
|
40
|
+
productKey: string;
|
|
41
|
+
mac: string;
|
|
42
|
+
}) => Promise<import("../aepApi/aepApiRequest").IServiceResult<IVerifyOnlineResult>>;
|
|
43
|
+
verifyDeviceOnline: ({ productKey, mac }: {
|
|
44
|
+
productKey: string;
|
|
45
|
+
mac: string;
|
|
46
|
+
}) => Promise<IResult<IVerifyOnlineResult>>;
|
|
34
47
|
enableAndGetBluetoothDevices: (softAPSSIDPrefix?: string) => Promise<{
|
|
35
48
|
success: false;
|
|
36
49
|
err: IError;
|
|
@@ -39,6 +52,6 @@ declare class BLEConfig extends ConfigBase {
|
|
|
39
52
|
bleDevices?: WechatMiniprogram.BlueToothDevice[];
|
|
40
53
|
}>;
|
|
41
54
|
setDeviceOnboardingDeploy: ({ timeout, isBind, softAPSSIDPrefix, }: ISetDeviceOnboardingDeployProps) => Promise<IResult<IDevice[]>>;
|
|
42
|
-
configBLEDevice: ({ ssid, password, softAPSSIDPrefix, }: configBLEDeviceParams) => Promise<IResult<
|
|
55
|
+
configBLEDevice: ({ ssid, password, softAPSSIDPrefix, }: configBLEDeviceParams) => Promise<IResult<IConfigResult>>;
|
|
43
56
|
}
|
|
44
57
|
export default BLEConfig;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mini_program_gizwits_sdk",
|
|
3
|
-
"version": "3.4.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "3.4.5-FeiSiMan",
|
|
4
|
+
"description": "配网包增加时区",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "node_modules/mocha/bin/_mocha -r ts-node/register tests/**/*.spec.ts -file ./tests/setup-wx.js -timeout 60s",
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import request from '../request';
|
|
2
|
+
import { getGlobalData } from "../globalData";
|
|
3
|
+
import errorCode from '../errorCode';
|
|
4
|
+
|
|
5
|
+
interface IResult<T> {
|
|
6
|
+
data: T;
|
|
7
|
+
errMsg: string;
|
|
8
|
+
statusCode: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface IServiceResult<T> {
|
|
12
|
+
success: boolean;
|
|
13
|
+
data?: T;
|
|
14
|
+
err?: IError;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const aepApiRequest = async <T>(url: string, options: any, needToken: boolean = true): Promise<IServiceResult<T>> => {
|
|
18
|
+
const requestOptions = { ...options };
|
|
19
|
+
const headers: any = {
|
|
20
|
+
'Content-Type': 'application/json',
|
|
21
|
+
'accessKey': getGlobalData('accessKey'),
|
|
22
|
+
'secretKey': getGlobalData('secretKey'),
|
|
23
|
+
};
|
|
24
|
+
if (needToken) {
|
|
25
|
+
headers['Authorization'] = getGlobalData('token');
|
|
26
|
+
}
|
|
27
|
+
requestOptions.header = { ...headers, ...options.headers };
|
|
28
|
+
delete requestOptions.headers;
|
|
29
|
+
const aepApiUrl = getGlobalData('cloudServiceInfo').aepAPIInfo;
|
|
30
|
+
console.log('aepApiRequest', aepApiUrl + url, requestOptions);
|
|
31
|
+
const res = await request<IResult<T>>(aepApiUrl + url, requestOptions);
|
|
32
|
+
console.log('aepApiRequest res', res);
|
|
33
|
+
// 统一封装OPEN API的错误码
|
|
34
|
+
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
35
|
+
return {
|
|
36
|
+
success: true,
|
|
37
|
+
data: res.data
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let baseError = {
|
|
42
|
+
success: false,
|
|
43
|
+
err: {
|
|
44
|
+
errorCode: errorCode.GIZ_SDK_HTTP_REQUEST_FAILED.errorCode,
|
|
45
|
+
errorMessage: '',
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
baseError = {
|
|
50
|
+
success: false,
|
|
51
|
+
err: {
|
|
52
|
+
errorCode: (res.data as any).error_code,
|
|
53
|
+
errorMessage: (res.data as any).error_message,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
} catch (error) {
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
return baseError;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export default aepApiRequest;
|
package/src/handler/ble.ts
CHANGED
|
@@ -435,6 +435,7 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
435
435
|
// remove me in the future
|
|
436
436
|
this.openBluetoothAdapter();
|
|
437
437
|
this.notifyError({ errMsg: err.errMsg, errCode: -1 });
|
|
438
|
+
return {success: false,}
|
|
438
439
|
}
|
|
439
440
|
} else {
|
|
440
441
|
return await this.init();
|
|
@@ -555,7 +556,6 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
555
556
|
if (targetBleDev) {
|
|
556
557
|
// 存在设备,更新ctime 并更新属性
|
|
557
558
|
const newDevice = BTDevice2GDevice(device, this.pks);
|
|
558
|
-
|
|
559
559
|
if (newDevice.productKey && newDevice.mac) {
|
|
560
560
|
// 广播设备没有 bleWorkStatus
|
|
561
561
|
const isChange = this.checkDeviceIsChange(newDevice, targetBleDev);
|
|
@@ -569,6 +569,7 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
569
569
|
}
|
|
570
570
|
} else {
|
|
571
571
|
// 新增设备
|
|
572
|
+
|
|
572
573
|
let isValidDevice = this.pks.some((pk) =>
|
|
573
574
|
advertisDataStr.includes(pk)
|
|
574
575
|
);
|
|
@@ -767,7 +768,7 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
767
768
|
// 先锁定这个设备 防止被剔除
|
|
768
769
|
try {
|
|
769
770
|
this.connectingDevId = device.bleDeviceID;
|
|
770
|
-
return this._connectDevice(device);
|
|
771
|
+
return await this._connectDevice(device);
|
|
771
772
|
} finally {
|
|
772
773
|
this.connectingDevId = null;
|
|
773
774
|
}
|
|
@@ -819,6 +820,13 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
819
820
|
private handleBindReq = (deviceId: string) => {
|
|
820
821
|
// 处理设备回复绑定消息
|
|
821
822
|
return new Promise<IDeviceReq<string>>((res) => {
|
|
823
|
+
const timer = setTimeout(() => {
|
|
824
|
+
GizLog.debug('绑定协议执行超时');
|
|
825
|
+
res({
|
|
826
|
+
success: false,
|
|
827
|
+
data: ''
|
|
828
|
+
})
|
|
829
|
+
}, 5* 1000)
|
|
822
830
|
const onListener = (
|
|
823
831
|
_curDevice: WechatMiniprogram.OnBLECharacteristicValueChangeListenerResult,
|
|
824
832
|
hexString: string
|
|
@@ -826,6 +834,7 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
826
834
|
if (_curDevice.deviceId !== deviceId) {
|
|
827
835
|
return;
|
|
828
836
|
}
|
|
837
|
+
timer && clearTimeout(timer)
|
|
829
838
|
GizLog.log('监听蓝牙特征值发生变化');
|
|
830
839
|
const bindData = new Bind(hexStrint2byte(hexString));
|
|
831
840
|
this.removeEventListener('GizBleDeviceData', onListener);
|
|
@@ -849,6 +858,13 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
849
858
|
|
|
850
859
|
private handleLoginReq = (deviceId) => {
|
|
851
860
|
return new Promise<IDeviceReq<String>>((res) => {
|
|
861
|
+
const timer = setTimeout(() => {
|
|
862
|
+
GizLog.debug('登录协议执行超时');
|
|
863
|
+
res({
|
|
864
|
+
success: false,
|
|
865
|
+
data: ''
|
|
866
|
+
})
|
|
867
|
+
}, 5* 1000)
|
|
852
868
|
const onListener = (
|
|
853
869
|
_curDevice: WechatMiniprogram.OnBLECharacteristicValueChangeListenerResult,
|
|
854
870
|
hexString: string
|
|
@@ -857,6 +873,7 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
857
873
|
if (_curDevice.deviceId !== deviceId) {
|
|
858
874
|
return;
|
|
859
875
|
}
|
|
876
|
+
timer && clearTimeout(timer)
|
|
860
877
|
GizLog.log('设备回复LoginReq', hexString);
|
|
861
878
|
const loginData = new Login(hexStrint2byte(hexString));
|
|
862
879
|
this.removeEventListener('GizBleDeviceData', onListener);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import productConfigFileManage from "../productConfigFileManage";
|
|
2
|
-
import { arrayToString, checkHeader, fillString, getProtocolLen, hexStrint2byte, completeBlock} from "./tool";
|
|
2
|
+
import { arrayToString, checkHeader, fillString, getProtocolLen, hexStrint2byte, completeBlock } from "./tool";
|
|
3
3
|
|
|
4
4
|
export interface IDataPointConfig {
|
|
5
5
|
name: string;
|
|
@@ -35,7 +35,7 @@ type TDataOptionType = 'status_writable' | 'status_readonly' | 'alert' | 'fault'
|
|
|
35
35
|
export interface IDataPointAttr {
|
|
36
36
|
display_name: string;
|
|
37
37
|
uint_spec: IUnitSpec;
|
|
38
|
-
name:string;
|
|
38
|
+
name: string;
|
|
39
39
|
data_type: TDataType;
|
|
40
40
|
position: IDataPointPosition;
|
|
41
41
|
type: TDataOptionType;
|
|
@@ -181,7 +181,7 @@ const DataPointToP = ({ config, data, isAdaptiveDatapoint }: IDataPointToP0Param
|
|
|
181
181
|
*/
|
|
182
182
|
const flag = [0];
|
|
183
183
|
const headerCmd = [0, 147]; // cmd
|
|
184
|
-
const sn = [0,0,0,0];
|
|
184
|
+
const sn = [0, 0, 0, 0];
|
|
185
185
|
|
|
186
186
|
// 业务指令命令字 定长上报是4,变长上报是14
|
|
187
187
|
let cmd = [0x1];
|
|
@@ -194,7 +194,7 @@ const DataPointToP = ({ config, data, isAdaptiveDatapoint }: IDataPointToP0Param
|
|
|
194
194
|
|
|
195
195
|
// 找到可写
|
|
196
196
|
if (!isAdaptiveDatapoint) {
|
|
197
|
-
attrsConfig = attrsConfig.filter(item => item.type ==='status_writable')
|
|
197
|
+
attrsConfig = attrsConfig.filter(item => item.type === 'status_writable')
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
attrsConfig.map((item) => {
|
|
@@ -265,7 +265,7 @@ const DataPointToP = ({ config, data, isAdaptiveDatapoint }: IDataPointToP0Param
|
|
|
265
265
|
return {
|
|
266
266
|
data: packageData,
|
|
267
267
|
raw: {
|
|
268
|
-
header: [0,0,0,3],
|
|
268
|
+
header: [0, 0, 0, 3],
|
|
269
269
|
flag,
|
|
270
270
|
len: lengthArr,
|
|
271
271
|
headerCmd,
|
|
@@ -274,7 +274,7 @@ const DataPointToP = ({ config, data, isAdaptiveDatapoint }: IDataPointToP0Param
|
|
|
274
274
|
}
|
|
275
275
|
};
|
|
276
276
|
};
|
|
277
|
-
|
|
277
|
+
|
|
278
278
|
interface IPToDataPointParams {
|
|
279
279
|
config: IDataPointAttr[];
|
|
280
280
|
data: number[];
|
|
@@ -316,7 +316,7 @@ function PToDataPoint({ config = [], data }: IPToDataPointParams) {
|
|
|
316
316
|
let action: number;
|
|
317
317
|
let message = '';
|
|
318
318
|
let messageType: messageType;
|
|
319
|
-
const rawData: IRawData = { header: arrayToString(data.slice(0, 4)), flag: '', len: '', cmd: '', sn: '',action: '', payload: '' };
|
|
319
|
+
const rawData: IRawData = { header: arrayToString(data.slice(0, 4)), flag: '', len: '', cmd: '', sn: '', action: '', payload: '' };
|
|
320
320
|
// 获取数据长度 0,0,0,3 到 0 这一段都是长度 校验长度可以忽略
|
|
321
321
|
const attrs = config;
|
|
322
322
|
|
|
@@ -662,7 +662,7 @@ function calculationCmdData({ attrs, flagString, boolEnumLength, cmdData, accumu
|
|
|
662
662
|
const unpack = async (data: number[], pk: string) => {
|
|
663
663
|
const productConfig = await productConfigFileManage.getConfigFile(pk);
|
|
664
664
|
if (productConfig) {
|
|
665
|
-
const resData =
|
|
665
|
+
const resData = PToDataPoint({ config: (await productConfig).entities[0].attrs, data })
|
|
666
666
|
if (resData.kvData) {
|
|
667
667
|
// 格式化binary
|
|
668
668
|
resData.kvData = await formatBinary(resData?.kvData, pk, 'object');
|
|
@@ -675,16 +675,16 @@ const pack = async (data: object, pk: string) => {
|
|
|
675
675
|
const productConfig = await productConfigFileManage.getConfigFile(pk);
|
|
676
676
|
if (productConfig) {
|
|
677
677
|
const isAdaptiveDatapoint = productConfig.protocolType === 'var_len';
|
|
678
|
-
return DataPointToP({data, config: (await productConfig).entities[0].attrs, isAdaptiveDatapoint});
|
|
678
|
+
return DataPointToP({ data, config: (await productConfig).entities[0].attrs, isAdaptiveDatapoint });
|
|
679
679
|
}
|
|
680
680
|
return null;
|
|
681
681
|
}
|
|
682
682
|
|
|
683
683
|
const padBoradcastData = (data: number[]) => {
|
|
684
|
-
const head = [0,0,0,3];
|
|
684
|
+
const head = [0, 0, 0, 3];
|
|
685
685
|
const flag = [0];
|
|
686
686
|
const headerCmd = [0, 0x93]; // cmd
|
|
687
|
-
const sn = [0, 0, 0
|
|
687
|
+
const sn = [0, 0, 0, 0];
|
|
688
688
|
const flagToEnd = flag.concat(headerCmd).concat(sn).concat(data);
|
|
689
689
|
const lengthArr: number[] = getVariableLength(flagToEnd);
|
|
690
690
|
return arrayToString(head.concat(lengthArr).concat(flagToEnd));
|
|
@@ -692,10 +692,10 @@ const padBoradcastData = (data: number[]) => {
|
|
|
692
692
|
|
|
693
693
|
type TargetType = 'int' | 'string';
|
|
694
694
|
// 格式化enum 兼容sdk 和 socket 之间的差异
|
|
695
|
-
const formatEnum = async (attrs: any, pk: string, targetType: TargetType
|
|
696
|
-
for(let key in attrs) {
|
|
695
|
+
const formatEnum = async (attrs: any, pk: string, targetType: TargetType) => {
|
|
696
|
+
for (let key in attrs) {
|
|
697
697
|
const itemData = await productConfigFileManage.getAttrItem(pk, key);
|
|
698
|
-
if (itemData && itemData.data_type ==='enum') {
|
|
698
|
+
if (itemData && itemData.data_type === 'enum') {
|
|
699
699
|
if (targetType === 'int' && typeof attrs[key] === 'string') {
|
|
700
700
|
// 转成int
|
|
701
701
|
const enumIndex = itemData.enum.findIndex(item => item === attrs[key]);
|
|
@@ -710,10 +710,10 @@ const formatEnum = async (attrs: any, pk: string, targetType: TargetType ) => {
|
|
|
710
710
|
}
|
|
711
711
|
|
|
712
712
|
type BTargetType = 'string' | 'object';
|
|
713
|
-
const formatBinary = async (attrs: any, pk: string, targetType: BTargetType
|
|
714
|
-
for(let key in attrs) {
|
|
713
|
+
const formatBinary = async (attrs: any, pk: string, targetType: BTargetType) => {
|
|
714
|
+
for (let key in attrs) {
|
|
715
715
|
const itemData = await productConfigFileManage.getAttrItem(pk, key);
|
|
716
|
-
if (itemData && itemData.data_type ==='binary') {
|
|
716
|
+
if (itemData && itemData.data_type === 'binary') {
|
|
717
717
|
if (targetType === 'object' && typeof attrs[key] === 'string') {
|
|
718
718
|
attrs[key] = hexStrint2byte(attrs[key])
|
|
719
719
|
}
|
|
@@ -725,4 +725,4 @@ const formatBinary = async (attrs: any, pk: string, targetType: BTargetType ) =>
|
|
|
725
725
|
return attrs
|
|
726
726
|
}
|
|
727
727
|
|
|
728
|
-
export {pack, unpack, padBoradcastData, formatEnum, formatBinary};
|
|
728
|
+
export { pack, unpack, padBoradcastData, formatEnum, formatBinary };
|
package/src/sdk.ts
CHANGED
|
@@ -74,6 +74,12 @@ export interface ISetDeviceOnboardingDeployProps
|
|
|
74
74
|
softAPSSIDPrefix: string;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
export interface IConfigResult {
|
|
78
|
+
mac: string;
|
|
79
|
+
productKey: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
77
83
|
export interface IRandomCodesResult {
|
|
78
84
|
random_code: string;
|
|
79
85
|
product_key: string;
|
|
@@ -132,6 +138,7 @@ export interface IResult<T> {
|
|
|
132
138
|
|
|
133
139
|
interface ICloudServiceInfo {
|
|
134
140
|
openAPIInfo: string;
|
|
141
|
+
aepAPIInfo: string;
|
|
135
142
|
}
|
|
136
143
|
|
|
137
144
|
export type TimeoutHandle = ReturnType<typeof setTimeout> | null;
|
|
@@ -148,6 +155,8 @@ interface GizwitsSdkOption {
|
|
|
148
155
|
token?: string;
|
|
149
156
|
uid?: string;
|
|
150
157
|
offlineThreshold?: number;
|
|
158
|
+
accessKey?: string; // 京东平台接口请求参数
|
|
159
|
+
secretKey?: string;// 京东平台接口请求参数
|
|
151
160
|
}
|
|
152
161
|
|
|
153
162
|
class GizwitsMiniSDK {
|
|
@@ -211,7 +220,8 @@ class GizwitsMiniSDK {
|
|
|
211
220
|
}
|
|
212
221
|
});
|
|
213
222
|
|
|
214
|
-
const connectionMap = this.socketHandle._connections;
|
|
223
|
+
// const connectionMap = this.socketHandle._connections;
|
|
224
|
+
const connectionMap = {};
|
|
215
225
|
|
|
216
226
|
Object.keys(connectionMap).forEach((wsInfo) => {
|
|
217
227
|
const conn = connectionMap[wsInfo];
|
|
@@ -298,16 +308,16 @@ class GizwitsMiniSDK {
|
|
|
298
308
|
}
|
|
299
309
|
|
|
300
310
|
private get socketHandle() {
|
|
301
|
-
if (!this._gizSocket) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}
|
|
311
|
+
// if (!this._gizSocket) {
|
|
312
|
+
// this._gizSocket = new GizwitsWS({
|
|
313
|
+
// appID: getGlobalData('appID'),
|
|
314
|
+
// token: getGlobalData('token'),
|
|
315
|
+
// uid: getGlobalData('uid'),
|
|
316
|
+
// });
|
|
317
|
+
// this._gizSocket.subscribeDeviceStatus(this.handleSocketDeviceData);
|
|
318
|
+
// this._gizSocket.subscribeBindingChanged(this.getBindingList);
|
|
319
|
+
// this._gizSocket.subscribeSocketStatus(this.handleSocketStatus);
|
|
320
|
+
// }
|
|
311
321
|
return this._gizSocket;
|
|
312
322
|
}
|
|
313
323
|
|
|
@@ -320,6 +330,8 @@ class GizwitsMiniSDK {
|
|
|
320
330
|
token,
|
|
321
331
|
uid,
|
|
322
332
|
offlineThreshold,
|
|
333
|
+
accessKey,
|
|
334
|
+
secretKey
|
|
323
335
|
}: GizwitsSdkOption) => {
|
|
324
336
|
this.productInfo = productInfo;
|
|
325
337
|
// 保存相关信息
|
|
@@ -327,7 +339,10 @@ class GizwitsMiniSDK {
|
|
|
327
339
|
setGlobalData('appSecret', appSecret);
|
|
328
340
|
setGlobalData('productInfo', productInfo);
|
|
329
341
|
setGlobalData('token', token);
|
|
342
|
+
console.log('SDK init', token);
|
|
330
343
|
setGlobalData('uid', uid);
|
|
344
|
+
setGlobalData('accessKey', accessKey);
|
|
345
|
+
setGlobalData('secretKey', secretKey);
|
|
331
346
|
|
|
332
347
|
/**
|
|
333
348
|
* 同时也设置域名信息
|
|
@@ -342,7 +357,7 @@ class GizwitsMiniSDK {
|
|
|
342
357
|
* lan 比较特殊
|
|
343
358
|
* 初始化sdk的时候就要开始扫描设备
|
|
344
359
|
*/
|
|
345
|
-
this.initLan();
|
|
360
|
+
// this.initLan();
|
|
346
361
|
}
|
|
347
362
|
public reInit(props: GizwitsSdkOption) {
|
|
348
363
|
this.init(props);
|
|
@@ -359,7 +374,7 @@ class GizwitsMiniSDK {
|
|
|
359
374
|
openAPIInfo !== getGlobalData('cloudServiceInfo').openAPIInfo
|
|
360
375
|
) {
|
|
361
376
|
// 需要重启
|
|
362
|
-
this.socketHandle.destory();
|
|
377
|
+
// this.socketHandle.destory();
|
|
363
378
|
this._gizSocket = null;
|
|
364
379
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
365
380
|
this.socketHandle;
|
|
@@ -726,22 +741,26 @@ class GizwitsMiniSDK {
|
|
|
726
741
|
* @returns {Promise<{success: boolean, err: string}>}
|
|
727
742
|
*/
|
|
728
743
|
public initBle = async (): Promise<ISDKResult<null>> => {
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
744
|
+
try {
|
|
745
|
+
this.bleHandle.addEventListener(
|
|
746
|
+
'GizBleDeviceData',
|
|
747
|
+
this.handleBleDeviceData
|
|
748
|
+
);
|
|
749
|
+
this.bleHandle.addEventListener('GizBleDeviceList', this.handleBleDevices);
|
|
750
|
+
this.bleHandle.addEventListener('GizBleError', this.handleBleError);
|
|
751
|
+
const permissionData = await this.bleHandle.checkPermission();
|
|
752
|
+
if (!permissionData.success) {
|
|
753
|
+
GizLog.error('init BLE Error', new Error(JSON.stringify(permissionData)));
|
|
754
|
+
return {
|
|
755
|
+
success: false,
|
|
756
|
+
err: errorCode.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON,
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
GizLog.debug('init BLE succcess', permissionData);
|
|
760
|
+
} catch (error) {
|
|
761
|
+
GizLog.error('init BLE error', error);
|
|
762
|
+
return {success: false, err: errorCode.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON}
|
|
736
763
|
}
|
|
737
|
-
|
|
738
|
-
this.bleHandle.addEventListener(
|
|
739
|
-
'GizBleDeviceData',
|
|
740
|
-
this.handleBleDeviceData
|
|
741
|
-
);
|
|
742
|
-
this.bleHandle.addEventListener('GizBleDeviceList', this.handleBleDevices);
|
|
743
|
-
this.bleHandle.addEventListener('GizBleError', this.handleBleError);
|
|
744
|
-
GizLog.debug('init BLE succcess', permissionData);
|
|
745
764
|
return { success: true };
|
|
746
765
|
};
|
|
747
766
|
|
|
@@ -794,7 +813,7 @@ class GizwitsMiniSDK {
|
|
|
794
813
|
case 'WAN': {
|
|
795
814
|
// 枚举要转换成枚举值
|
|
796
815
|
const newAttrs = await formatEnum(attrs, target.productKey, 'string')
|
|
797
|
-
|
|
816
|
+
return;
|
|
798
817
|
return this.socketHandle.writeData(target, newAttrs);
|
|
799
818
|
}
|
|
800
819
|
case 'LAN': {
|
|
@@ -835,6 +854,7 @@ class GizwitsMiniSDK {
|
|
|
835
854
|
}
|
|
836
855
|
}
|
|
837
856
|
case 'WAN': {
|
|
857
|
+
return { success: false };
|
|
838
858
|
return this.socketHandle.send(target.did, data);
|
|
839
859
|
}
|
|
840
860
|
case 'LAN': {
|
|
@@ -986,7 +1006,7 @@ class GizwitsMiniSDK {
|
|
|
986
1006
|
if (data.success) {
|
|
987
1007
|
setGlobalData('token', data.data?.token);
|
|
988
1008
|
setGlobalData('uid', data.data?.uid);
|
|
989
|
-
this.socketHandle.updateToken({token: data.data.token, uid: data.data.uid})
|
|
1009
|
+
// this.socketHandle.updateToken({token: data.data.token, uid: data.data.uid})
|
|
990
1010
|
}
|
|
991
1011
|
return data;
|
|
992
1012
|
};
|
|
@@ -1007,6 +1027,7 @@ class GizwitsMiniSDK {
|
|
|
1007
1027
|
);
|
|
1008
1028
|
}
|
|
1009
1029
|
case 'WAN':
|
|
1030
|
+
return { success: false, }
|
|
1010
1031
|
return this.socketHandle.readStatus(target, attrNames);
|
|
1011
1032
|
default: {
|
|
1012
1033
|
return {
|
|
@@ -1075,11 +1096,12 @@ class GizwitsMiniSDK {
|
|
|
1075
1096
|
// const target = this.deviceList.find((item) =>
|
|
1076
1097
|
// isSameDevice(item, device)
|
|
1077
1098
|
// );
|
|
1078
|
-
const data = this.socketHandle.connectDevice(target);
|
|
1079
|
-
if (data.success) {
|
|
1080
|
-
|
|
1081
|
-
}
|
|
1082
|
-
return data;
|
|
1099
|
+
// const data = this.socketHandle.connectDevice(target);
|
|
1100
|
+
// if (data.success) {
|
|
1101
|
+
// this.setDeviceMeta(device, 'connectType', 'WAN', true);
|
|
1102
|
+
// }
|
|
1103
|
+
// return data;
|
|
1104
|
+
return { success: false, }
|
|
1083
1105
|
}
|
|
1084
1106
|
case 'LAN': {
|
|
1085
1107
|
const data = await this.lanHandle.connectDevice(target);
|
|
@@ -1115,11 +1137,14 @@ class GizwitsMiniSDK {
|
|
|
1115
1137
|
return disconnectRes;
|
|
1116
1138
|
}
|
|
1117
1139
|
case 'WAN': {
|
|
1118
|
-
const res = this.socketHandle.disConnectDevice(target);
|
|
1119
|
-
if (res.success) {
|
|
1120
|
-
|
|
1121
|
-
}
|
|
1122
|
-
return res;
|
|
1140
|
+
// const res = this.socketHandle.disConnectDevice(target);
|
|
1141
|
+
// if (res.success) {
|
|
1142
|
+
// this.setDeviceMeta(target, 'connectType', 'NONE', true);
|
|
1143
|
+
// }
|
|
1144
|
+
// return res;
|
|
1145
|
+
return {
|
|
1146
|
+
success: false,
|
|
1147
|
+
};
|
|
1123
1148
|
}
|
|
1124
1149
|
case 'LAN': {
|
|
1125
1150
|
const res = this.lanHandle.disConnectDevice(target);
|
|
@@ -1401,8 +1426,10 @@ class GizwitsMiniSDK {
|
|
|
1401
1426
|
private setDomain = (cloudServiceInfo: ICloudServiceInfo) => {
|
|
1402
1427
|
const openAPIInfo =
|
|
1403
1428
|
(cloudServiceInfo && cloudServiceInfo.openAPIInfo) || 'api.gizwits.com';
|
|
1429
|
+
const aepAPIInfo =
|
|
1430
|
+
(cloudServiceInfo && cloudServiceInfo.aepAPIInfo) || 'https://mini-dev.viessmann.cn/';
|
|
1404
1431
|
|
|
1405
|
-
const newData = { ...(cloudServiceInfo || {}), openAPIInfo };
|
|
1432
|
+
const newData = { ...(cloudServiceInfo || {}), openAPIInfo, aepAPIInfo };
|
|
1406
1433
|
setGlobalData('cloudServiceInfo', newData);
|
|
1407
1434
|
};
|
|
1408
1435
|
|
|
@@ -1429,11 +1456,12 @@ class GizwitsMiniSDK {
|
|
|
1429
1456
|
|
|
1430
1457
|
// 内部刷新设备列表的方法
|
|
1431
1458
|
public getBindingList = async () => {
|
|
1432
|
-
const data = await getBindingList();
|
|
1433
|
-
this.deviceList = data.data || [];
|
|
1434
|
-
// 推送
|
|
1435
|
-
this.notiDeviceList();
|
|
1436
|
-
return data;
|
|
1459
|
+
// const data = await getBindingList();
|
|
1460
|
+
// this.deviceList = data.data || [];
|
|
1461
|
+
// // 推送
|
|
1462
|
+
// this.notiDeviceList();
|
|
1463
|
+
// return data;
|
|
1464
|
+
return {}
|
|
1437
1465
|
};
|
|
1438
1466
|
|
|
1439
1467
|
/**
|
|
@@ -1532,7 +1560,7 @@ class GizwitsMiniSDK {
|
|
|
1532
1560
|
public destory = () => {
|
|
1533
1561
|
this.bleHandle.destory();
|
|
1534
1562
|
this.lanHandle.destory();
|
|
1535
|
-
this.socketHandle.destory();
|
|
1563
|
+
// this.socketHandle.destory();
|
|
1536
1564
|
this.keepScanTimer && clearInterval(this.keepScanTimer);
|
|
1537
1565
|
};
|
|
1538
1566
|
}
|
package/src/utils.ts
CHANGED
|
@@ -136,11 +136,12 @@ const parseAdv = (advertisData: ArrayBuffer, pks: string[]) => {
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
const tmpBytes = advertisData.slice(index + 1, index + len + 1);
|
|
139
|
-
if (len >= 6 && len <=
|
|
140
|
-
mac
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
139
|
+
if (len >= 6 && len <= 15) {
|
|
140
|
+
// 菲斯曼的mac需要转化下
|
|
141
|
+
const nums = Array.prototype.map.call(new Uint8Array(tmpBytes), function (bit) {
|
|
142
|
+
return bit;
|
|
143
|
+
});
|
|
144
|
+
mac = numberArrToASCIIString(nums);
|
|
144
145
|
}
|
|
145
146
|
|
|
146
147
|
if (len == 16) {
|
|
@@ -157,6 +158,15 @@ const parseAdv = (advertisData: ArrayBuffer, pks: string[]) => {
|
|
|
157
158
|
return {bleWorkStatus, mac, productKey}
|
|
158
159
|
}
|
|
159
160
|
|
|
161
|
+
// 数值数组转字符串(按AscII码转化)
|
|
162
|
+
function numberArrToASCIIString(nums: number[]) {
|
|
163
|
+
// 数值数组转字符串(按AscII码转化)
|
|
164
|
+
let str = '';
|
|
165
|
+
for (let i = 0; i < nums.length; i++) {
|
|
166
|
+
str += String.fromCharCode(nums[i]);
|
|
167
|
+
}
|
|
168
|
+
return str;
|
|
169
|
+
}
|
|
160
170
|
|
|
161
171
|
export const advertisData2PkAndMac = (
|
|
162
172
|
advertisData: ArrayBuffer,
|