我正在尝试使用ev3dev和python在Mindstorm EV3上设置蓝牙服务器。
服务器看起来工作得很好,因为它是蓝牙服务器套接字的一个非常基本的实现。
#!/usr/bin/env python3
import bluetooth
from ev3dev2.sound import Sound
sound = Sound()
server_sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
port = 1
server_sock.bind(("", port))
server_sock.listen(1)
sound.speak("Accepting connections on port " + str(port))
client_sock, address = server_sock.accept()
sound.speak("Accepted connection from " + str(address))
data = client_sock.recv(1024)
sound.speak("received " + str(data))
client_sock.close()
server_sock.close()我现在遇到的问题是,在我的flutter应用程序中,我似乎无法检测到来自EV3的蓝牙信号。我可以很好地找到其他设备,我可以在手机的蓝牙设置中找到EV3,只是应用程序没有检测到它。
这是我用来检测蓝牙设备的代码
_btSubscription = _flutterBlue.scan().listen((scanResult) {
if (scanResult.device.name.isEmpty || _detectedDevices.contains(scanResult.device))
return;
print('Found Bluetooth device: (${scanResult.device.name})');
_detectedDevices.add(scanResult.device);EV3确实设置了名称,因此不会因为名称检查而被忽略。
任何建议都是值得感谢的。
提前感谢
发布于 2020-11-13 15:31:40
这是一个古老的问题,但将其发布给未来的读者。
请注意,蓝牙有许多版本/变体,并不是所有版本/变体都兼容。flutter_blue包是针对BLE (低能耗)的,这是一项新技术,在蓝牙4.0中引入,自2015年以来在手机中很常见。请参阅https://en.wikipedia.org/wiki/Bluetooth#Specifications_and_features
乐高EV3使用蓝牙V2.1EDR,(经典蓝牙)作为老式笔记本电脑,所以这将是flutterBlue.scan()无法“看到”这些设备的原因。另请参见https://superuser.com/questions/502825/how-can-i-find-out-what-version-of-bluetooth-my-laptop-supports。
如果你想在Flutter中工作,使用蓝牙经典版,看看其他的软件包,比如https://pub.dev/packages/flutter_bluetooth_serial。(我并不是说这可以在EV3上工作,但至少是正确的蓝牙!)
https://stackoverflow.com/questions/58412177
复制相似问题