简体   繁体   中英

How to detect Mindstorm EV3 using flutter_blue

I am trying to setup a bluetooth server on a Mindstorm EV3 using ev3dev with python.

The server appears to work fine as it is a very basic implementation of the bluetooth server socket.

#!/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()

The problem I am having right now is the fact that I cannot seem to detect the bluetooth signal from the EV3 in my flutter app. I can find other devices just fine and I can find the EV3 in the bluetooth settings on the phone, it's just the app that doesn't detect it.

This is the code I use to detect bluetooth devices

_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);

The EV3 does have a name set so it is not being ignored because of the name check.

Any advice is appreciated.

Thanks in advance

This is an old question, but posting this for future readers.

Note that there are many versions/variants of Bluetooth, and not all are compatible. The flutter_blue package is for BLE (Low Energy) which a recent technology, introduced in Bluetooth 4.0, and common in phones since 2015 see https://en.wikipedia.org/wiki/Bluetooth#Specifications_and_features

The Lego EV3 uses Bluetooth V2.1 EDR, (Classic Bluetooth) as do older laptops, so this will be the reason that flutterBlue.scan() does not "see" these devices. see also https://superuser.com/questions/502825/how-can-i-find-out-what-version-of-bluetooth-my-laptop-supports .

If you want to work in Flutter, with Bluetooth Classic, look at other packages like https://pub.dev/packages/flutter_bluetooth_serial . (I am not saying this will work with EV3, but at least is the right Bluetooth!)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM