orbital-systems / react-native-esp-idf-provisioning

ESP IDF provisioning and custom data library for react-native
MIT License
24 stars 5 forks source link

scanWifiList never succeed if proofOfPossession is used #35

Closed tri-bao closed 7 months ago

tri-bao commented 8 months ago

Our app follows the example app. searchESPDevices works, we can see list of devices.

On a found device, we call await espDevice.connect(proofOfPossession);

Then call await device.scanWifiList(); This always fails with message Failed to create session.

Logcat show onCharacteristicWrite, status : 4 And stack trace

java.lang.Exception: Write to BLE failed
at com.espressif.provisioning.transport.BLETransport$1.onCharacteristicWrite(BLETransport.java:377)
at android.bluetooth.BluetoothGatt$1$7.run(BluetoothGatt.java:562)
at android.bluetooth.BluetoothGatt.runOrQueueCallback(BluetoothGatt.java:959)
at android.bluetooth.BluetoothGatt.-$$Nest$mrunOrQueueCallback(Unknown Source:0)
at android.bluetooth.BluetoothGatt$1.onCharacteristicWrite(BluetoothGatt.java:557)
at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:279)
at android.os.Binder.execTransactInternal(Binder.java:1351)
at android.os.Binder.execTransact(Binder.java:1310)

I found that the android native property ESPDevice.proofOfPossession is always an empty string which make it unable to create BLE session with the device, hence the error above.

The reason is:

I made a patch and it seems to work for my case. Not know if there is any other cases. I don't check the property android.bluetooth.BluetoothDevice.uuids because it always null in my case: the bluetooth device is not null by its uuids is null. fix_proofOfPossession_is_never_set_patch.txt

fazal26 commented 7 months ago

Facing the same issue. I updated the package to latest build 0.2.13, and using a test string as a proof of possession, and getting "Failed to create session."

mateogianolio commented 7 months ago

Hey! I got the same issue on 0.2.12 when testing yesterday (however my error was onCharacteristicWrite, status : 133). But it worked after applying #36. Did you rebuild the app after updating the package? Our device uses proof of possession.

Note that it may be related to #46. Before I have time to patch it, you need to make sure the device and the app use the same security setting (secure1 for just POP, secure2 for POP + username). Otherwise you will get "Failed to create session", because the esp-provisioning-android library does not check if the security setting matches until after connection is established and you try scanning for wifi.

fazal26 commented 7 months ago

@mateogianolio thanks for reaching out, I've given the app following permissions: `

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission
    android:name="android.permission.NEARBY_WIFI_DEVICES"
    android:usesPermissionFlags="neverForLocation" />

Plus I'm using the following configuration prior to device connection: const prefix = 'PROV_'; const transport = ESPTransport.ble; const security = ESPSecurity.secure; and while connecting I'm using a simple string as a pop: device .connect('pop123456') ` All the permissions are granted, the device scanning is working, device gets connected but on wifi scan call it fails, I've updated the package to 0.2.13 and still getting this.

    any help much appreciated thanks.

Screenshot 2024-01-25 at 4 05 19 PM

fazal26 commented 7 months ago

And when I try to provision the device by manually passing ssid and password (bypassing the wifi scan function) i get the same error.

mateogianolio commented 7 months ago

Maybe stupid question: Have you configured your proof of possession string pop123456 on your ESP device?

fazal26 commented 7 months ago

I am not sure if our device has a POP configuration, thats why i tried with no value and unsecure security value as well.

x3beche commented 1 month ago

Make sure that you did correct configurations on esp side for security version 1: image