Sending data to a bluno beetle with flutter

67 Views Asked by At

I am trying to talk to a bluno beetle v1.1 through bluetooth with a flutter app. From what I understand of the example app I have to use the bluetooth serial port and not the services/characteristics? I did ArduinoBLE as it seemed like that might make me be able to use characteristics but that doesn't work with the bluno so not sure what else to use on the arduinos side.

So I am able to connect to the device using the flutter blue plus library but I can't figure out how to send data to the serial port.

I've tried to use flutter bluetooth serial ble but it seems like you can't even define a baudrate? or atleast I am unsure of how to use it and it has limited documentation.

I've also tried to use flutter_libserialport but that straight up does not build the apk because of some error in the lib i don't know how to fix.

Here are some code snippets:

Where i connect to the bluetooth scanned devices

                            onTap: () async {
                             // change page to ledcontroll
                                Navigator.push(
                                  context,
                                  MaterialPageRoute<void>(
                                    builder: (BuildContext context) =>
                                        const LedControll(),
                                  ),
                                );
                                // connect to the device
                                final bluetoothDevice = BluetoothDevice(
                                    remoteId: data.device.remoteId);
                                await bluetoothDevice.connect();

                                // var services =
                                //     await bluetoothDevice.discoverServices();
                                // for (BluetoothService service in services) {
                                //   // ignore: avoid_print
                                //   print("Service: $service");
                                //   for (BluetoothCharacteristic characteristic
                                //       in service.characteristics) {
                                //     // ignore: avoid_print
                                //     print("Characteristic: $characteristic");
                                //   }
                                // }
                              },

bluetooth scanner

class BluetoothController extends GetxController {
  Future scanDevices() async {
    FlutterBluePlus.startScan(timeout: const Duration(seconds: 5));
    //FlutterBluePlus.stopScan();
  }

  Stream<List<ScanResult>> get scanResults => FlutterBluePlus.scanResults;
}
1

There are 1 best solutions below

0
On

I found the fix!

on the arduinos side i've got the basic code from the example:

#include <Adafruit_NeoPixel.h>

int pixelPin = 3;
int pixelNum = 1;

int data;

String command;
String r;
String g;
String b;

int color[3] = {150, 0, 0};

Adafruit_NeoPixel pixels(pixelNum, pixelPin, NEO_GRB + NEO_KHZ800);

void setup() {
  pixels.begin();
  Serial.begin(115200);
}

void loop() {
  if(Serial.available() > 0) {
    data = Serial.read();
    command = Serial.readStringUntil('\n');
    Serial.print("New Byte Received: 0x");
    Serial.println(data, HEX);

    Serial.print("command: ");
    Serial.println(command);

    String c[3];
    int index = 0;
    for (int i=0;i<3;i++){
      index = command.indexOf(' ');
      c[i] = command.substring(0, index);
      command = command.substring(index+1);

      color[i] = c[i].toInt();
    }
  }

  //manage pixel
  pixels.clear();

  for(int i=0; i<pixelNum; i++) {

    pixels.setPixelColor(i, pixels.Color(color[0], color[1], color[2]));
    pixels.show();
    delay(500);
  }
}

and on the flutter size i made it run through every single service and every single characteristic and try to send a message containing its uuid to the bluno and that actually came through into the serial monitor :)