|
@@ -2,6 +2,8 @@
|
|
|
const { BtHelper } = require("../../devices/bt_helper");
|
|
|
import EventManager from '../../utils/event_bus'
|
|
|
import { EnumCmdEvent, CmdEvent } from '../../devices/cmd_key_event';
|
|
|
+import store from '../../utils/store';
|
|
|
+import { BtCmd } from '../../devices/bluetooth/bt_cmd';
|
|
|
Page({
|
|
|
data: {
|
|
|
wifiName: '',
|
|
@@ -11,7 +13,17 @@ Page({
|
|
|
|
|
|
getConnectedWifi: function () {
|
|
|
const that = this;
|
|
|
-
|
|
|
+ let wifiDic = store.getStore("wifiInfo")
|
|
|
+ let wifiName = wifiDic.wifiName
|
|
|
+ let pwd = wifiDic.wifiPassword
|
|
|
+ if (wifiName && pwd) {
|
|
|
+ console.log("获取Wi-Fi信息", wifiName, pwd);
|
|
|
+ that.setData({
|
|
|
+ wifiName: wifiName,
|
|
|
+ wifiPassword: pwd
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
wx.startWifi({
|
|
|
success(res) {
|
|
|
console.log(res.errMsg)
|
|
@@ -50,19 +62,6 @@ Page({
|
|
|
wifiPassword: e.detail.value
|
|
|
});
|
|
|
},
|
|
|
- // string转换为List<int>
|
|
|
- string2ListInt(text) {
|
|
|
- let code = Array.from(text).map(char => char.charCodeAt(0));
|
|
|
- console.log("string转换为List<int>", text, code)
|
|
|
- return code
|
|
|
- },
|
|
|
- _int2Hex(num) {
|
|
|
- let value = num ?? 0;
|
|
|
- let hexStr = value.toString(16).toUpperCase();
|
|
|
- hexStr = hexStr.padStart(2, '0');
|
|
|
- let hexNum = parseInt(hexStr, 16);
|
|
|
- return hexNum;
|
|
|
- },
|
|
|
sendWiFiInfo(wifiName, pwd) {
|
|
|
// [0x22, (wifiList.length + pwdList.length + 6), 0x33, (wifiList.length), (wifiList), 0x44, (pwdList)];
|
|
|
|
|
@@ -77,19 +76,20 @@ Page({
|
|
|
let result = [];
|
|
|
|
|
|
// 字母*6 +
|
|
|
- let wifiList = this.string2ListInt(wifiName);
|
|
|
+ let wifiList = BtCmd.stringToUint8Array(wifiName);
|
|
|
|
|
|
// 数字*3 +
|
|
|
- let pwdList = this.string2ListInt(pwd);
|
|
|
+ let pwdList = BtCmd.stringToUint8Array(pwd);
|
|
|
console.log("wifiList", wifiList, "pwdList", pwdList)
|
|
|
|
|
|
// 16进制
|
|
|
result.push(0x22);
|
|
|
- result.push(this._int2Hex(wifiList.length + pwdList.length + 6));
|
|
|
+
|
|
|
+ result.push(BtCmd.intToHex(wifiList.length + pwdList.length + 6));
|
|
|
|
|
|
// 账号
|
|
|
result.push(0x33);
|
|
|
- result.push(this._int2Hex(wifiList.length));
|
|
|
+ result.push(BtCmd.intToHex(wifiList.length));
|
|
|
|
|
|
let p = result[3] + 4;
|
|
|
let j = 0;
|
|
@@ -99,7 +99,7 @@ Page({
|
|
|
|
|
|
// 密码
|
|
|
result.splice(p, 0, 0x44);
|
|
|
- result.splice(++p, 0, this._int2Hex(pwdList.length));
|
|
|
+ result.splice(++p, 0, BtCmd.intToHex(pwdList.length));
|
|
|
p++;
|
|
|
j = 0;
|
|
|
for (let i = p; i < p + pwdList.length; i++) {
|
|
@@ -136,6 +136,12 @@ Page({
|
|
|
title: toast,
|
|
|
icon: 'none'
|
|
|
})
|
|
|
+ if (name === EnumCmdEvent.otaWifi && value === 1) {
|
|
|
+ store.setStore("wifiInfo", {
|
|
|
+ wifiName: _this.data.wifiName,
|
|
|
+ wifiPassword: _this.data.wifiPassword
|
|
|
+ })
|
|
|
+ }
|
|
|
}, _this)
|
|
|
},
|
|
|
onLoad: function (options) {
|