PhilipsHue / flutter_reactive_ble

Flutter library that handles BLE operations for multiple devices.
https://developers.meethue.com/
Other
667 stars 334 forks source link

App crash when I turn off esp32. #731

Closed Ali-Ahmad-dev closed 1 year ago

Ali-Ahmad-dev commented 1 year ago

Please help,

App connects to esp32 and perform read and write operations in respectively. But When I power off the esp app is crashing without providing any kind of exception.

Exception : W/System.err(20805): io.reactivex.exceptions.UndeliverableException: The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with. Further reading: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling | com.polidea.rxandroidble2.exceptions.BleDisconnectedException: Disconnected from MAC='XX:XX:XX:XX:XX:XX' with status 0 (GATT_SUCCESS) W/System.err(20805): at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:367)

onConnection Function :

D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26da enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26d9 enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26aa enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26ac enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26ad enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26a9 enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26ae enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26af enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26b0 enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26b3 enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26b1 enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26b2 enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26b4 enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26b6 enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26b5 enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26b7 enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26ab enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26ba enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26bb enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26bc enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26bd enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26be enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26bf enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26c0 enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26c1 enable: false D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26c2 enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26c3 enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26c4 enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26c5 enable: false D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26c6 enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26c7 enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26c8 enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26c9 enable: false D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26cd enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26ca enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26cb enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26cc enable: false D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26ce enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26cf enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26d5 enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26d4 enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26d7 enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26d6 enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26d8 enable: true D/BluetoothGatt(14231): setCharacteristicNotification() - uuid: beb5483e-36e1-4688-b7f5-ea07361b26d0 enable: true

And When I power off esp..

Lost connection to device.

