帖子
帖子
用户
博客
课程
显示全部楼层
45
帖子
0
勋章
213
Y币

[BUG] BLE模块IOS的错误!

[复制链接]
发表于 2016-12-13 14:02:47
在安卓下工作正常,在IOS下,用ble.discoverCharacteristics执行的结果是错误的,ble.discoverCharacteristics返回的propertiesbroadcast,但是该蓝牙模块在lightblue下监测properties是:write without responsenotify,并且能写数据,但是BLE模块无法写入数据。这个是iOS ble模块的一个BUG,请大侠改一下。
45
帖子
0
勋章
213
Y币
很着急啊,请赶快处理一下吧!
代码贴下,

截图看看lightblue下检测的,跟ble模块获取的
45
帖子
0
勋章
213
Y币
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>slidPane</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <style>
        body{
        background-color:#F2F2F2;
        width: 100%;
        height: 100%;
        }
        header {
            background-color: #f2f2f2;
            border-bottom: 1px solid #f2f2f2;
        }
        .header {
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;            
        }
        .header a{
            display: block;
            padding: 20px;
        }
        .title {
            line-height:40px;
            -webkit-box-flex: 1;
            -webkit-flex: 1;
            flex: 1;
            text-align: center;
        }
        .header .menu {
            background-size: 30px;
            background-repeat: no-repeat;
            background-position: center;
            background-image: url("../image/menu.png");
        }
        .btn{
                        width:80px;
                        height:30px;
                        background-color:#4285F4;
                        margin:10px;
                        font-size:13px;
                        border-radius:9px;
                }
        .input{
                        width:80%;
                        height:30px;
                        font-size:13px;
                }

    </style>
</head>
<body>
<header>
    <div class="header">
        <a class="menu" tapmode="" onclick="sliding()"></a>
        <div class="title" >灵犀蓝魔测试工具</div>
        <a></a>
    </div>
</header>
<div>
   <button type="button" class="btn">
                            <a href="#" onClick="startscan();">搜索</a>
  </button>
   <button type="button" class="btn">
                            <a href="#" onClick="serch();">马达测试</a>
  </button>
   <button type="button" class="btn">
                            <a href="#" onClick="serch();">马达老化</a>
  </button>
   <input type="text" class="input">
                            <a href="#" onClick="serch();">执行</a>
  </input>
   <input type="text" class="input" value="返回结果">
  </input>
  
</div>
<script type="text/javascript" src="../script/api.js"></script>
<script>
            var ble;
                var suuid="0000ffe0-0000-1000-8000-00805f9b34fb";
                var puuid="";
                var cuuid="0000ffe1-0000-1000-8000-00805f9b34fb";
                var cuuid8="0000ffe8-0000-1000-8000-00805f9b34fb";
                var cuuid7="0000ffe7-0000-1000-8000-00805f9b34fb";
                var cuuid5="0000ffe5-0000-1000-8000-00805f9b34fb";
                var cuuid8="0000ffe8-0000-1000-8000-00805f9b34fb";
        var listdata;
        var UIListView;
        var mySettingInfo
    function sliding() {
        api.openSlidPane({type: 'left'});
    }
    apiready = function () {
      UIListView=api.require('UIListView');
      ble = api.require('ble');   
      mySettingInfo = api.require('mySettingInfo');
        };
                        function Datasion(uid,imgPath,title){
            this.uid=uid;
            this.imgPath=imgPath;
            this.title=title;
            this.icon="";
            }

