Murxer
Murxer

Reputation: 1

L2cap connection flutter Linux

I want to exchange Data between my android Smartphone and Linux (Debian 11.9) MC via Bluetooth. I adding a network-Card Intel AX200 over the M.2 slot. I'm able to connect my Smartphone with the MC ('bluetoothctl: connected: yes') but I'm not able to create the L2CAP-Channel to send data. My kernel (5.10.104-cip3) doesn't support RFCOMM and BNEP.

I tried to develop a simple app to test the connection. The first button create the connection to the MC. When I press the second button this Error occurs: D/L2capBlePlugin( 6662): createL2capChannel: Failure(java.io.IOException: read failed, socket might closed or timeout, read ret: -1)

This is the flutter code on the client:

#use of l2cap_ble.dart
Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('L2CAP Connection Demo'),
      ),
      body: Column(children: [
        ElevatedButton(
          onPressed: () async {
            #this works:
            await ble.connectToDevice(deviceId);
          },
          child: Text('connectToDevice'),
        ),
        ElevatedButton(
          onPressed: () async {
            #Error:
            print('Create Channel...');
            await ble.createL2capChannel(0x1001);
          },
          child: Text('channelCreated'),
        ),
        ElevatedButton(
          onPressed: () async {
            await ble.sendMessage(Uint8List.fromList([0X04, 0X00, 0X13, 0X00]));
          },
          child: Text('messageSent'),
        ),
        ElevatedButton(
          onPressed: () async {
            await ble.disconnectFromDevice(deviceId);
          },
          child: Text('disconnect'),
        ),
      ]),
    );
  }

and this the python Code on my MC:

import bluetooth

server_sock = bluetooth.BluetoothSocket(bluetooth.L2CAP)
port = 0x1001
server_sock.bind(("", port))
server_sock.listen(1)

client_sock, address = server_sock.accept()
print(f"Verbunden mit {address}")

while True:
    data = client_sock.recv(1024)
    if len(data) == 0: break
    print(f"Empfangene Nachricht: {data}")

client_sock.close()
server_sock.close()```

Upvotes: 0

Views: 95

Answers (0)

Related Questions