readErrors method

Future<List<String>> readErrors()

Errors are returned in a list ordered from oldest to newest.

Implementation

Future<List<String>> readErrors() async {
  final bleService = await getBleService();
  final errorsCharacteristic = bleService.characteristics.firstWhere(
    (char) => char.uuid.str == ViamBluetoothUUIDs.errorsUUID,
    orElse: () => throw Exception('errorsCharacteristic not found'),
  );

  final errorsBytes = await errorsCharacteristic.read();
  final errorsString = String.fromCharCodes(errorsBytes); // not decoding with utf8 or it stops at first null byte
  // split by null bytes and filter out empty strings
  final errorList = errorsString.split('\x00').where((error) => error.isNotEmpty).toList();
  return errorList;
}