mini_program_gizwits_sdk 3.4.4 → 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/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 +0 -1
- package/src/protocol/dataPoint.ts +18 -18
- package/src/sdk.ts +56 -32
- 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
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
|
@@ -556,7 +556,6 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
556
556
|
if (targetBleDev) {
|
|
557
557
|
// 存在设备,更新ctime 并更新属性
|
|
558
558
|
const newDevice = BTDevice2GDevice(device, this.pks);
|
|
559
|
-
|
|
560
559
|
if (newDevice.productKey && newDevice.mac) {
|
|
561
560
|
// 广播设备没有 bleWorkStatus
|
|
562
561
|
const isChange = this.checkDeviceIsChange(newDevice, targetBleDev);
|
|
@@ -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;
|
|
@@ -798,7 +813,7 @@ class GizwitsMiniSDK {
|
|
|
798
813
|
case 'WAN': {
|
|
799
814
|
// 枚举要转换成枚举值
|
|
800
815
|
const newAttrs = await formatEnum(attrs, target.productKey, 'string')
|
|
801
|
-
|
|
816
|
+
return;
|
|
802
817
|
return this.socketHandle.writeData(target, newAttrs);
|
|
803
818
|
}
|
|
804
819
|
case 'LAN': {
|
|
@@ -839,6 +854,7 @@ class GizwitsMiniSDK {
|
|
|
839
854
|
}
|
|
840
855
|
}
|
|
841
856
|
case 'WAN': {
|
|
857
|
+
return { success: false };
|
|
842
858
|
return this.socketHandle.send(target.did, data);
|
|
843
859
|
}
|
|
844
860
|
case 'LAN': {
|
|
@@ -990,7 +1006,7 @@ class GizwitsMiniSDK {
|
|
|
990
1006
|
if (data.success) {
|
|
991
1007
|
setGlobalData('token', data.data?.token);
|
|
992
1008
|
setGlobalData('uid', data.data?.uid);
|
|
993
|
-
this.socketHandle.updateToken({token: data.data.token, uid: data.data.uid})
|
|
1009
|
+
// this.socketHandle.updateToken({token: data.data.token, uid: data.data.uid})
|
|
994
1010
|
}
|
|
995
1011
|
return data;
|
|
996
1012
|
};
|
|
@@ -1011,6 +1027,7 @@ class GizwitsMiniSDK {
|
|
|
1011
1027
|
);
|
|
1012
1028
|
}
|
|
1013
1029
|
case 'WAN':
|
|
1030
|
+
return { success: false, }
|
|
1014
1031
|
return this.socketHandle.readStatus(target, attrNames);
|
|
1015
1032
|
default: {
|
|
1016
1033
|
return {
|
|
@@ -1079,11 +1096,12 @@ class GizwitsMiniSDK {
|
|
|
1079
1096
|
// const target = this.deviceList.find((item) =>
|
|
1080
1097
|
// isSameDevice(item, device)
|
|
1081
1098
|
// );
|
|
1082
|
-
const data = this.socketHandle.connectDevice(target);
|
|
1083
|
-
if (data.success) {
|
|
1084
|
-
|
|
1085
|
-
}
|
|
1086
|
-
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, }
|
|
1087
1105
|
}
|
|
1088
1106
|
case 'LAN': {
|
|
1089
1107
|
const data = await this.lanHandle.connectDevice(target);
|
|
@@ -1119,11 +1137,14 @@ class GizwitsMiniSDK {
|
|
|
1119
1137
|
return disconnectRes;
|
|
1120
1138
|
}
|
|
1121
1139
|
case 'WAN': {
|
|
1122
|
-
const res = this.socketHandle.disConnectDevice(target);
|
|
1123
|
-
if (res.success) {
|
|
1124
|
-
|
|
1125
|
-
}
|
|
1126
|
-
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
|
+
};
|
|
1127
1148
|
}
|
|
1128
1149
|
case 'LAN': {
|
|
1129
1150
|
const res = this.lanHandle.disConnectDevice(target);
|
|
@@ -1405,8 +1426,10 @@ class GizwitsMiniSDK {
|
|
|
1405
1426
|
private setDomain = (cloudServiceInfo: ICloudServiceInfo) => {
|
|
1406
1427
|
const openAPIInfo =
|
|
1407
1428
|
(cloudServiceInfo && cloudServiceInfo.openAPIInfo) || 'api.gizwits.com';
|
|
1429
|
+
const aepAPIInfo =
|
|
1430
|
+
(cloudServiceInfo && cloudServiceInfo.aepAPIInfo) || 'https://mini-dev.viessmann.cn/';
|
|
1408
1431
|
|
|
1409
|
-
const newData = { ...(cloudServiceInfo || {}), openAPIInfo };
|
|
1432
|
+
const newData = { ...(cloudServiceInfo || {}), openAPIInfo, aepAPIInfo };
|
|
1410
1433
|
setGlobalData('cloudServiceInfo', newData);
|
|
1411
1434
|
};
|
|
1412
1435
|
|
|
@@ -1433,11 +1456,12 @@ class GizwitsMiniSDK {
|
|
|
1433
1456
|
|
|
1434
1457
|
// 内部刷新设备列表的方法
|
|
1435
1458
|
public getBindingList = async () => {
|
|
1436
|
-
const data = await getBindingList();
|
|
1437
|
-
this.deviceList = data.data || [];
|
|
1438
|
-
// 推送
|
|
1439
|
-
this.notiDeviceList();
|
|
1440
|
-
return data;
|
|
1459
|
+
// const data = await getBindingList();
|
|
1460
|
+
// this.deviceList = data.data || [];
|
|
1461
|
+
// // 推送
|
|
1462
|
+
// this.notiDeviceList();
|
|
1463
|
+
// return data;
|
|
1464
|
+
return {}
|
|
1441
1465
|
};
|
|
1442
1466
|
|
|
1443
1467
|
/**
|
|
@@ -1536,7 +1560,7 @@ class GizwitsMiniSDK {
|
|
|
1536
1560
|
public destory = () => {
|
|
1537
1561
|
this.bleHandle.destory();
|
|
1538
1562
|
this.lanHandle.destory();
|
|
1539
|
-
this.socketHandle.destory();
|
|
1563
|
+
// this.socketHandle.destory();
|
|
1540
1564
|
this.keepScanTimer && clearInterval(this.keepScanTimer);
|
|
1541
1565
|
};
|
|
1542
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,
|
|
@@ -3,6 +3,7 @@ import sleep from "../sleep";
|
|
|
3
3
|
import errorCode from "../errorCode";
|
|
4
4
|
import { bindMac, checkDeviceRegister } from '../services/devices';
|
|
5
5
|
import GizLog from "../GizLog";
|
|
6
|
+
import timeZoneDic from './timeZoneName.json'
|
|
6
7
|
|
|
7
8
|
interface IRejectCallback {
|
|
8
9
|
(result: IResult<unknown>): void;
|
|
@@ -42,6 +43,49 @@ class ConfigBase {
|
|
|
42
43
|
this.cleanTimeout();
|
|
43
44
|
};
|
|
44
45
|
|
|
46
|
+
// 插入配网扩展信息
|
|
47
|
+
appendExtendData = (key: string) => {
|
|
48
|
+
const cmd = 0 // 小程序默认国内
|
|
49
|
+
const zone: number = new Date().getTimezoneOffset() / 60; //手机时区
|
|
50
|
+
let hour: number = Math.floor(zone);
|
|
51
|
+
let m: number = 0; //最终下发的时区精度
|
|
52
|
+
let h: string = ""; //最终下发的时区
|
|
53
|
+
let zoneAccuracy: number = zone - hour;
|
|
54
|
+
let timeZoneCode =0
|
|
55
|
+
const timeZoneName = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
56
|
+
|
|
57
|
+
if (hour >= 0 && hour <= 9) { //时区0~9
|
|
58
|
+
h = String.fromCharCode('0'.charCodeAt(0) + hour);
|
|
59
|
+
} else if (hour > 9) { //A~F
|
|
60
|
+
h = String.fromCharCode(hour - 10 + 'A'.charCodeAt(0));
|
|
61
|
+
} else { //a~o
|
|
62
|
+
h = String.fromCharCode(-hour - 1 + 'a'.charCodeAt(0));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (zoneAccuracy < 0) { //转正数
|
|
66
|
+
zoneAccuracy = -zoneAccuracy;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (zoneAccuracy >= 0 && zoneAccuracy < 0.25) { //精度
|
|
70
|
+
m = 0;
|
|
71
|
+
} else if (zoneAccuracy >= 0.25 && zoneAccuracy < 0.5) {
|
|
72
|
+
m = 1;
|
|
73
|
+
} else if (zoneAccuracy >= 0.5 && zoneAccuracy < 0.75) {
|
|
74
|
+
m = 2;
|
|
75
|
+
} else {
|
|
76
|
+
m = 3;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
Object.entries(timeZoneDic).forEach(([key, value]) => {
|
|
80
|
+
if (value === timeZoneName) {
|
|
81
|
+
timeZoneCode = parseInt(key);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
return key + `\0\x1b` + cmd + "\x1b" + h + m + "\x1b" + timeZoneCode;
|
|
87
|
+
}
|
|
88
|
+
|
|
45
89
|
hasTimeoutHandler = (cb?: IRejectCallback) => {
|
|
46
90
|
if (this.timeoutHandler) {
|
|
47
91
|
// 方法还在执行中
|
package/src/wifiConfig/ap.ts
CHANGED
|
@@ -143,6 +143,8 @@ class ApConfig extends ConfigBase {
|
|
|
143
143
|
}: ISetDeviceOnboardingDeployProps) => {
|
|
144
144
|
const ssid = this.ssid;
|
|
145
145
|
const password = this.password;
|
|
146
|
+
// 插入时区信息
|
|
147
|
+
const appendPassword = this.appendExtendData(password)
|
|
146
148
|
return new Promise<IResult<IDevice[]>>(async (res, rej) => {
|
|
147
149
|
this.destroy();
|
|
148
150
|
this.initDeviceOnboardingDeploy(res, rej);
|
|
@@ -151,7 +153,7 @@ class ApConfig extends ConfigBase {
|
|
|
151
153
|
try {
|
|
152
154
|
const result = await this.configDevice({
|
|
153
155
|
ssid,
|
|
154
|
-
password,
|
|
156
|
+
password:appendPassword,
|
|
155
157
|
softAPSSIDPrefix,
|
|
156
158
|
});
|
|
157
159
|
const newData: IDevice[] = (result.data || []).map(item => {
|