收藏
回答

微信蓝牙在android版的奇怪问题,IOS正常

问题描述: 在android上 wx.getBLEDeviceService得到了错误的device service uuid,在IOS上是正确的。 说一下问题:

1. 通过扫描得到deviceID: F2:13:4A:B4:EA:75

2. 找到其advertiesServiceUUIDs:["6e400001-xxxxxx-e50e24dcca9e"]

3. 通过creatBleconnection后读取service uuid变成了"000018xxxxx"

4. 有一次调试偶然间看到这个uuid是一个叫UIKI-sport-002的设备的数据,但是我周围没有这个设备,其他蓝牙软件扫描不能发现这个设备,我怀疑是你们hardcode的。或者缓存的原因。(最后一张图UIKI-sport-002我怀疑这个设备是你们虚拟出来的)


具体看代码和截图:


相应的代码和log:

var topClass = this;
        var currentDeviceId=topClass.data.deviceId;
        wx.createBLEConnection({
            deviceId: currentDeviceId,
            success: function (res) {
                console.log("success create a connection to device", currentDeviceId, res);
                topClass.data.connected = true;
                /**
                 * 连接成功,后开始获取设备的服务列表
                 */
                wx.getBLEDeviceServices({
                    // 这里的 deviceId 需要在上面的 getBluetoothDevices中获取
                    deviceId: currentDeviceId,
                    success: function (serviceRes) {
                        console.log("success to get device services", currentDeviceId, serviceRes);
                        topClass.setData({ services: serviceRes.services });
                        serviceRes.services.forEach(function (devService) {
                            console.log('loop device service:', devService);
                            //if (devService.uuid.indexOf("6e400001-b5a3-f393-e0a9-e50e24dcca9e") != -1) {
                            topClass.setData({ serviceId: devService.uuid });
                            console.log('getBLEDeviceCharacteristics:', currentDeviceId, devService.uuid);
                            topClass.getBLEDeviceCharacteristics();
                            //}
                        });
                        if (topClass.data.writeCharId && topClass.data.notefyCharId) {     
                                wx.showModal({
                                    title: '提示',
                                    content: '建立连接成功,可以发送数据了'
                                });
                        }else{
                            wx.showModal({
                                    title: '提示',
                                    content: '找不到正確的characteristics'
                                });
                                return;
                                wx.closeBLEConnection({
                                  success: function(res){
                                    console.log("success closebleconnection");
                                  },
                                  fail: function(res) {
                                     console.log("failed closebleconnection");
                                  },
                                  complete: function(res) {
                                    // complete
                                  }
                                })
                            }
                    },
                    complete: function (res) {

                    }
                })
            },
            fail: function (res) {
                console.log("failed to connect to device:", res);
            },
            complete: function (res) {
            }





回答关注问题邀请回答
收藏

2 个回答

  • Vera
    Vera
    2017-08-24

    请教下楼主android连接蓝牙能成功吗?是wx.openBluetoothAdapter=》wx.startBluetoothDevicesDiscovery=》wx.getBluetoothDevices=》wx.createBLEConnection这样调用的吗?我用android手机时wx.createBLEConnection报10003错误死活连不上,wx.createBLEConnection的参数是mac地址吗?还是要转成uuid?求指教,万分感谢

    2017-08-24
    有用
    回复
  • 吉吉
    吉吉
    2017-05-09

    有很多service uuid 的,你要使用你们设备的uuid

    2017-05-09
    有用
    回复
登录 后发表内容