function serch(){}
function startscan(){
        ble.stopScan();
        ble.initManager(function(ret){
        if(ret.state=="poweredOff"){alert("请打开蓝牙");bleset();}
          if(ret.state == "poweredOn"){
                          ble.scan(function(ret,err){
                            if(ret.status) {
                            api.toast({
                        msg:"扫描启动!"
                });
                                          setTimeout("getmac()",5000);
                            };
                            if(err) toast("扫描启动失败!");
    });
          }
        })
       
}
function getmac(){
        var data = new Datasion("","","","","","");
        data=[];

        ble.getPeripheral(
            function(ret,err) {
            if(ret){
             var length=ret.peripherals.length;
             var data1=ret.peripherals;
             alert(JSON.stringify(data1));
             data1.sort(compare("rssi"));
             //alert(JSON.stringify(data1));
             if (length>0){
             var uuid= new Array;
             var name= new Array;
             var rssi= new Array;
             data=[];
             for(i=0;i<length;i++){
                var txt=data1[i].name+"["+data1[i].uuid+"]"+data1[i].rssi;
                                data.push(new Datasion(data1[i].uuid,"widget://image/lock_l.png",txt));
                    }
                    listdata=data;
                    UIListView.close();
                    fnopen();

             }
         
     }
           
    });
   
}
function fnopen(){
        UIListView.open({
    rect: {
            y: api.winHeight/3.8,
            h: api.winHeight*0.67
                            
    },
    data: listdata,
    rightBtns: [{
        bgColor: '#388e8e',
        activeBgColor: '',
        width: 70,
        title: '开始连接',
        titleSize: 12,
        titleColor: '#fff',
        icon: '',
        iconWidth: 20
    },{
        bgColor: '#388e8e',
        activeBgColor: '',
        width: 70,
        title: '断开连接',
        titleSize: 12,
        titleColor: '#fff',
        icon: '',
        iconWidth: 20
    }],
    leftBtns: [{
        bgColor: '#388e8e',
        activeBgColor: '',
        width: 70,
        title: '服务',
        titleSize: 12,
        titleColor: '#fff',
        icon: '',
        iconWidth: 20
    },{
        bgColor: '#388e8e',
        activeBgColor: '',
        width: 70,
        title: '特征',
        titleSize: 12,
        titleColor: '#fff',
        icon: '',
        iconWidth: 20
    }],
    styles: {
        borderColor: '#E0E0E0',
        item: {
            bgColor: '#FFFFFF',
            activeBgColor: '#AFEEEE',
            height: 55.0,
            imgWidth: 40,
            imgHeight: 40,
            imgCorner: 4,
            placeholderImg: '',
            titleSize: 16.0,
            titleColor: '#000',
            subTitleSize: 12.0,
            subTitleColor: '#000',
            remarkColor: '#000',
            remarkSize: 16,
            remarkIconWidth: 30
        }
    },
    fixedOn: api.frameName
}, function(ret, err) {
    if (ret) {
       if (ret.eventType=="clickContent" ){
          var index=ret.index;
          puuid=listdata[index].uid;
          alert(JSON.stringify(listdata[index]));     
                }
       if (ret.eventType=="clickRightBtn" ){
          var index=ret.index;
          var rindex=ret.btnIndex;
          puuid=listdata[index].uid;
          switch (rindex)
          {
          case 0:
           ble.connect({
                   peripheralUUID: puuid
           },function(ret,err){
                     if(ret.status){
                        api.toast({
                            msg:"连接成功"
                    });
                         discserverint(puuid);           
                     }
                     else
                     {
                     alert(puuid+"连接错误代码:"+err.code);
                     }
           });
          break;
          case 1:
          ble.disconnect({
                  peripheralUUID: puuid
          },function(ret,err){
                  alert(JSON.stringify(ret));
          });
          break;
          }     
                }

    } else {
        alert(JSON.stringify(err));
    }
});
        }

function discserverint(uuid){
    ble.discoverService({
            peripheralUUID: uuid
    },function(ret,err){
            if(ret){
         // stopscan();
         readint(uuid)
          api.toast({
                  msg:"搜索到蓝牙服务。。"+JSON.stringify(ret)
          });
         
        
            }
    });
}
function bleset(){mySettingInfo.settingInt({ 'index': 1 }, function(ret, err) {alert(JSON.stringify(ret));});}
function readint(uuid){
ble.writeValueForCharacteristic({
    peripheralUUID: uuid,
    serviceUUID: suuid,
    characteristicUUID: cuuid,
    value: 'a1b4'
}, function(ret,err) {
    if (ret) {
    api.toast({
                                msg:"读取初始化按键",
                            duration: 2500,
                            location: "bottom"
                        });
    }
    else
    {
    api.toast({
                                msg:'操作失败!',
                            duration: 2500,
                            location: "top"
                        });
       
           
   

    };
    if(err) alert(JSON.stringify(ret));
   });
         //listenint(uuid,suuid,cuuid);

}

function openlist(){
}
function compare(propertyName) {
return function (object1, object2) {
var value1 = object1[propertyName];
var value2 = object2[propertyName];
if (value2 < value1) {
return -1;
}
else if (value2 > value1) {
return 1;
}
else {
return 0;
}
}
}

