|
var ble = api.require('ble');
ble.isConnected({
peripheralUUID: uuid
}, function(ret) {
if (ret) {
if(ret.status == false){
console.log('未连接'+uuid);
ble.clean();
ble.connect({
peripheralUUID: uuid
}, function(ret, err) {
if (ret) {
console.log(JSON.stringify(ret));
if(ret.status == true){
$('.deviceconnect').show();
$api.setStorage('connectname',name);
$api.setStorage('connectuuid',uuid);
//获取服务UUID
ble.discoverService({
peripheralUUID: uuid
}, function(ret) {
if (ret) {
console.warn(JSON.stringify(ret));
if(ret.status == true){
var services = ret.services;
for(var i = 0;i < services.length;i++){
var service = services;
if (service.indexOf('0000ffe0') != -1) {
console.warn(service);
$api.setStorage('connectserviceuuid',service);
}else{
console.log('不包含该设备');
}
}
}
}
});
}else{
api.toast({
msg: '连接失败',
duration: 2000,
location: 'bottom'
});
}
} else {
console.log(JSON.stringify(err));
}
});
$('.nodevice').show();
}else{
$('.deviceconnect').show();
}
}
});
connect方法没有返回任何结果... |
|