[英]How to detect Mindstorm EV3 using flutter_blue
我正在嘗試使用帶有 python 的 ev3dev 在 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 確實設置了名稱,因此不會因為名稱檢查而被忽略。
任何建議表示贊賞。
提前致謝
這是一個老問題,但將其發布給未來的讀者。
請注意,藍牙有許多版本/變體,並非所有版本都兼容。 Flutter_blue package 用於 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,但至少是正確的藍牙!)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.