Here is my code inside onConnection method: onConnectDevice(int index) { _currentConnectionStream = flutterReactiveBle.connectToAdvertisingDevice( id: foundBleUARTDevices[index].id, prescanDuration: Duration(seconds: 5), withServices: [ _UART_UUID, _CHARACTERISTIC_UUID_SPEED_INTERNAL, _CHARACTERISTIC_UUID_MAX_SPEED, _CHARACTERISTIC_UUID_AVG_SPEED, _CHARACTERISTIC_UUID_TOT_DISTANCE, _CHARACTERISTIC_UUID_RANGE, _CHARACTERISTIC_UUID_DRIVING_RANGE, _CHARACTERISTIC_UUID_PERCENTAGE, _CHARACTERISTIC_UUID_CONTROLLER_CURRENT, _CHARACTERISTIC_UUID_BATTERY_SOH, _CHARACTERISTIC_UUID_BATTERY_TEMPRATURE, _CHARACTERISTIC_UUID_BATTERY_VOLTAGE, _CHARACTERISTIC_UUID_BATTERY_CURRENT, _CHARACTERISTIC_UUID_CONTROLLER_VOLTAGE, _CHARACTERISTIC_UUID_CONTROLLER_TEMPRATURE, _CHARACTERISTIC_UUID_CONTROLLER_MAPPING, _CHARACTERISTIC_UUID_MOTOR_RPM, _CHARACTERISTIC_UUID_MOTOR_TEMPRATURE, _CHARACTERISTIC_UUID_MOTOR_ODO, _CHARACTERISTIC_UUID_CONTROLLER_POWER_TUBE_FAULT, _CHARACTERISTIC_UUID_CONTROLLER_DRIVING_POWER_FAULT, _CHARACTERISTIC_UUID_CONTROLLER_OVER_CURRENT_FAULT, _CHARACTERISTIC_UUID_CONTROLLER_OVER_VOLTAGE_PROTECTION, _CHARACTERISTIC_UUID_CONTROLLER_OVER_TEMPRATURE_PROTECTION, _CHARACTERISTIC_UUID_MOTOR_PHASE_WIRE_FAULT, _CHARACTERISTIC_UUID_MOTOR_HALL_FAULT, _CHARACTERISTIC_UUID_MOTOR_OVER_TEMPRATURE_PROTECTION, _CHARACTERISTIC_UUID_CONTROLLER_UNDER_VOLTAGE_PROTECTION, _CHARACTERISTIC_UUID_MOTOR_STALL_PROTECTION, _CHARACTERISTIC_UUID_THROTTLE_FAULT, _CHARACTERISTIC_UUID_HROTTLE_NOT_RELEASED, _CHARACTERISTIC_UUID_BMS_LOW_VOLTAGE, _CHARACTERISTIC_UUID_BMS_OVER_CURRENT_CHARGE, _CHARACTERISTIC_UUID_BMS_OVER_CURRENT_DISCHARGE, _CHARACTERISTIC_UUID_BMS_OVER_TEMPRATURE_DISCHARGE, _CHARACTERISTIC_UUID_BMS_UNDER_TEMPRATURE_DISCHARGE, _CHARACTERISTIC_UUID_BMS_CELL_OPEN, _CHARACTERISTIC_UUID_BMS_SHORT_DISCHARGE, _CHARACTERISTIC_UUID_BMS_OVER_TEMPRATURE_CHARGE, _CHARACTERISTIC_UUID_BMS_UNDER_TEMPRATURE_CHARGE, _CHARACTERISTIC_UUID_BMS_OVER_TEMPRATURE_MOSFET, _CHARACTERISTIC_UUID_BMS_TEMPRATURE_SENSOR_ERROR, _CHARACTERISTIC_UUID_DRIVING_STATE, _CHARACTERISTIC_UUID_MOTOR_GEARS, _CHARACTERISTIC_UUID_MOTOR_TIERS, _CHARACTERISTIC_UUID_CONTROLLER_THROTTLE, _CHARACTERISTIC_UUID_BMS_STATUS, _CHARACTERISTIC_UUID_VCU_STATUS, _CHARACTERISTIC_UUID_BMS_CHARGING, _CHARACTERISTIC_UUID_BMS_DISCHARGING, _CHARACTERISTIC_UUID_BMS_CHARGE_COMPLETED, ], ); _logTexts = ""; update(); _connection = _currentConnectionStream.listen( (event) { if (event.deviceId == "") return; var id = event.deviceId; switch (event.connectionState) { case DeviceConnectionState.connecting: { utility().connected_snackbar(); _logTexts = "${_logTexts}Connecting to $id\n"; print(_logTexts); break; } case DeviceConnectionState.connected: { _logTexts = "${_logTexts}Connected to $id\n";

          QUALIFIED_CHARACTERISTIC_UUID_DISPLAY = QualifiedCharacteristic(
              serviceId: _UART_UUID,
              characteristicId: _CHARACTERISTIC_UUID_DISPLAY,
              deviceId: event.deviceId);

          _qulaified_CHARACTERISTIC_UUID_SPEED_INTERNAL =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_SPEED_INTERNAL,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_MAX_SPEED =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_MAX_SPEED,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_AVG_SPEED =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_AVG_SPEED,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_TOT_DISTANCE =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_TOT_DISTANCE,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_RANGE = QualifiedCharacteristic(
              serviceId: _UART_UUID,
              characteristicId: _CHARACTERISTIC_UUID_RANGE,
              deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_DRIVING_MODE =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_DRIVING_RANGE,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_DRIVING_STATE =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_DRIVING_STATE,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_PERCENTAGE =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_PERCENTAGE,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_CONTROLLER_CURRENT =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_CONTROLLER_CURRENT,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_BATTERY_SOH =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_BATTERY_SOH,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_BATTERY_TEMPRATURE =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_BATTERY_TEMPRATURE,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_BATTERY_VOLTAGE =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_BATTERY_VOLTAGE,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_BATTERY_CURRENT =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_BATTERY_CURRENT,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_CONTROLLER_VOLTAGE =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_CONTROLLER_VOLTAGE,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_CONTROLLER_TEMPRATURE =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId:
                      _CHARACTERISTIC_UUID_CONTROLLER_TEMPRATURE,
                  deviceId: event.deviceId);

          _QUALIFIED_CHARACTERISTIC_UUID_CONTROLLER_THROTTLE =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId:
                      _CHARACTERISTIC_UUID_CONTROLLER_THROTTLE,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_CONTROLLER_MAPPING =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_CONTROLLER_MAPPING,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_MOTOR_RPM =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_MOTOR_RPM,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_MOTOR_TEMPRATURE =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_MOTOR_TEMPRATURE,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_MOTOR_ODO =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_MOTOR_ODO,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_CONTROLLER_POWER_TUBE_FAULT =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId:
                      _CHARACTERISTIC_UUID_CONTROLLER_POWER_TUBE_FAULT,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_CONTROLLER_DRIVING_POWER_FAULT =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId:
                      _CHARACTERISTIC_UUID_CONTROLLER_DRIVING_POWER_FAULT,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_CONTROLLER_OVER_CURRENT_FAULT =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId:
                      _CHARACTERISTIC_UUID_CONTROLLER_OVER_CURRENT_FAULT,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_CONTROLLER_OVER_VOLTAGE_PROTECTION =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId:
                      _CHARACTERISTIC_UUID_CONTROLLER_OVER_VOLTAGE_PROTECTION,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_CONTROLLER_OVER_TEMPRATURE_PROTECTION =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId:
                      _CHARACTERISTIC_UUID_CONTROLLER_OVER_TEMPRATURE_PROTECTION,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_MOTOR_PHASE_WIRE_FAULT =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId:
                      _CHARACTERISTIC_UUID_MOTOR_PHASE_WIRE_FAULT,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_MOTOR_HALL_FAULT =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_MOTOR_HALL_FAULT,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_MOTOR_OVER_TEMPRATURE_PROTECTION =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId:
                      _CHARACTERISTIC_UUID_MOTOR_OVER_TEMPRATURE_PROTECTION,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_CONTROLLER_UNDER_VOLTAGE_PROTECTION =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId:
                      _CHARACTERISTIC_UUID_CONTROLLER_UNDER_VOLTAGE_PROTECTION,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_MOTOR_STALL_PROTECTION =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId:
                      _CHARACTERISTIC_UUID_MOTOR_STALL_PROTECTION,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_THROTTLE_FAULT =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_THROTTLE_FAULT,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_HROTTLE_NOT_RELEASED =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId:
                      _CHARACTERISTIC_UUID_HROTTLE_NOT_RELEASED,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_BMS_LOW_VOLTAGE =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_BMS_LOW_VOLTAGE,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_BMS_OVER_CURRENT_CHARGE =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId:
                      _CHARACTERISTIC_UUID_BMS_OVER_CURRENT_CHARGE,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_BMS_OVER_CURRENT_DISCHARGE =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId:
                      _CHARACTERISTIC_UUID_BMS_OVER_CURRENT_DISCHARGE,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_BMS_OVER_TEMPRATURE_DISCHARGE =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId:
                      _CHARACTERISTIC_UUID_BMS_OVER_TEMPRATURE_DISCHARGE,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_BMS_UNDER_TEMPRATURE_DISCHARGE =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId:
                      _CHARACTERISTIC_UUID_BMS_UNDER_TEMPRATURE_DISCHARGE,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_BMS_CELL_OPEN =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_BMS_CELL_OPEN,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_BMS_SHORT_DISCHARGE =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId:
                      _CHARACTERISTIC_UUID_BMS_SHORT_DISCHARGE,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_BMS_OVER_TEMPRATURE_CHARGE =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId:
                      _CHARACTERISTIC_UUID_BMS_OVER_TEMPRATURE_CHARGE,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_BMS_UNDER_TEMPRATURE_CHARGE =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId:
                      _CHARACTERISTIC_UUID_BMS_UNDER_TEMPRATURE_CHARGE,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_BMS_OVER_TEMPRATURE_MOSFET =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId:
                      _CHARACTERISTIC_UUID_BMS_OVER_TEMPRATURE_MOSFET,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_BMS_TEMPRATURE_SENSOR_ERROR =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId:
                      _CHARACTERISTIC_UUID_BMS_TEMPRATURE_SENSOR_ERROR,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_WHEEL = QualifiedCharacteristic(
              serviceId: _UART_UUID,
              characteristicId: _CHARACTERISTIC_UUID_MOTOR_TIERS,
              deviceId: event.deviceId);
          ////////////////////
          _QUALIFIED_CHARACTERISTIC_GEAR = QualifiedCharacteristic(
              serviceId: _UART_UUID,
              characteristicId: _CHARACTERISTIC_UUID_MOTOR_TIERS,
              deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_BMS_STATUS =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_BMS_STATUS,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_VCU_STATUS =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_VCU_STATUS,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_BMS_CHARGING =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_BMS_CHARGING,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_BMS_DISCHARGING =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId: _CHARACTERISTIC_UUID_BMS_DISCHARGING,
                  deviceId: event.deviceId);
          _QUALIFIED_CHARACTERISTIC_UUID_BMS_CHARGE_COMPLETED =
              QualifiedCharacteristic(
                  serviceId: _UART_UUID,
                  characteristicId:
                      _CHARACTERISTIC_UUID_BMS_CHARGE_COMPLETED,
                  deviceId: event.deviceId);

          _speedInternal_Stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _qulaified_CHARACTERISTIC_UUID_SPEED_INTERNAL);
          _speedInternal_Stream.listen((data) {
            onReceived_SpeedInternal(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          _maxSpeed_Stream = flutterReactiveBle.subscribeToCharacteristic(
              _QUALIFIED_CHARACTERISTIC_UUID_MAX_SPEED);
          _maxSpeed_Stream.listen((data) {
            onReceived_maxSpeed(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          _avgSpeed_Stream = flutterReactiveBle.subscribeToCharacteristic(
              _QUALIFIED_CHARACTERISTIC_UUID_AVG_SPEED);
          _avgSpeed_Stream.listen((data) {
            onReceived_avgSpeed(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          _totalDistance_Stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_TOT_DISTANCE);
          _totalDistance_Stream.listen((data) {
            onReceived_totalDistance(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          _range_Stream = flutterReactiveBle.subscribeToCharacteristic(
              _QUALIFIED_CHARACTERISTIC_UUID_RANGE);
          _range_Stream.listen((data) {
            onReceived_range(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });

          _driving_mode_Stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_DRIVING_MODE);
          _driving_mode_Stream.listen((data) {
            onReceived_driving_mode(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          _driving_mode_State_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_DRIVING_STATE);
          _driving_mode_State_stream.listen((data) {
            onReceived_driving_state(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          _percentage_internal_Stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_PERCENTAGE);
          _percentage_internal_Stream.listen((data) {
            onReceived_percentage_internal(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          _current_level_Stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_CONTROLLER_CURRENT);
          _current_level_Stream.listen((data) {
            onReceived_current_level(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });

          _battery_state_of_health_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_BATTERY_SOH);
          _battery_state_of_health_stream.listen((data) {
            onReceived_battery_soh(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          _battery_current_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_BATTERY_CURRENT);
          _battery_current_stream.listen((data) {
            onReceived_battery_current(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          _battery_temprature_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_BATTERY_TEMPRATURE);
          _battery_temprature_stream.listen((data) {
            onReceived_battery_temprature(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          _battery_voltage_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_BATTERY_VOLTAGE);
          _battery_voltage_stream.listen((data) {
            onReceived_battery_voltage(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          _controller_voltage_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_CONTROLLER_VOLTAGE);
          _controller_voltage_stream.listen((data) {
            onReceived_controller_voltage(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          _controller_temprature_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_CONTROLLER_TEMPRATURE);
          _controller_temprature_stream.listen((data) {
            onReceived_controller_temprature(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          _controller_throttle_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_CONTROLLER_THROTTLE);
          _controller_throttle_stream.listen((data) {
            onReceived_controller_throttle(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          _controller_mapping_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_CONTROLLER_MAPPING);
          _controller_mapping_stream.listen((data) {
            onReceived_controller_map(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          _motor_revol_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_MOTOR_RPM);
          _motor_revol_stream.listen((data) {
            onReceived_motor_revol(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          _motor_temprature_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_MOTOR_TEMPRATURE);
          _motor_temprature_stream.listen((data) {
            onReceived_motor_temprature(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          _motor_odo_stream = flutterReactiveBle.subscribeToCharacteristic(
              _QUALIFIED_CHARACTERISTIC_UUID_MOTOR_ODO);
          _motor_odo_stream.listen((data) {
            onReceived_motor_odo(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });

          controller_power_tube_fault_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_CONTROLLER_POWER_TUBE_FAULT);
          controller_power_tube_fault_stream.listen((data) {
            onReceived_controller_power_tube_fault(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          controller_driving_power_fault_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_CONTROLLER_DRIVING_POWER_FAULT);
          controller_driving_power_fault_stream.listen((data) {
            onReceived_controller_driving_power_fault(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          controller_over_current_fault_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_CONTROLLER_OVER_CURRENT_FAULT);
          controller_over_current_fault_stream.listen((data) {
            onReceived_controller_over_current_fault(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          controller_over_voltage_protection_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_CONTROLLER_OVER_VOLTAGE_PROTECTION);
          controller_over_voltage_protection_stream.listen((data) {
            onReceived_controller_over_voltage_protection(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          controller_over_temprature_protection_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_CONTROLLER_OVER_TEMPRATURE_PROTECTION);
          controller_over_temprature_protection_stream.listen((data) {
            onReceived_controller_over_temprature_protection(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          motor_phase_wire_fault_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_MOTOR_PHASE_WIRE_FAULT);
          motor_phase_wire_fault_stream.listen((data) {
            onReceived_motor_phase_wire_fault(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          motor_hall_fault_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_MOTOR_HALL_FAULT);
          motor_hall_fault_stream.listen((data) {
            onReceived_motor_hall_fault(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          motor_over_temprature_protection_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_MOTOR_OVER_TEMPRATURE_PROTECTION);
          motor_over_temprature_protection_stream.listen((data) {
            onReceived_motor_over_temprature_protection(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          controller_under_voltage_protection_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_CONTROLLER_UNDER_VOLTAGE_PROTECTION);
          controller_under_voltage_protection_stream.listen((data) {
            onReceived_controller_under_voltage_protection(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          motor_stall_protection_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_MOTOR_STALL_PROTECTION);
          motor_stall_protection_stream.listen((data) {
            onReceived_motor_stall_protection(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          throttle_fault_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_THROTTLE_FAULT);
          throttle_fault_stream.listen((data) {
            onReceived_throttle_fault(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          throttle_not_released_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_HROTTLE_NOT_RELEASED);
          throttle_not_released_stream.listen((data) {
            onReceived_throttle_not_released(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          bms_low_voltage_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_BMS_LOW_VOLTAGE);
          bms_low_voltage_stream.listen((data) {
            onReceived_bms_low_voltage(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          bms_over_current_charge_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_BMS_OVER_CURRENT_CHARGE);
          bms_over_current_charge_stream.listen((data) {
            onReceived_bms_over_current_discharge(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          bms_over_current_discharge_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_BMS_OVER_CURRENT_DISCHARGE);
          bms_over_current_discharge_stream.listen((data) {
            onReceived_motor_odo(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          bms_over_temprature_discharge_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_BMS_OVER_TEMPRATURE_DISCHARGE);
          bms_over_temprature_discharge_stream.listen((data) {
            onReceived_bms_over_temprature_discharge(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          bms_under_temprature_discharge_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_BMS_UNDER_TEMPRATURE_DISCHARGE);
          bms_under_temprature_discharge_stream.listen((data) {
            onReceived_bms_under_temprature_discharge(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          bms_under_temprature_charge_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_BMS_UNDER_TEMPRATURE_CHARGE);
          bms_under_temprature_charge_stream.listen((data) {
            onReceived_bms_under_temprature_charge(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });

          bms_cell_open_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_BMS_CELL_OPEN);
          bms_cell_open_stream.listen((data) {
            onReceived_bms_cell_open(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          bms_short_discharge_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_BMS_SHORT_DISCHARGE);
          bms_short_discharge_stream.listen((data) {
            onReceived_bms_short_discharge(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          bms_over_temprature_charge_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_BMS_OVER_TEMPRATURE_CHARGE);
          bms_over_temprature_charge_stream.listen((data) {
            onReceived_bms_over_temprature_charge(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          bms_under_temprature_charge_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_BMS_UNDER_TEMPRATURE_CHARGE);
          bms_under_temprature_charge_stream.listen((data) {
            onReceived_bms_under_temprature_charge(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          bms_over_temprature_mosfet_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_BMS_OVER_TEMPRATURE_MOSFET);
          bms_over_temprature_mosfet_stream.listen((data) {
            onReceived_bms_over_temprature_mosfet(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          bms_temprature_sensor_error_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_BMS_TEMPRATURE_SENSOR_ERROR);
          bms_temprature_sensor_error_stream.listen((data) {
            onReceived_bms_temprature_sensor_error(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });

          bms_status_stream = flutterReactiveBle.subscribeToCharacteristic(
              _QUALIFIED_CHARACTERISTIC_UUID_BMS_STATUS);
          bms_status_stream.listen((data) {
            onReceived_bms_status(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });

          vcu_status_stream = flutterReactiveBle.subscribeToCharacteristic(
              _QUALIFIED_CHARACTERISTIC_UUID_VCU_STATUS);
          vcu_status_stream.listen((data) {
            onReceived_vcu_status(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });

          bms_charging_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_BMS_CHARGING);
          bms_charging_stream.listen((data) {
            onReceived_bms_charging(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          bms_discharging_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_BMS_DISCHARGING);
          bms_discharging_stream.listen((data) {
            onReceived_bms_discharging(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });

          bms_charge_completed_stream =
              flutterReactiveBle.subscribeToCharacteristic(
                  _QUALIFIED_CHARACTERISTIC_UUID_BMS_CHARGE_COMPLETED);
          bms_charge_completed_stream.listen((data) {
            onReceived_bms_charge_completed(data);
          }, onError: (dynamic error) {
            _logTexts = "${_logTexts}Error:$error$id\n";
          });
          _motor_gear_stream = flutterReactiveBle
              .subscribeToCharacteristic(_QUALIFIED_CHARACTERISTIC_GEAR);
          _motor_gear_stream.listen(
            (data) {
              onReceived_motor_gear(data);
            },
            onError: (dynamic error) {
              _logTexts = "${_logTexts}Error:$error$id\n";
            },
          );

          _motor_wheel_stream = flutterReactiveBle
              .subscribeToCharacteristic(_QUALIFIED_CHARACTERISTIC_WHEEL);
          _motor_wheel_stream.listen(
            (data) {
              onReceived_motor_wheel(data);
            },
            onError: (dynamic error) {
              _logTexts = "${_logTexts}Error:$error$id\n";
            },
          );
          break;
        }

      case DeviceConnectionState.disconnecting:
        {
          connected.value = false;
          _logTexts = "${_logTexts}Disconnecting from $id\n";
          print(_logTexts);
          break;
        }
      case DeviceConnectionState.disconnected:
        {
          utility().disconnected_snackbar();
          _logTexts = "${_logTexts}Disconnected from $id\n";
          print(_logTexts);
          break;
        }
    }
  },
);

}

remonh87 commented 1 year ago

I would recommend to follow:

https://github.com/PhilipsHue/flutter_reactive_ble#faq