</script>
</body>
</html>
45
帖子
0
勋章
213
Y币
模块咨询-Turbo 发表于 2016-12-14 17:26
代码贴下,

截图看看lightblue下检测的,跟ble模块获取的

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>slidPane</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <style>
        body{
        background-color:#F2F2F2;
        width: 100%;
        height: 100%;
        }
        header {
            background-color: #f2f2f2;
            border-bottom: 1px solid #f2f2f2;
        }
        .header {
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;            
        }
        .header a{
            display: block;
            padding: 20px;
        }
        .title {
            line-height:40px;
            -webkit-box-flex: 1;
            -webkit-flex: 1;
            flex: 1;
            text-align: center;
        }
        .header .menu {
            background-size: 30px;
            background-repeat: no-repeat;
            background-position: center;
            background-image: url("../image/menu.png");
        }
        .btn{
                        width:80px;
                        height:30px;
                        background-color:#4285F4;
                        margin:10px;
                        font-size:13px;
                        border-radius:9px;
                }
        .input{
                        width:80%;
                        height:30px;
                        font-size:13px;
                }

    </style>
</head>
<body>
<header>
    <div class="header">
        <a class="menu" tapmode="" onclick="sliding()"></a>
        <div class="title" >灵犀蓝魔测试工具</div>
        <a></a>
    </div>
</header>
<div>
   <button type="button" class="btn">
                            <a href="#" onClick="startscan();">搜索</a>
  </button>
   <button type="button" class="btn">
                            <a href="#" onClick="serch();">马达测试</a>
  </button>
   <button type="button" class="btn">
                            <a href="#" onClick="serch();">马达老化</a>
  </button>
   <input type="text" class="input">
                            <a href="#" onClick="serch();">执行</a>
  </input>
   <input type="text" class="input" value="返回结果">
  </input>
  
</div>
<script type="text/javascript" src="../script/api.js"></script>
<script>
            var ble;
                var suuid="0000ffe0-0000-1000-8000-00805f9b34fb";
                var puuid="";
                var cuuid="0000ffe1-0000-1000-8000-00805f9b34fb";
                var cuuid8="0000ffe8-0000-1000-8000-00805f9b34fb";
                var cuuid7="0000ffe7-0000-1000-8000-00805f9b34fb";
                var cuuid5="0000ffe5-0000-1000-8000-00805f9b34fb";
                var cuuid8="0000ffe8-0000-1000-8000-00805f9b34fb";
        var listdata;
        var UIListView;
        var mySettingInfo
    function sliding() {
        api.openSlidPane({type: 'left'});
    }
    apiready = function () {
      UIListView=api.require('UIListView');
      ble = api.require('ble');   
      mySettingInfo = api.require('mySettingInfo');
        };
                        function Datasion(uid,imgPath,title){
            this.uid=uid;
            this.imgPath=imgPath;
            this.title=title;
            this.icon="";
            }

