|
@@ -63,7 +63,6 @@ class BleUtil {
|
|
|
// await that.disconnect(device);
|
|
|
|
|
|
var res = await that.manager.startConnect(device);
|
|
|
- console.log("gadsfasdfadfaf===aaaa==" + JSON.stringify(res));
|
|
|
if (!res) {
|
|
|
onChanged(false, device);
|
|
|
return;
|
|
@@ -81,30 +80,31 @@ class BleUtil {
|
|
|
async function (notifyServiceId, notifyCharaterId) {
|
|
|
var isTrue = that.manager.monitorCharacteristicValueChange(device, notifyServiceId, notifyCharaterId);
|
|
|
if (!isTrue) {
|
|
|
- console.log("gadsfasdfadfaf===ccc==");
|
|
|
onChanged(false);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ console.log("gadsfasdfadfaf===ddd==" + JSON.stringify(isTrue));
|
|
|
///解决连接之后会有一段时间显示离线,先添加进去就不会了
|
|
|
- var has = false;
|
|
|
- var compareList = that.manager.getCompareList();
|
|
|
- for (var j = 0; j < compareList.length; j++) {
|
|
|
- if (compareList[j].deviceId == device.deviceId) {
|
|
|
- has = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!has) {
|
|
|
- compareList.unshift(device);
|
|
|
- that.manager.setCompareList(compareList);
|
|
|
- }
|
|
|
+ // var has = false;
|
|
|
+ // var compareList = that.manager.getCompareList();
|
|
|
+ // for (var j = 0; j < compareList.length; j++) {
|
|
|
+ // if (compareList[j].deviceId == device.deviceId) {
|
|
|
+ // has = true;
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // if (!has) {
|
|
|
+ // compareList.unshift(device);
|
|
|
+ // that.manager.setCompareList(compareList);
|
|
|
+ // }
|
|
|
onChanged(true);
|
|
|
|
|
|
const hex_util = require('./../../utils/hex_util');
|
|
|
const bt_parse = require('./../../devices/bluetooth/bt_parse');
|
|
|
that.manager.onBLECharacteristicValueChange(function (value) {
|
|
|
var receiveText = hex_util.buf2string(value);
|
|
|
+ console.log("gadsfasdfadfaf===eeee==" + receiveText);
|
|
|
console.log('接收到数据文字:' + receiveText);
|
|
|
|
|
|
var buffer = new DataView(value);
|
|
@@ -116,16 +116,17 @@ class BleUtil {
|
|
|
});
|
|
|
},
|
|
|
function () {
|
|
|
- console.log("gadsfasdfadfaf===ddd==");
|
|
|
onChanged(false);
|
|
|
return;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
///发送数据
|
|
|
- async sendData(device, text) {
|
|
|
+ async sendData(device, wifiName, pwd) {
|
|
|
var that = this;
|
|
|
- console.log("gadsfasdfadfaf===222==" + text);
|
|
|
+ console.log("gadsfasdfadfaf===222==" + wifiName + "===" + pwd);
|
|
|
+ var text = that.sendWiFiInfo(wifiName, pwd);
|
|
|
+ console.log("gadsfasdfadfaf===444==" + text);
|
|
|
var isTrue = await that.manager.sendData(device, text);
|
|
|
console.log("gadsfasdfadfaf===333==" + isTrue);
|
|
|
///发送数据成功
|
|
@@ -134,6 +135,43 @@ class BleUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ sendWiFiInfo(wifiName, pwd) {
|
|
|
+ const hex_util = require('../hex_util');
|
|
|
+ let result = [];
|
|
|
+
|
|
|
+ // 字母*6 +
|
|
|
+ let wifiList = hex_util.string2ListInt(wifiName);
|
|
|
+
|
|
|
+ // 数字*3 +
|
|
|
+ let pwdList = hex_util.string2ListInt(pwd);
|
|
|
+
|
|
|
+ // 16进制
|
|
|
+ result.push(0x22);
|
|
|
+ result.push(parseInt(hex_util.int2Hex(wifiList.length + pwdList.length + 6), 16));
|
|
|
+
|
|
|
+ // 账号
|
|
|
+ result.push(0x33);
|
|
|
+ result.push(parseInt(hex_util.int2Hex(wifiList.length), 16));
|
|
|
+
|
|
|
+ let p = result[3] + 4;
|
|
|
+ let j = 0;
|
|
|
+ for (let i = 4; i < p; i++) {
|
|
|
+ result.splice(i, 0, wifiList[j++]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 密码
|
|
|
+ result.splice(p, 0, 0x44);
|
|
|
+ result.splice(++p, 0, parseInt(hex_util.int2Hex(pwdList.length), 16));
|
|
|
+ p++;
|
|
|
+ j = 0;
|
|
|
+ for (let i = p; i < p + pwdList.length; i++) {
|
|
|
+ result.splice(i, 0, pwdList[j++]);
|
|
|
+ }
|
|
|
+ ///[34, 22, 51, 5, 109, 117, 122, 101, 110, 68, 11, 109, 117, 122, 101, 110, 111, 102, 102, 105, 99, 101]
|
|
|
+ console.log("发送wifi账号密码:", result.toString());
|
|
|
+ return result.toString();
|
|
|
+ }
|
|
|
+
|
|
|
///断开设备连接
|
|
|
async disconnect(device) {
|
|
|
var that = this;
|