1

我正在尝试使用 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 确实设置了名称,因此不会因为名称检查而被忽略。

任何建议表示赞赏。

提前致谢

4

1 回答 1

0

这是一个老问题,但将其发布给未来的读者。

请注意,蓝牙有许多版本/变体,并非所有版本都兼容。flutter_blue 包适用于 BLE(低功耗),这是一项最新技术,在蓝牙 4.0 中引入,自 2015 年以来在手机中很常见,请参阅https://en.wikipedia.org/wiki/Bluetooth#Specifications_and_features

Lego EV3 使用蓝牙 V2.1 EDR(经典蓝牙)和旧笔记本电脑一样,因此这将是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,但至少是正确的蓝牙!)

于 2020-11-13T07:31:39.573 回答