Abdullah Al Noman
Abdullah Al Noman

Reputation: 41

How to received data from arduino using bluetooth flutter?

I am able to connect and send data to arduino but I don't know how I can received data from arduino. Please help me.

I am using flutter_bluetooth_serial package

Send message to arduio code here:

Future<bool> sendMessage(String text) async {
    if (connected != false) {
      //await connectToBluetooth();
      text = text.trim();
      connection!.output.add(Uint8List.fromList(utf8.encode(text + "\r\n")));
      await connection!.output.allSent;
      return true;
    } else {
      return false;
    }
   
  }

Upvotes: 1

Views: 1491

Answers (1)

LMech
LMech

Reputation: 168

If you bonded the device and have the address you can start a stream to listen to the changes like so:

connection = await BluetoothConnection.toAddress(server.address);
connection!.input!.listen((event) {
print(event);
}

from the Arduino side you can make the bluetooth to send data like:

bluetooth.write(-1) // for numbers;
bluetooth.print(str) // for strings;

Upvotes: 3

Related Questions