繁体   English   中英

如何在esp32和flutter应用程序之间的flutter中从BLE接收数据

[英]how to recieve data from BLE in flutter between esp32 and flutter app

我想从 ESP32 接收数据包并且 ESP32 工作正常(我使用 BLE 扫描仪对其进行了测试)但是当我想在我自己的应用程序上接收数据时,我收到以下数据:

I/flutter (23252): The received Value is ESP32 GET NOTI FROM DEVICE
I/flutter (23252): The received Value is
I/flutter (23252): The received Value is

其中“ESP32 GET NOTI FROM DEVICE”是ESP32蓝牙设备的名称

这不是我应该收到的……我想得到的数据是 0 或 1,所以我得到的值并不合适,实际上我收到了这个:

I/flutter (23252): The received Value is [69, 83, 80, 51, 50, 32, 71, 69, 84, 32, 78, 79, 84, 73, 32, 70, 82, 79, 77, 32, 68, 69, 86, 73, 67, 69]
I/flutter (23252): The received Value is [0, 0]
I/flutter (23252): The received Value is [0]

然后我将其转换为最上面的。

接收数据的代码是:

  writeDataAndWaitForRespond() async {
    writeData("A 300 300 300");
    List<BluetoothService> services = await targetDevice.discoverServices();
    print("////////////////We're here, listening to Hive...");
    services.forEach((service) async {
      var characteristics = service.characteristics;
      Future.delayed(const Duration(milliseconds: 500), () async {
        for (BluetoothCharacteristic c in characteristics) {
          List<int> value = await c.read();
          print("We're here, listening to hive...");
          String stringValue = new String.fromCharCodes(value);
          print("The received Value is $stringValue");
        }
      });
    });
  }

当我向设备发送“A 300 300 300”时,它会发送 1 或 0 作为回报。 这是写代码吗?? 我正在使用的库是 flutter_blue,提前致谢。

我认为您应该使用flutter_blue包。 我检查了 flutter_ble 包,它看起来像一个旧叉子。 还有一个示例项目。

与主题有关。 您需要扫描一个设备,然后才能发现目标特征服务。 之后,您必须注册到特定的特征。

如果是ESP32,你是在透明桥接模式下使用吗? 所以在这种情况下,你通常有 rx 和 tx 服务。 我还有一个例子,它可能会帮助你: https : //github.com/KevinRohn/flutter_ble_data_handler/blob/master/example/lib/main.dart

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM