OZEO-DOOZ / nrf_mesh_plugin

A Flutter plugin to enable mesh network management and communication using Nordic Semiconductor's SDKs.
https://pub.dev/packages/nordic_nrf_mesh
BSD 3-Clause "New" or "Revised" License
28 stars 19 forks source link

Local 'provisionedMeshNode' has not been initialized #262

Closed thiszhong closed 1 year ago

thiszhong commented 1 year ago

Hello, I have a problem when provisionning...

flutter: 3.3.5 nordic_nrf_mesh: 0.13.0 phone: android

The code:

Future<void> provisionDevice(DiscoveredDevice device) async {
    if (isScanning) {
      await _stopScan();
    }
    if (isProvisioning) {
      return;
    }
    isProvisioning = true;

    String deviceUUID;
    if (Platform.isAndroid) {
      deviceUUID = list.firstWhere((e) => e.id == device.id).uuid;
    } else if (Platform.isIOS) {
      deviceUUID = device.id.toString();
    } else {
      throw UnimplementedError('device uuid on platform : ${Platform.operatingSystem}');
    }
    debugPrint('------deviceUUID:$deviceUUID');
    final provisioningEvent = ProvisioningEvent();
    await nordicNrfMesh
        .provisioning(
          _meshManagerApi,
          BleMeshManager(),
          device,
          deviceUUID,
          events: provisioningEvent,
        )
        .timeout(const Duration(minutes: 1));
  }

The log:

D/BluetoothAdapter(24421): isLeEnabled(): ON
I/flutter (24421): ------deviceUUID:4c696768-742d-4231-4443-37320f0f0f0f
I/flutter (24421): [NordicNrfMesh] calling disconnect without connected device..
D/BluetoothGatt(24421): connect() - device: 70:3E:97:B1:DC:72, auto: false, eattSupport: false
D/BluetoothGatt(24421): registerApp()
D/BluetoothGatt(24421): registerApp() - UUID=ee9d2f14-6a14-4b32-85ce-7fa0b70b3286
D/BluetoothGatt(24421): onClientRegistered() - status=0 clientIf=10
I/flutter (24421): [NordicNrfMesh] received unexpected connection state update : ConnectionStateUpdate(deviceId: 70:3E:97:B1:DC:72, connectionState: DeviceConnectionState.connecting, failure: null)
D/BluetoothGatt(24421): onClientConnectionState() - status=0 clientIf=10 device=70:3E:97:B1:DC:72
I/flutter (24421): [NordicNrfMesh] received ConnectionStateUpdate(deviceId: 70:3E:97:B1:DC:72, connectionState: DeviceConnectionState.connected, failure: null)
D/BluetoothGatt(24421): discoverServices() - device: 70:3E:97:B1:DC:72
D/BluetoothGatt(24421): onConnectionUpdated() - Device=70:3E:97:B1:DC:72 interval=6 latency=0 timeout=500 status=0
D/BluetoothGatt(24421): onPhyUpdate() - status=0 address=70:3E:97:B1:DC:72 txPhy=2 rxPhy=2
D/BluetoothGatt(24421): onSearchComplete() = Device=70:3E:97:B1:DC:72 Status=0
I/flutter (24421): [NordicNrfMesh] services [DiscoveredService(serviceId: 00001801-0000-1000-8000-00805f9b34fb, characteristicIds: [00002a05-0000-1000-8000-00805f9b34fb], characteristics: [DiscoveredCharacteristic(characteristicId: 00002a05-0000-1000-8000-00805f9b34fb, serviceId: 00001801-0000-1000-8000-00805f9b34fb)], includedServices: []), DiscoveredService(serviceId: 00001800-0000-1000-8000-00805f9b34fb, characteristicIds: [00002a00-0000-1000-8000-00805f9b34fb, 00002a01-0000-1000-8000-00805f9b34fb, 00002a04-0000-1000-8000-00805f9b34fb, 00002aa6-0000-1000-8000-00805f9b34fb], characteristics: [DiscoveredCharacteristic(characteristicId: 00002a00-0000-1000-8000-00805f9b34fb, serviceId: 00001800-0000-1000-8000-00805f9b34fb), DiscoveredCharacteristic(characteristicId: 00002a01-0000-1000-8000-00805f9b34fb, serviceId: 00001800-0000-1000-8000-00805f9b34fb), DiscoveredCharacteristic(characteristicId: 00002a04-0000-1000-8000-00805f9b34fb, serviceId: 00001800-0000-1000-8000-00805f9b34fb), DiscoveredCharacteristic(characteristicId: 0000
D/BluetoothGatt(24421): configureMTU() - device: 70:3E:97:B1:DC:72 mtu: 517
D/BluetoothGatt(24421): onConnectionUpdated() - Device=70:3E:97:B1:DC:72 interval=24 latency=0 timeout=500 status=0
D/BluetoothGatt(24421): onConfigureMTU() - Device=70:3E:97:B1:DC:72 mtu=247 status=0
I/flutter (24421): [NordicNrfMesh] connect took 1780ms
D/fr.dooz.nordic_nrf_mesh.DoozMeshProvisioningStatusCallbacks(24421): onProvisioningStateChanged 4c696768-742d-4231-4443-37320f0f0f0f
D/fr.dooz.nordic_nrf_mesh.DoozMeshProvisioningStatusCallbacks(24421): meshNodeAlreadySaved false
D/fr.dooz.nordic_nrf_mesh.DoozMeshManagerCallbacks(24421): getMtu 244
D/fr.dooz.nordic_nrf_mesh.DoozMeshManagerCallbacks(24421): sendProvisioningPdu
D/BluetoothGatt(24421): setCharacteristicNotification() - uuid: 00002ade-0000-1000-8000-00805f9b34fb enable: true
E/flutter (24421): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: LateInitializationError: Local 'provisionedMeshNode' has not been initialized.
E/flutter (24421): #0      LateError._throwLocalNotInitialized (dart:_internal-patch/internal_patch.dart:199:5)
E/flutter (24421): #1      _provisioning.<anonymous closure>
package:nordic_nrf_mesh/…/utils/provisioning.dart:191
E/flutter (24421): #2      _RootZone.runUnaryGuarded (dart:async/zone.dart:1586:10)
E/flutter (24421): #3      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (24421): #4      _DelayedData.perform (dart:async/stream_impl.dart:515:14)
E/flutter (24421): #5      _PendingEvents.handleNext (dart:async/stream_impl.dart:620:11)
E/flutter (24421): #6      _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:591:7)
E/flutter (24421): #7      _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
E/flutter (24421): #8      _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
E/flutter (24421):
V/MeshManagerApi(24421): Provisioning pdu sent: 0x030005
ghost commented 1 year ago

Hello @thiszhong Thanks for the report.

Is that a bug you have at each try or ? Also could you provide more information about your devices characteristics (both phone and mesh node)?

thiszhong commented 1 year ago

Hello @R0m4in-dooz

Phone: Xiaomi 12, Android 13 (API 33). Sorry about mesh node, I don't know much about hardware. But hardware manufacturer's native demo app run ok.

I have tried the example, got same result. Abort at: https://github.com/OZEO-DOOZ/nrf_mesh_plugin/blob/3102f2b08d53fcac0cb740ffaa6008b460b435f7/lib/src/utils/provisioning.dart#L191

It seems like the listener was not executed: https://github.com/OZEO-DOOZ/nrf_mesh_plugin/blob/3102f2b08d53fcac0cb740ffaa6008b460b435f7/lib/src/utils/provisioning.dart#L106