function serch(){}
function startscan(){
        ble.stopScan();
        ble.initManager(function(ret){
        if(ret.state=="poweredOff"){alert("请打开蓝牙");bleset();}
          if(ret.state == "poweredOn"){
                          ble.scan(function(ret,err){
                            if(ret.status) {
                            api.toast({
                        msg:"扫描启动!"
                });
                                          setTimeout("getmac()",5000);
                            };
                            if(err) toast("扫描启动失败!");
    });
          }
        })
       
}
function getmac(){
        var data = new Datasion("","","","","","");
        data=[];

        ble.getPeripheral(
            function(ret,err) {
            if(ret){
             var length=ret.peripherals.length;
             var data1=ret.peripherals;
             alert(JSON.stringify(data1));
             data1.sort(compare("rssi"));
             //alert(JSON.stringify(data1));
             if (length>0){
             var uuid= new Array;
             var name= new Array;
             var rssi= new Array;
             data=[];
             for(i=0;i<length;i++){
                var txt=data1.name+"["+data1.uuid+"]"+data1.rssi;
                                data.push(new Datasion(data1.uuid,"widget://image/lock_l.png",txt));
                    }
                    listdata=data;
                    UIListView.close();
                    fnopen();

             }
         
     }
           
    });
   
}
function fnopen(){
        UIListView.open({
    rect: {
            y: api.winHeight/3.8,
            h: api.winHeight*0.67
                            
    },
    data: listdata,
    rightBtns: [{
        bgColor: '#388e8e',
        activeBgColor: '',
        width: 70,
        title: '开始连接',
        titleSize: 12,
        titleColor: '#fff',
        icon: '',
        iconWidth: 20
    },{
        bgColor: '#388e8e',
        activeBgColor: '',
        width: 70,
        title: '断开连接',
        titleSize: 12,
        titleColor: '#fff',
        icon: '',
        iconWidth: 20
    }],
    leftBtns: [{
        bgColor: '#388e8e',
        activeBgColor: '',
        width: 70,
        title: '服务',
        titleSize: 12,
        titleColor: '#fff',
        icon: '',
        iconWidth: 20
    },{
        bgColor: '#388e8e',
        activeBgColor: '',
        width: 70,
        title: '特征',
        titleSize: 12,
        titleColor: '#fff',
        icon: '',
        iconWidth: 20
    }],
    styles: {
        borderColor: '#E0E0E0',
        item: {
            bgColor: '#FFFFFF',
            activeBgColor: '#AFEEEE',
            height: 55.0,
            imgWidth: 40,
            imgHeight: 40,
            imgCorner: 4,
            placeholderImg: '',
            titleSize: 16.0,
            titleColor: '#000',
            subTitleSize: 12.0,
            subTitleColor: '#000',
            remarkColor: '#000',
            remarkSize: 16,
            remarkIconWidth: 30
        }
    },
    fixedOn: api.frameName
}, function(ret, err) {
    if (ret) {
       if (ret.eventType=="clickContent" ){
          var index=ret.index;
          puuid=listdata[index].uid;
          alert(JSON.stringify(listdata[index]));     
                }
       if (ret.eventType=="clickRightBtn" ){
          var index=ret.index;
          var rindex=ret.btnIndex;
          puuid=listdata[index].uid;
          switch (rindex)
          {
          case 0:
           ble.connect({
                   peripheralUUID: puuid
           },function(ret,err){
                     if(ret.status){
                        api.toast({
                            msg:"连接成功"
                    });
                         discserverint(puuid);           
                     }
                     else
                     {
                     alert(puuid+"连接错误代码:"+err.code);
                     }
           });
          break;
          case 1:
          ble.disconnect({
                  peripheralUUID: puuid
          },function(ret,err){
                  alert(JSON.stringify(ret));
          });
          break;
          }     
                }

    } else {
        alert(JSON.stringify(err));
    }
});
        }

function discserverint(uuid){
    ble.discoverService({
            peripheralUUID: uuid
    },function(ret,err){
            if(ret){
         // stopscan();
         readint(uuid)
          api.toast({
                  msg:"搜索到蓝牙服务。。"+JSON.stringify(ret)
          });
         
        
            }
    });
}
function bleset(){mySettingInfo.settingInt({ 'index': 1 }, function(ret, err) {alert(JSON.stringify(ret));});}
function readint(uuid){
ble.writeValueForCharacteristic({
    peripheralUUID: uuid,
    serviceUUID: suuid,
    characteristicUUID: cuuid,
    value: 'a1b4'
}, function(ret,err) {
    if (ret) {
    api.toast({
                                msg:"读取初始化按键",
                            duration: 2500,
                            location: "bottom"
                        });
    }
    else
    {
    api.toast({
                                msg:'操作失败!',
                            duration: 2500,
                            location: "top"
                        });
       
           
   

    };
    if(err) alert(JSON.stringify(ret));
   });
         //listenint(uuid,suuid,cuuid);

}

function openlist(){
}
function compare(propertyName) {
return function (object1, object2) {
var value1 = object1[propertyName];
var value2 = object2[propertyName];
if (value2 < value1) {
return -1;
}
else if (value2 > value1) {
return 1;
}
else {
return 0;
}
}
}

</script>
</body>
</html>
45
帖子
0
勋章
213
Y币
模块咨询-Turbo 发表于 2016-12-14 17:26
代码贴下,

截图看看lightblue下检测的,跟ble模块获取的

除了不能写,现在扫描的参数里没rssi
80
帖子
0
勋章
538
Y币
16年了,到现在还没解决
您需要登录后才可以回帖 登录

本版积分规则