I would like to know how to realize a sort of "bluetooth broadcast" (using Bluetooth Low Energy) for a Flutter application. In particular, i want to achieve those points:
- I want to send random string and integers "in the air" using bluetooth.
- I want also to be able to receive those data by other devices
- The app must be able to send and receive simultaneously
Now, i checked some beacon library from pub.dev (like this or this) but it turns out that probably i did not understand if and how those libraries can help me.
For example, let's consider beacon_broadcast library:
The suggested code to make a beacon is the following:
beaconBroadcast
.setUUID('39ED98FF-2900-441A-802F-9C398FC199D2')
.setMajorId(1)
.setMinorId(100)
.setTransmissionPower(-59) //optional
.setIdentifier('com.example.myDeviceRegion') //iOS-only, optional
.setLayout('s:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-21v') //Android-only, optional
.setManufacturerId(0x001D) //Android-only, optional
.start();
However i'm a little bit confused. I would like to understand how can i send custom data (a simple string and a simpler integer). On the receiver side, i would like to get all beacons with a specific layout, not only beacons matching a specific UUID.
Something similar to what I want to achieve can be found here but it's made in kotlin. If you consider this as the nearest thing to what i need, please suggest me how can i use native code in my flutter project.
Thank you very much.
Edit 1: we now need to find two Flutter libraries in order to simultaneously send and receive all kind of beacons with the AltBeacon layout. This is not trivial, because it turns out that other devs have strangely implemented one side of the communication and not both. Moreover, it's difficult to find libraries with "batteries included" (i.e able to talk each other out-of-the-box).
Edit 2: Breaking News ! I combined two flutter libraries, in particular flutter_beacon and beacon_broadcast. Now, please, help me with the following problem: i can receive beacon, start advertising but not both at the same time.
I don't know what my mistake is, anyway, let's have a look here:
The code i use to scan beacons is the following:
Future<void> beacon() async {
await flutterBeacon.initializeScanning;
final regions = <Region>[];
// Android platform, it can ranging out of beacon that filter all of Proximity UUID
regions.add(Region(identifier: 'unito'));
// to start monitoring beacons
var _streamRanging = flutterBeacon.ranging(regions).listen((RangingResult result) {
// result contains a region, event type and event state
print(result);
print(result.toJson);
print(result.beacons.toString());
});
}
The following content is displayed into the debug console:
But, unfortunately, nothing happens if i also activate BLE Advertising:
So, are there any advices ? When i use separately a device for scanning and another for advertising it works...

