ble.connect(
{
peripheralUUID: uuid
},
function(rets, err) {
console.log("rets:" + JSON.stringify(rets));
if (rets.status) {
console.log("连接成功");
ble.discoverService(
{
peripheralUUID: uuid
},
function(ret, err) {
if (ret.status) {
var serviceUUID =
ret.services[2];
console.log(
"serviceUUID:" + serviceUUID
);
ble.discoverCharacteristics(
{
serviceUUID: serviceUUID,
peripheralUUID: uuid
},
function(ret) {
console.log(
JSON.stringify(ret)
);
api.hideProgress();
if (ret.status) {
api.openWin({
name: "info",
url:
"../**.**stml",
pageParam: {
uuid: uuid,
characteristics:
ret.characteristics
}
});
} else {
api.toast({
msg:
"蓝牙连接失败"
});
startBleScan();
}
}
);
} else {
api.toast({
msg: "蓝牙连接失败"
});
//获取不到serviceUUID
//重新开启蓝牙扫描
startBleScan();
}
}
);
} else {
console.log(JSON.stringify(err));
api.toast({
msg: "蓝牙连接失败"
});
startBleScan();
}
}
);
1.第一次连接成功不知为何有重新连接第二次
log:
C6:05:04:07:B2:62 at bloodPress_win_v1.html : 286 {"status":true,"peripheralUUID":"C6:05:04:07:B2:62"} at bloodPress_win_v1.html : 290 第一次 {} at bloodPress_win_v1.html : 291 {"status":false} at bloodPress_win_v1.html : 290 第二次 {"code":19,"peripheralUUID":"C6:05:04:07:B2:62","detailErrorCode":"newState:0"} at bloodPress_win_v1.html : 291 |