I am writing an application to control devices with BLE
Therefore, for control I need to send commands to them through the SERVICE_UUID and CHARACTERISTIC_UUID.
I am using the flutter_blue library, and I use a function like this
void _turnOn() async {
List<BluetoothService> services = await widget.device.discoverServices();
services.forEach((service) async {
// do something with service
var characteristics = service.characteristics;
for(BluetoothCharacteristic c in characteristics) {
if (service.uuid.toString() == "bae55b96-7d19-458d-970c-50613d801bc9"){
if (c.uuid.toString() == "76e137ac-b15f-49d7-9c4c-e278e6492ad9") {
List<int> value = await c.read();
if (value.toString() == "[1]"){
await c.write([0]);
_changeColor(0);
}
else if (value.toString() == "[0]"){
await c.write([1]);
_changeColor(1);
}
}
}
}
});
}
But the problem is I have to use the loop and it’s quite complicated
So do I have a way to send commands directly, such as Sendcommand (SERVICE_UUID, CHARACTERISTIC_UUID, DATA)
In some way or does a library support this?
Does anyone have any ideas?