简体   繁体   English

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

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

I want to receive data packets from ESP32 and the ESP32 is working properly(I tested it using BLE scanner) but when I want to receive data on my own app, i receive the following data:我想从 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

where "ESP32 GET NOTI FROM DEVICE" is the name of ESP32 bluetooth device其中“ESP32 GET NOTI FROM DEVICE”是ESP32蓝牙设备的名称

and this is not what I should receive... the data I want to get is either 0 or 1, so the value I got is not really suitable and actually I received this:这不是我应该收到的……我想得到的数据是 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]

then I converted it to the top one.然后我将其转换为最上面的。

the code which receives the data is:接收数据的代码是:

  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");
        }
      });
    });
  }

when I send "A 300 300 300" to the device, it'll send either 1 or 0 in return.当我向设备发送“A 300 300 300”时,它会发送 1 或 0 作为回报。 is this the write code??这是写代码吗?? the library I'm using is flutter_blue, Thanks in advance.我正在使用的库是 flutter_blue,提前致谢。

I think you should use the flutter_blue package.我认为您应该使用flutter_blue包。 I checked the flutter_ble package, it looks like an old fork.我检查了 flutter_ble 包,它看起来像一个旧叉子。 There is also an example project.还有一个示例项目。

In relation to the topic.与主题有关。 You need to scan for a device, then you can discover the target characteristic service.您需要扫描一个设备,然后才能发现目标特征服务。 After that you have to register to the specific characteristics.之后,您必须注册到特定的特征。

If it is a ESP32, do you use it in transparent bridge mode?如果是ESP32,你是在透明桥接模式下使用吗? So in this case, you generally have service for rx and tx.所以在这种情况下,你通常有 rx 和 tx 服务。 I've also an example, which might help you out: https://github.com/KevinRohn/flutter_ble_data_handler/blob/master/example/lib/main.dart我还有一个例子,它可能会帮助你: https : //github.com/KevinRohn/flutter_ble_data_handler/blob/master/example/lib/main.dart

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

相关问题 Android app(Java) 和 ESP32 BLE 服务器之间的 Gatt 连接有问题 - I have a problem with Gatt connection between Android app(Java) and ESP32 BLE Server Android + ESP32 通过蓝牙 (BLE) 发送数据 - Android + ESP32 send data over bluetooth (BLE) 将数据从 Android 手机发送到 ESP32 - Send data from Android Phone to ESP32 如何使用Micropython直接连接ESP32 BLE和手机蓝牙? - How Can I Directly Connect ESP32 BLE with Mobile Bluetooth using Micropython? 通过 BLE 在 ESP32 中共享音频文件 - Audio file sharing in ESP32 over BLE 如何使用 flutter video_player 插件支持来自 ESP32CAM 的视频流? - How to support video streaming from ESP32CAM using flutter video_player plugin? 升级到Android 9后无法从Xamarin.Forms应用打开ESP32套接字 - Unable to open ESP32 socket from Xamarin.Forms app after upgrading to Android 9 ESP32 Android HTTP 上的应用程序通信 - ESP32 Android App communication over HTTP ESP32 在与 MIT App Inventor 2 交互时停止一切 - ESP32 stops everything when interacting with MIT App inventor 2 Android BLE,扫描开始,找到设备但未连接过滤器(ESP32 和三星) - Android BLE, scan started, finds devices but does not connect with filter (ESP32 & Samsung)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM