我正在尝试使用 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()
我现在遇到的问题是我似乎无法在我的颤振应用程序中检测到来自 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 确实设置了名称,因此不会因为名称检查而被忽略。
任何建议表示赞赏。
提前致谢