flutter_blue
flutter_blue copied to clipboard
Help! connect to device
How can I connect to device if I only have mac address value? Thanks a lot!
If you know the information of the device beforehand then you can create a BluetoothDevice
object yourself and use that to connect.
Simple example:
BluetoothDevice myDevice = BluetoothDevice(
id: DeviceIdentifier("MAC address"),
type: BluetoothDeviceType.le,
name: "Device Name",
),
await myDevice.connect();
Pre Flutter Blue 0.6.0:
BluetoothDevice myDevice = BluetoothDevice(
id: DeviceIdentifier("MAC address"),
type: BluetoothDeviceType.le,
name: "Device Name",
),
FlutterBlue.instance.connect(mydevice);
Thanks for your support <3
On iOS you cannot connect to a device via mac address - they are not exposed to the users (https://stackoverflow.com/a/2971250/4312184). As I know, the only way to do it is to store device mac address inside an advertisement manufacturer data. At least we do it with our devices and everything working good.
I am using ^0.7.2 version and when I run on apple device my app, the logs don't show me the mac address, but I know the device mac address to connect to, the code above doesn't work for me. How can in create device in connect to it? Problem: BluetoothDevice doesn't have a default constructor. Thank you.
I am using ^0.7.2 version and when I run on apple device my app, the logs don't show me the mac address, but I know the device mac address to connect to, the code above doesn't work for me. How can in create device in connect to it? Problem: BluetoothDevice doesn't have a default constructor. Thank you.
I'm also in trouble
Does anyone have any idea how to solve this issue, I also want to connect to a specific device, and there is no longer the constructor in the BluetoothDevice class.
@WanKapef try importing this
import 'package:flutter_blue/gen/flutterblue.pb.dart' as ProtoBluetoothDevice;
and then use the ProtoBluetoothDevice.BlueoothDevice constructor.
var protoBt = ProtoBluetoothDevice.BluetoothDevice(
remoteId: uuid
);
var d = BluetoothDevice.fromProto(protoBt);