Can't receive/read response from OBD2 Dongle using BLE connection

55 Views Asked by At

I am currently trying to communicate to every characteristic my app has discovered. I am sending 'AT Z\r' and 'AT R1\r' (as a test) to check if the commands work. Using nRF Connect, i see that characteristic 0000fff1-0000-1000-8000-00805f934fb sends back an indication.

Indication received from 0000fff1-0000 -1000-8000-00805f9b34fb, value: (0x) 4F-4B-OD-0D-3E 15:57:03.160 "(0x) 4F-4B-OD-OD-3E" received

However, when im in my app and setNotifyValue(true) to that characteristic, it doesn't print any received data, or at best just echoes it back (yes, even after sending 'AT E0\r').

This is my function:

void fetchDataFromDevice(BluetoothDevice device) async {
    List<BluetoothService> services = await device.discoverServices();

    for (BluetoothService service in services) {
      for (BluetoothCharacteristic characteristic in service.characteristics) {
        if (characteristic.properties.notify) {
          await characteristic.setNotifyValue(true);
        }

        if (characteristic.properties.write) {
          final commands = ['AT Z\r', 'AT R1\r'];
          for (var command in commands) {
            final convertedCommand = AsciiEncoder().convert(command);
            await characteristic.write(convertedCommand);
            print("Command '$command' sent to: ${characteristic.uuid}");
              characteristic.lastValueStream.listen((data) {
              print("Received from ${characteristic.uuid}: $data");
              print("Received from ${characteristic.uuid}: ${String.fromCharCodes(data)}");
              print("Received from ${characteristic.uuid}: ${data.map((e) => e.toRadixString(16).padLeft(2, '0')).join('-').toUpperCase()}");
            });
            await Future.delayed(Duration(seconds: 1));
            characteristic.lastValueStream.listen((data) {
              print("Received from ${characteristic.uuid}: ${String.fromCharCodes(data)}");
              print("Received from ${characteristic.uuid}: ${data.map((e) => e.toRadixString(16).padLeft(2, '0')).join('-').toUpperCase()}");
            });
            await Future.delayed(Duration(seconds: 1));
            characteristic.lastValueStream.listen((data) {
              print("Received from ${characteristic.uuid}: ${String.fromCharCodes(data)}");
              print("Received from ${characteristic.uuid}: ${data.map((e) => e.toRadixString(16).padLeft(2, '0')).join('-').toUpperCase()}");
            });
          }
        }
      }
    }
  }

And this is the output of the Debug Console:

I/flutter (20392): Received from 49535343-aca3-481c-91ec-d85e28a60318: 41-54-20-52-31-0D
I/flutter (20392): Command 'AT R1
I/flutter (20392): Received from 49535343-aca3-481c-91ec-d85e28a60318: [65, 84, 32, 82, 49, 13]
I/flutter (20392): Received from 49535343-aca3-481c-91ec-d85e28a60318: AT R1
I/flutter (20392): Received from 49535343-aca3-481c-91ec-d85e28a60318: 41-54-20-52-31-0D
I/flutter (20392): Received from 49535343-aca3-481c-91ec-d85e28a60318: AT R1
I/flutter (20392): Received from 49535343-aca3-481c-91ec-d85e28a60318: 41-54-20-52-31-0D
I/flutter (20392): Received from 49535343-aca3-481c-91ec-d85e28a60318: AT R1
I/flutter (20392): Received from 49535343-aca3-481c-91ec-d85e28a60318: 41-54-20-52-31-0D
D/[FBP-Android](20392): [FBP] onMethodCall: setNotifyValue
D/BluetoothGatt(20392): setCharacteristicNotification() - uuid: 0000fff1-0000-1000-8000-00805f9b34fb enable: true
D/[FBP-Android](20392): [FBP] onDescriptorWrite:
D/[FBP-Android](20392): [FBP]   chr: fff1
D/[FBP-Android](20392): [FBP]   desc: 2902
D/[FBP-Android](20392): [FBP]   status: GATT_SUCCESS (0)
D/[FBP-Android](20392): [FBP] onMethodCall: writeCharacteristic
D/[FBP-Android](20392): [FBP] onCharacteristicWrite:
D/[FBP-Android](20392): [FBP]   chr: fff2
D/[FBP-Android](20392): [FBP]   status: GATT_SUCCESS (0)
D/[FBP-Android](20392): [FBP] onCharacteristicChanged:
D/[FBP-Android](20392): [FBP]   chr: fff1
I/flutter (20392): Command 'AT Z
I/flutter (20392): Received from fff2: [65, 84, 32, 90, 13]
I/flutter (20392): Received from fff2: AT Z
I/flutter (20392): Received from fff2: 41-54-20-5A-0D
D/BluetoothGatt(20392): onConnectionUpdated() - Device=8C:DE:52:D9:16:6A interval=12 latency=0 timeout=512 status=0
D/[FBP-Android](20392): [FBP] onCharacteristicChanged:
D/[FBP-Android](20392): [FBP]   chr: fff1
I/flutter (20392): Received from fff2: AT Z
I/flutter (20392): Received from fff2: 41-54-20-5A-0D
I/flutter (20392): Received from fff2: AT Z

Its too much to fit everything in here, but you guys get the pattern, receiving echoes from other services, but the one thats actually sending correct repsonses in nRF Connect (characteristic fff1) somehow doesnt do that in my app.

Any ideas why?

In the end, im trying to receive continuous ambient air temperature data, but for now ive tried everything to just receive an "OK" in my app.

0

There are 0 best solutions below