0

我正在使用 react-native-bluetooth-serial。每当我尝试通过我的 react native 应用程序连接蓝牙设备时,我都会收到此错误:

错误:读取失败,套接字可能关闭或超时,读取 ret:-1 无法连接到设备

这是我正在尝试做的事情:

 connectToDevice () {
    if (this.state.discovering) {
      return false
    } else {
      this.setState({ discovering: true })
      console.log("searching");
      BluetoothSerial.list()
      .then((Devices) => {
        this.setState({ Devices, discovering: false })
        for(var i = 0; 1; i++)
        {
          if(Devices[i]["name"] == "JBL Flip 3 SE")
          {
            console.log(Devices[i]["id"]);
            BluetoothSerial.connect(Devices[i]["id"]).then((res) => {
              console.log(res);
            }).catch(err => {
              console.log(err);
            })
            break;
          }
        }
        // console.log(unpairedDevices);
      })
      .catch((err) => console.log(err.message))
    }
}

即使我克隆示例存储库也会发生同样的情况。

知道为什么会这样吗?

4

1 回答 1

1

我鼓励您在 React Native 中使用react-native-ble-plx蓝牙,如果您需要实时示例,您可以查看我们的辅助项目,该项目使用此库向 Arduino 发送颜色并处理 LED 灯https://github.com /SparingSoftware/HomeLed

于 2020-05-25T10:49:05.840 回答