[英]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.