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

[BUG] ble模块连接报错133

[复制链接]
发表于 2023-3-28 11:08:57
本帖最后由 BIP353084 于 2023-3-28 13:44 编辑

之前用ble模块连接没问题,这几天连接蓝牙一直报错133,安卓和ios的都不行

api.showProgress({
            title: '蓝牙连接中...'
    });
    console.log('---------------------------连接中。。。。')
    var ble = api.require('ble');
    console.log('---------------------------连接中。。。。')
        ble.connect({
            peripheralUUID:peripheraluuid
        }, function(ret, err) {
            console.log('---------------------------连接成功。。。。')
            console.log(JSON.stringify(ret))
            obj.peripheralUUID = ret.peripheralUUID
            if (ret.status) {
                api.hideProgress();
                alert("连接成功!");
                var ble = api.require('ble');
                    ble.discoverService({
                        peripheralUUID: ret.peripheralUUID
                    }, function(ret) {
                        if (ret) {
                            console.log(JSON.stringify(ret))
                        }
                    });
            } else {
                console.log(JSON.stringify(err))
                alert("连接失败");
                api.hideProgress();
            }
        });


0
帖子
1
勋章
2524
Y币
是不是和别的设备有链接,断开其他的设备再试试
10
帖子
0
勋章
127
Y币
模块开发-JP1688 · 2023-3-28 13:58是不是和别的设备有链接,断开其他的设备再试试

调用disconnect方法不执行,跟之前配对过的蓝牙耳机有关系吗?
1
帖子
0
勋章
24
Y币
管理员麻烦升级一下,会不会是这个问题。 Android Ble 连接设备失败 onConnectionStateChange status 返回133

Android Ble 连接设备失败时回调函数 onConnectionStateChange status 返回133
开始找问题 各种mac地址,权限,线程…找了个遍,结果就是返回纹丝不动
又因为 mBluetoothGatt = mBluetoothDevice.connectGatt(mContext, true, mGattCallback);
第二个参数传的true 所有导致返回的status是4,找遍了都没找到4代表什么状态,就懵逼了一下午,
后来在调试的时候改成false才发现报 status =133,一上网查问题就解决了
SDK >6.0以上连接蓝牙函数多加了一个参数,坑死我了,一行代码坑半天

错误代码:
mBluetoothGatt = mBluetoothDevice.connectGatt(mContext, false, mGattCallback);
1
正确代码
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    mBluetoothGatt = mBluetoothDevice.connectGatt(mContext, false, mGattCallback,BluetoothDevice.TRANSPORT_LE);
  } else {
   mBluetoothGatt = mBluetoothDevice.connectGatt(mContext, false, mGattCallback);
  }
您需要登录后才可以回帖 登录

本版积分规则