收藏
回答

wx.createBLEConnection连接不稳定,报错status 133?

  1. 环境

手机型号vivo x80 Android 13

微信版本:8.0.40 基础库:3.0.2

蓝牙板:是自己定制的,使用的芯片是WH-BLE102 U1.1

在iOS 微信版本8.0.39上连接大概是10次2次连接不上。升级到8.0.42基本上10次2次连接上。

2.连接开发的蓝牙板,连接非常不稳定,大概10次连接有2次成功,其他都报连接错误,status 133.

我尝试了你们提供的蓝牙BLE Sample代码,也是一样的现象。每次连接后都会关闭BLE连接和Adapter.

请问如何调试,确认问题点?

connectBLE(name, deviceId) {

    const that = this;

    wx.createBLEConnection({

      deviceId: deviceId,

      success: (res) => {

        console.log("[wiggle]start BLE connection OK ", res);


        const mtu = 100;

        wx.setBLEMTU({

            deviceId: deviceId,

            mtu,

            success: (res) => {

              console.log("setBLEMTU success>>", res)

            },

            fail: (res) => {

              console.log("setBLEMTU fail>>", res)

            }

          }),

          //开始监听蓝牙状态 


        that.getBLEDeviceServices(deviceId);

        that.setConnectedDeviceInfo2GlobalData(name, deviceId);

        that.setGlobal2LocalData();

        wx.hideLoading();

        wx.showToast({

          title: '连接成功',

          mask: true,

          duration: 1000,

        });


        wx.onBLEConnectionStateChange((res) => {

          console.log("onBLEConnectionStateChange res=", res);

          if((res.connected === false)&&(res.deviceId === getApp().globalData.deviceId)){

            console.log("onBLEConnectionStateChange reset connected device!" );

            that.clearConnectedDeviceGlobalData();

            that.clearLocalDeviceConnectedData();

          }


        });


      },

      fail: (res) => {

        wx.hideLoading();

        console.log("[wiggle]start BLE connection falied **** ", res);

        if (res.errCode === -1{

          wx.showToast({

            title: "已经连接",

            mask: true,

          });

          setConnectedDeviceInfo2GlobalData(name, devcieId);

        } else {

          that.showErrMessage(res.errCode);


        }

      },

    });

    console.log("[wiggle][tapEventCreateBLEConnection]end");

  },


3.wx.writeBLECharacteristicValue写入是成功的,但是写入7个数据,只有1个数据可以获取到是写入的。间隔时间从50毫秒,1秒,2秒都试过。

 setTimeout(() => {

      this.createSpeedCmdBuffer();

    }, 1000);


createSpeedCmdBuffer() {

    let speed = this.data.speed * 1000;

    let temp = speed.toString(16);

    console.log("[wiggler]createSpeedCmdBuffer = ", util.formatTime(new Date()), temp, speed);

    let buffer = util.stringHex2SpecialBuffer(temp, 0x88, 0x88);

    // console.log("[wiggler]createSpeedCmdBuffer = ", util.ab2Array(buffer));

    

    let deviceId = this.data.deviceId;

    let serviceId= this.data.serviceId;

    let uuid = this.data.writeUUID[0];


    wx.writeBLECharacteristicValue({

      deviceId: deviceId,

      serviceId: serviceId,

      characteristicId: uuid,

      writeType:"write",

      value: buffer,

      success: (res) => {

        console.log("[wiggle]createSpeedCmdBuffer 1-OK res = ", res);

      },

      fail: (res) => {

        console.log("[wiggle]createSpeedCmdBuffer 2-fail res = ", res);

      },

      complete: (res) => {

        // console.log("[wiggle]createSpeedCmdBuffer 3-complete res = ", res);

      }

    });

  },



最后一次编辑于  2023-09-18
回答关注问题邀请回答
收藏

2 个回答

  • 世界一刘
    世界一刘
    01-03

    这问题社区没人管吗

    01-03
    有用
    回复
  • Jones
    Jones
    2023-09-28

    我和你遇到一样的问题,而且这个问题只有安卓有,你有解决吗

    2023-09-28
    有用
    回复
登录 后发表内容