mini_program_gizwits_sdk 3.6.4 → 3.6.5
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 +3 -3
- package/package.json +1 -1
- package/yarn-error.log +6901 -0
- package/dist/src/GizLog.d.ts +0 -18
- package/dist/src/crc/calculators/crc16modbus.d.ts +0 -2
- package/dist/src/crc/calculators/crc32.d.ts +0 -2
- package/dist/src/crc/crc16modbus.d.ts +0 -7
- package/dist/src/crc/crc32.d.ts +0 -7
- package/dist/src/crc/create_buffer.d.ts +0 -3
- package/dist/src/crc/define_crc.d.ts +0 -7
- package/dist/src/crc/index.d.ts +0 -19
- package/dist/src/crc/types.d.ts +0 -11
- package/dist/src/errorCode.d.ts +0 -3
- package/dist/src/globalData.d.ts +0 -2
- package/dist/src/handler/EventListener.d.ts +0 -9
- package/dist/src/handler/ble.d.ts +0 -105
- package/dist/src/handler/lan.d.ts +0 -78
- package/dist/src/handler/socket.d.ts +0 -151
- package/dist/src/openApiRequest.d.ts +0 -3
- package/dist/src/productConfigFileManage.d.ts +0 -11
- package/dist/src/protocol/Bind.d.ts +0 -7
- package/dist/src/protocol/DeviceInfo.d.ts +0 -11
- package/dist/src/protocol/DiscoverUDP.d.ts +0 -17
- package/dist/src/protocol/GetDeviceStatus.d.ts +0 -5
- package/dist/src/protocol/Login.d.ts +0 -12
- package/dist/src/protocol/Ntp.d.ts +0 -5
- package/dist/src/protocol/OTA/AwaitNoti.d.ts +0 -7
- package/dist/src/protocol/OTA/CheckCanOTA.d.ts +0 -10
- package/dist/src/protocol/OTA/OTAPackPackage.d.ts +0 -8
- package/dist/src/protocol/OTA/OtaComplete.d.ts +0 -8
- package/dist/src/protocol/OTA/PreOTA.d.ts +0 -11
- package/dist/src/protocol/OTA/ResetPosition.d.ts +0 -6
- package/dist/src/protocol/OffLineData.d.ts +0 -23
- package/dist/src/protocol/ProtocolBase.d.ts +0 -11
- package/dist/src/protocol/Reset.d.ts +0 -8
- package/dist/src/protocol/SetReset.d.ts +0 -7
- package/dist/src/protocol/WifiConfig.d.ts +0 -6
- package/dist/src/protocol/dataPoint.d.ts +0 -34
- package/dist/src/protocol/tool.d.ts +0 -14
- package/dist/src/randomCode.d.ts +0 -3
- package/dist/src/request.d.ts +0 -1
- package/dist/src/sdk.d.ts +0 -136
- package/dist/src/sentry.d.ts +0 -2
- package/dist/src/services/devices.d.ts +0 -47
- package/dist/src/services/login.d.ts +0 -4
- package/dist/src/services/monitor.d.ts +0 -12
- package/dist/src/services/ota.d.ts +0 -7
- package/dist/src/services/tool.d.ts +0 -4
- package/dist/src/services/uploadP0.d.ts +0 -14
- package/dist/src/sleep.d.ts +0 -2
- package/dist/src/types/index.d.ts +0 -361
- package/dist/src/utils.d.ts +0 -46
- package/dist/src/wechatApi.d.ts +0 -19
- package/dist/src/wifiConfig/ConfigBase.d.ts +0 -27
- package/dist/src/wifiConfig/ap.d.ts +0 -11
- package/dist/src/wifiConfig/ble.d.ts +0 -41
- package/dist/src/wifiConfig/nfc/disposeData.d.ts +0 -2
- package/dist/src/wifiConfig/nfc/formatData.d.ts +0 -3
- package/dist/src/wifiConfig/nfc/formatSSID.d.ts +0 -6
- package/dist/src/wifiConfig/nfc/index.d.ts +0 -22
- package/dist/src/wifiConfig/nfc/isIncludedCH.d.ts +0 -1
- package/dist/src/wifiConfig/nfc/nfcAConnect.d.ts +0 -6
- package/dist/src/wifiConfig/nfc/nfcATransceive.d.ts +0 -5
- package/dist/src/wifiConfig/nfc/ssIDToASC.d.ts +0 -1
- package/dist/src/wifiConfig/nfc/stringToGbk.d.ts +0 -1
- package/dist/src/wifiConfig/nfc/transceive.wx.d.ts +0 -2
- package/dist/src/wifiConfig/nfc/types.d.ts +0 -15
- package/index.ts +0 -8
- package/src/GizLog.ts +0 -51
- package/src/crc/calculators/crc16modbus.ts +0 -36
- package/src/crc/calculators/crc32.ts +0 -47
- package/src/crc/crc16modbus.ts +0 -3
- package/src/crc/crc32.ts +0 -4
- package/src/crc/create_buffer.ts +0 -7
- package/src/crc/define_crc.ts +0 -9
- package/src/crc/index.ts +0 -10
- package/src/crc/package.json +0 -3
- package/src/crc/types.ts +0 -10
- package/src/errorCode.ts +0 -83
- package/src/globalData.ts +0 -9
- package/src/handler/EventListener.ts +0 -44
- package/src/handler/ble.ts +0 -1369
- package/src/handler/lan.ts +0 -389
- package/src/handler/socket.ts +0 -686
- package/src/openApiRequest.ts +0 -50
- package/src/productConfigFileManage.ts +0 -72
- package/src/protocol/Bind.ts +0 -22
- package/src/protocol/DeviceInfo.ts +0 -37
- package/src/protocol/DiscoverUDP.ts +0 -80
- package/src/protocol/GetDeviceStatus.ts +0 -61
- package/src/protocol/Login.ts +0 -43
- package/src/protocol/Ntp.ts +0 -13
- package/src/protocol/OTA/AwaitNoti.ts +0 -14
- package/src/protocol/OTA/CheckCanOTA.ts +0 -23
- package/src/protocol/OTA/OTAPackPackage.ts +0 -37
- package/src/protocol/OTA/OtaComplete.ts +0 -17
- package/src/protocol/OTA/PreOTA.ts +0 -48
- package/src/protocol/OTA/ResetPosition.ts +0 -14
- package/src/protocol/OffLineData.ts +0 -81
- package/src/protocol/ProtocolBase.ts +0 -54
- package/src/protocol/Reset.ts +0 -16
- package/src/protocol/SetReset.ts +0 -13
- package/src/protocol/WifiConfig.ts +0 -42
- package/src/protocol/dataPoint.ts +0 -687
- package/src/protocol/tool.ts +0 -140
- package/src/randomCode.ts +0 -25
- package/src/request.ts +0 -22
- package/src/sdk.ts +0 -1536
- package/src/sentry.ts +0 -55
- package/src/services/devices.ts +0 -313
- package/src/services/login.ts +0 -11
- package/src/services/monitor.ts +0 -117
- package/src/services/ota.ts +0 -17
- package/src/services/tool.ts +0 -10
- package/src/services/uploadP0.ts +0 -57
- package/src/sleep.ts +0 -2
- package/src/types/index.ts +0 -456
- package/src/utils.ts +0 -449
- package/src/wechatApi.ts +0 -211
- package/src/wifiConfig/ConfigBase.ts +0 -235
- package/src/wifiConfig/ap.ts +0 -185
- package/src/wifiConfig/ble.ts +0 -460
- package/src/wifiConfig/nfc/disposeData.ts +0 -63
- package/src/wifiConfig/nfc/formatData.ts +0 -46
- package/src/wifiConfig/nfc/formatSSID.ts +0 -59
- package/src/wifiConfig/nfc/index.ts +0 -134
- package/src/wifiConfig/nfc/isIncludedCH.ts +0 -8
- package/src/wifiConfig/nfc/nfcAConnect.ts +0 -30
- package/src/wifiConfig/nfc/nfcATransceive.ts +0 -29
- package/src/wifiConfig/nfc/ssIDToASC.ts +0 -12
- package/src/wifiConfig/nfc/stringToGbk.ts +0 -51
- package/src/wifiConfig/nfc/transceive.wx.ts +0 -124
- package/src/wifiConfig/nfc/types.ts +0 -18
- package/src/wifiConfig/timeZoneName.json +0 -1
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import { IRandomCodesResult, IRejectCallback, IResult, TimeoutHandle } from "../types";
|
|
2
|
-
import sleep from "../sleep";
|
|
3
|
-
import errorCode from "../errorCode";
|
|
4
|
-
import { bindMac, checkDeviceRegister } from '../services/devices';
|
|
5
|
-
import GizLog from "../GizLog";
|
|
6
|
-
import { ConfigEventData, IDevice } from "../types";
|
|
7
|
-
// import timeZoneDic from './timeZoneName.json'
|
|
8
|
-
class ConfigBase {
|
|
9
|
-
ssid = '';
|
|
10
|
-
bssid = '';
|
|
11
|
-
password = '';
|
|
12
|
-
specialProductKeys: string[] = [];
|
|
13
|
-
disableSearchDevice = false;
|
|
14
|
-
specialProductKeySecrets: string[] = []
|
|
15
|
-
timeoutHandler: TimeoutHandle = null;
|
|
16
|
-
eventCallBack: (event: ConfigEventData) => void;
|
|
17
|
-
|
|
18
|
-
private setDeviceOnboardingDeployRej?: (value: unknown) => void = () => {}; // 保存promise的rej,用于临时中断
|
|
19
|
-
// private setDeviceOnboardingDeployRes?: (value: unknown) => void = () => {}; // 保存promise的res,用于临时中断
|
|
20
|
-
|
|
21
|
-
constructor(ssid: string, bssid: string, password: string, specialProductKeys: string[], specialProductKeySecrets: string[]) {
|
|
22
|
-
this.ssid = ssid;
|
|
23
|
-
this.bssid = bssid;
|
|
24
|
-
this.password = password;
|
|
25
|
-
this.specialProductKeys = specialProductKeys;
|
|
26
|
-
this.specialProductKeySecrets = specialProductKeySecrets;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public cleanTimeout = () => {
|
|
30
|
-
this.disableSearchDevice = true;
|
|
31
|
-
this.timeoutHandler && clearTimeout(this.timeoutHandler);
|
|
32
|
-
this.timeoutHandler = null;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
stopDeviceOnboardingDeploy = (): void => {
|
|
36
|
-
if (this.setDeviceOnboardingDeployRej) {
|
|
37
|
-
this.setDeviceOnboardingDeployRej({
|
|
38
|
-
success: false,
|
|
39
|
-
err: errorCode.GIZ_SDK_ONBOARDING_STOPPED,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
this.cleanTimeout();
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// 插入配网扩展信息
|
|
46
|
-
appendExtendData = (key: string) => {
|
|
47
|
-
const cmd = 0 // 小程序默认国内
|
|
48
|
-
// 以东八区为例,模组用的是+8,需要反过来
|
|
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
|
-
// 写死上海
|
|
55
|
-
let timeZoneCode =309
|
|
56
|
-
// const timeZoneName = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
57
|
-
|
|
58
|
-
if (hour >= 0 && hour <= 9) { //时区0~9
|
|
59
|
-
h = String.fromCharCode('0'.charCodeAt(0) + hour);
|
|
60
|
-
} else if (hour > 9) { //A~F
|
|
61
|
-
h = String.fromCharCode(hour - 10 + 'A'.charCodeAt(0));
|
|
62
|
-
} else { //a~o
|
|
63
|
-
h = String.fromCharCode(-hour - 1 + 'a'.charCodeAt(0));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (zoneAccuracy < 0) { //转正数
|
|
67
|
-
zoneAccuracy = -zoneAccuracy;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (zoneAccuracy >= 0 && zoneAccuracy < 0.25) { //精度
|
|
71
|
-
m = 0;
|
|
72
|
-
} else if (zoneAccuracy >= 0.25 && zoneAccuracy < 0.5) {
|
|
73
|
-
m = 1;
|
|
74
|
-
} else if (zoneAccuracy >= 0.5 && zoneAccuracy < 0.75) {
|
|
75
|
-
m = 2;
|
|
76
|
-
} else {
|
|
77
|
-
m = 3;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Object.entries(timeZoneDic).forEach(([key, value]) => {
|
|
81
|
-
// if (value === timeZoneName) {
|
|
82
|
-
// timeZoneCode = parseInt(key);
|
|
83
|
-
// return;
|
|
84
|
-
// }
|
|
85
|
-
// });
|
|
86
|
-
|
|
87
|
-
return key + `\0\x1b` + cmd + "\x1b" + h + m + "\x1b" + timeZoneCode;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
hasTimeoutHandler = (cb?: IRejectCallback) => {
|
|
91
|
-
if (this.timeoutHandler) {
|
|
92
|
-
// 方法还在执行中
|
|
93
|
-
cb &&
|
|
94
|
-
cb({
|
|
95
|
-
success: false,
|
|
96
|
-
err: errorCode.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING,
|
|
97
|
-
});
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
return false;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
handleTimeout = () => {
|
|
104
|
-
if (this.setDeviceOnboardingDeployRej) {
|
|
105
|
-
this.setDeviceOnboardingDeployRej({
|
|
106
|
-
success: false,
|
|
107
|
-
err: {
|
|
108
|
-
errorCode: errorCode.CONFIG_TIME_OUT,
|
|
109
|
-
errorMessage: 'time out',
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
this.timeoutHandler = null;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* 大循环确认
|
|
118
|
-
*/
|
|
119
|
-
protected searchDevice = ({ ssid, password }: { ssid: string; password: string }) => {
|
|
120
|
-
return new Promise<IResult<IRandomCodesResult[]>>((res, rej) => {
|
|
121
|
-
GizLog.debug('GIZ_SDK: 开始大循环搜索设备')
|
|
122
|
-
const query = async () => {
|
|
123
|
-
|
|
124
|
-
if (!this.hasTimeoutHandler()) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
try {
|
|
129
|
-
const data = await checkDeviceRegister({
|
|
130
|
-
SSID: ssid,
|
|
131
|
-
password,
|
|
132
|
-
productKeys: this.specialProductKeys,
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
// GizLog.debug('GIZ_SDK: try get device random codes', data);
|
|
136
|
-
if (data.err?.errorCode === errorCode.GIZ_OPENAPI_TOKEN_INVALID.errorCode) {
|
|
137
|
-
// token 失效
|
|
138
|
-
rej({
|
|
139
|
-
success: false,
|
|
140
|
-
err: errorCode.GIZ_OPENAPI_TOKEN_INVALID,
|
|
141
|
-
});
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (data.err || (data.data as IRandomCodesResult[]).length === 0) {
|
|
146
|
-
// 重新请求
|
|
147
|
-
// GizLog.debug('GIZ_SDK: 大循环没有发现设备');
|
|
148
|
-
await sleep(250);
|
|
149
|
-
!this.disableSearchDevice && query();
|
|
150
|
-
} else {
|
|
151
|
-
// 搜索到设备
|
|
152
|
-
this.eventCallBack?.({
|
|
153
|
-
event: "GIZ_CONFIG_SUCCESS",
|
|
154
|
-
});
|
|
155
|
-
GizLog.debug('GIZ_SDK: 大循环搜索到设备', data);
|
|
156
|
-
res({
|
|
157
|
-
success: true,
|
|
158
|
-
data: data.data,
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
} catch (error) {
|
|
162
|
-
// 重新请求
|
|
163
|
-
await sleep(3000);
|
|
164
|
-
!this.disableSearchDevice && query();
|
|
165
|
-
// GizLog.debug('GIZ_SDK: random codes error', error);
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
query();
|
|
169
|
-
});
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
initDeviceOnboardingDeploy = (_res, rej) => {
|
|
173
|
-
// this.setDeviceOnboardingDeployRes = res;
|
|
174
|
-
|
|
175
|
-
// 都用res 返回,不然外面需要trh
|
|
176
|
-
this.setDeviceOnboardingDeployRej = _res;
|
|
177
|
-
this.disableSearchDevice = false;
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
protected startTimeoutTimer = (timeout: number) => {
|
|
181
|
-
/**
|
|
182
|
-
* 设置超时时间
|
|
183
|
-
*/
|
|
184
|
-
this.timeoutHandler = setTimeout(this.handleTimeout, timeout * 1000);
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* 绑定多个设备
|
|
189
|
-
*/
|
|
190
|
-
protected bindDevices = (devices: IDevice[]) => {
|
|
191
|
-
GizLog.log('GIZ_SDK: start bind device');
|
|
192
|
-
return new Promise<IResult<IDevice[]>>(async (res, rej) => {
|
|
193
|
-
const promises = devices.map((item) => {
|
|
194
|
-
const index = this.specialProductKeys.findIndex(
|
|
195
|
-
(pk) => item.productKey === pk
|
|
196
|
-
);
|
|
197
|
-
if (index === -1) return;
|
|
198
|
-
const ps = this.specialProductKeySecrets[index];
|
|
199
|
-
|
|
200
|
-
return bindMac({
|
|
201
|
-
mac: item.mac,
|
|
202
|
-
productKey: item.productKey,
|
|
203
|
-
productSecret: ps,
|
|
204
|
-
})
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
try {
|
|
208
|
-
const data = await Promise.all(promises);
|
|
209
|
-
const successDevices = devices.filter((_, index) => {
|
|
210
|
-
const item = data[index];
|
|
211
|
-
return item && item.success;
|
|
212
|
-
});
|
|
213
|
-
if (successDevices.length > 0) {
|
|
214
|
-
GizLog.log('GIZ_SDK: bind device success', successDevices);
|
|
215
|
-
// 绑定成功,重新初始化socket
|
|
216
|
-
res({
|
|
217
|
-
success: true,
|
|
218
|
-
data: successDevices,
|
|
219
|
-
});
|
|
220
|
-
} else {
|
|
221
|
-
GizLog.log('GIZ_SDK: bind device error', data);
|
|
222
|
-
rej({
|
|
223
|
-
success: false,
|
|
224
|
-
data: devices,
|
|
225
|
-
err: errorCode.GIZ_SDK_BIND_DEVICE_FAILED,
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
} catch (error) {
|
|
229
|
-
rej(error);
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
export default ConfigBase;
|
package/src/wifiConfig/ap.ts
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import errorCode from "../errorCode";
|
|
2
|
-
import GizLog from "../GizLog";
|
|
3
|
-
import WifiConfig from "../protocol/WifiConfig";
|
|
4
|
-
import { IDevice, IRandomCodesResult, IResult, IntervalHandle, configDeviceParams, ISetDeviceOnboardingDeployProps } from "../types";
|
|
5
|
-
import ConfigBase from "./ConfigBase";
|
|
6
|
-
|
|
7
|
-
class ApConfig extends ConfigBase {
|
|
8
|
-
|
|
9
|
-
disableSendUDP = false;
|
|
10
|
-
private sendMessageInterval: IntervalHandle = null;
|
|
11
|
-
private UDPSocketHandler: WechatMiniprogram.UDPSocket | null = null;
|
|
12
|
-
|
|
13
|
-
destroy = () => {
|
|
14
|
-
this.cleanTimeout();
|
|
15
|
-
this.sendMessageInterval && clearInterval(this.sendMessageInterval);
|
|
16
|
-
this.sendMessageInterval = null;
|
|
17
|
-
|
|
18
|
-
if (this.UDPSocketHandler) {
|
|
19
|
-
this.UDPSocketHandler.offError();
|
|
20
|
-
this.UDPSocketHandler.offMessage();
|
|
21
|
-
this.UDPSocketHandler.close();
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* 负责发指令
|
|
27
|
-
*/
|
|
28
|
-
configDevice = ({ ssid, password, softAPSSIDPrefix }: configDeviceParams) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return new Promise<IResult<IRandomCodesResult[]>>((res, rej) => {
|
|
32
|
-
GizLog.debug('GIZ_SDK: start config device');
|
|
33
|
-
let searchingDevice = false;
|
|
34
|
-
let UDP_ERROR_NUM = 0;
|
|
35
|
-
const appendPassword = this.appendExtendData(password)
|
|
36
|
-
const uint8Array = WifiConfig.pack(ssid,appendPassword);
|
|
37
|
-
/**
|
|
38
|
-
* 连接socket 发送
|
|
39
|
-
*/
|
|
40
|
-
this.UDPSocketHandler = wx.createUDPSocket();
|
|
41
|
-
this.UDPSocketHandler.bind();
|
|
42
|
-
|
|
43
|
-
this.disableSendUDP = false;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* TODO
|
|
47
|
-
* 收到设备回的包后终止
|
|
48
|
-
* 或者超时
|
|
49
|
-
* 或者成功
|
|
50
|
-
*/
|
|
51
|
-
const sendMessage = () => {
|
|
52
|
-
try {
|
|
53
|
-
!this.disableSendUDP &&
|
|
54
|
-
this.UDPSocketHandler!.send({
|
|
55
|
-
address: '10.10.100.254',
|
|
56
|
-
port: 12414,
|
|
57
|
-
message: uint8Array,
|
|
58
|
-
offset: 0,
|
|
59
|
-
length: uint8Array.byteLength,
|
|
60
|
-
});
|
|
61
|
-
} catch (error) {
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
// 执行
|
|
66
|
-
this.sendMessageInterval = setInterval(() => {
|
|
67
|
-
sendMessage();
|
|
68
|
-
}, 2000);
|
|
69
|
-
|
|
70
|
-
this.UDPSocketHandler.onError((data: any) => {
|
|
71
|
-
UDP_ERROR_NUM += 1;
|
|
72
|
-
// UDPSocketHandler.close();
|
|
73
|
-
// 重试三次不行还是失败
|
|
74
|
-
if (UDP_ERROR_NUM > 2) {
|
|
75
|
-
this.destroy();
|
|
76
|
-
rej({
|
|
77
|
-
success: false,
|
|
78
|
-
err: {
|
|
79
|
-
errorCode: errorCode.WECHAT_ERROR.errorCode,
|
|
80
|
-
errorMessage: data.errMsg,
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
// 清理一些监听,调用搜索设备
|
|
87
|
-
const searchDeviceHandle = async () => {
|
|
88
|
-
if (searchingDevice) return;
|
|
89
|
-
this.UDPSocketHandler!.offMessage();
|
|
90
|
-
this.UDPSocketHandler!.offError();
|
|
91
|
-
this.sendMessageInterval && clearInterval(this.sendMessageInterval);
|
|
92
|
-
this.disableSendUDP = true;
|
|
93
|
-
// 标记可以停止监听
|
|
94
|
-
searchingDevice = true;
|
|
95
|
-
// 关闭socket
|
|
96
|
-
try {
|
|
97
|
-
const devicesReturn = await this.searchDevice({ ssid, password });
|
|
98
|
-
res(devicesReturn);
|
|
99
|
-
} catch (error) {
|
|
100
|
-
rej(error);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
this.UDPSocketHandler.onMessage((_data) => {
|
|
105
|
-
// 收到回调 可以停止发包
|
|
106
|
-
searchDeviceHandle();
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
// 没有收到udp回复的时候不进入配网
|
|
110
|
-
wx.onNetworkStatusChange(async () => {
|
|
111
|
-
// 发生网络切换的时候也停止发包,进入大循环配网
|
|
112
|
-
// 搜索中的时候不要重复搜索
|
|
113
|
-
!searchingDevice &&
|
|
114
|
-
wx.getConnectedWifi({
|
|
115
|
-
success: async (data) => {
|
|
116
|
-
/**
|
|
117
|
-
* 检查当前网络还是不是热点网络
|
|
118
|
-
*/
|
|
119
|
-
data.wifi.SSID.indexOf(softAPSSIDPrefix) === -1 &&
|
|
120
|
-
searchDeviceHandle();
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
|
-
/**
|
|
127
|
-
* 配网接口
|
|
128
|
-
* setDeviceOnboardingDeploy方法不可重复调用
|
|
129
|
-
*/
|
|
130
|
-
setDeviceOnboardingDeploy = ({
|
|
131
|
-
timeout,
|
|
132
|
-
isBind = true,
|
|
133
|
-
softAPSSIDPrefix,
|
|
134
|
-
}: ISetDeviceOnboardingDeployProps) => {
|
|
135
|
-
const ssid = this.ssid;
|
|
136
|
-
const password = this.password;
|
|
137
|
-
// 插入时区信息
|
|
138
|
-
return new Promise<IResult<IDevice[]>>(async (res, rej) => {
|
|
139
|
-
this.destroy();
|
|
140
|
-
this.initDeviceOnboardingDeploy(res, rej);
|
|
141
|
-
this.startTimeoutTimer(timeout);
|
|
142
|
-
|
|
143
|
-
try {
|
|
144
|
-
const result = await this.configDevice({
|
|
145
|
-
ssid,
|
|
146
|
-
password,
|
|
147
|
-
softAPSSIDPrefix,
|
|
148
|
-
});
|
|
149
|
-
const newData: IDevice[] = (result.data || []).map(item => {
|
|
150
|
-
return {
|
|
151
|
-
mac: item.mac,
|
|
152
|
-
productKey: item.product_key,
|
|
153
|
-
did: item.did,
|
|
154
|
-
name: '',
|
|
155
|
-
isBind: false,
|
|
156
|
-
localName: '',
|
|
157
|
-
connectType: 'NONE',
|
|
158
|
-
isBleOnline: false,
|
|
159
|
-
isLanOnline: false,
|
|
160
|
-
isOnline: false,
|
|
161
|
-
}
|
|
162
|
-
})
|
|
163
|
-
if (isBind) {
|
|
164
|
-
try {
|
|
165
|
-
res(await this.bindDevices(newData));
|
|
166
|
-
} catch (error) {
|
|
167
|
-
rej(error);
|
|
168
|
-
}
|
|
169
|
-
} else {
|
|
170
|
-
// 不需要绑定 直接返回成功
|
|
171
|
-
res({
|
|
172
|
-
success: true,
|
|
173
|
-
data: newData,
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
} catch (error) {
|
|
177
|
-
rej(error);
|
|
178
|
-
} finally {
|
|
179
|
-
this.destroy();
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export default ApConfig;
|