Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scanWifiList never succeed if proofOfPossession is used #35

Closed
tri-bao opened this issue Jan 1, 2024 · 7 comments · Fixed by #36
Closed

scanWifiList never succeed if proofOfPossession is used #35

tri-bao opened this issue Jan 1, 2024 · 7 comments · Fixed by #36

Comments

@tri-bao
Copy link

tri-bao commented Jan 1, 2024

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:

  • in method onPeripheralFound, whenever a device is found (via searchESPDevices), it is added to the espDevices cache. But it that time, there is no PoP, thus no thing is set. Here is the line.
  • then in method createESPDevice, if the device exist in the espDevices cache, it returns immediately without filling the Pop. And the result is that PoP is never used.

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

mateogianolio added a commit that referenced this issue Jan 23, 2024
* fix(#35): apply patch from issue to fix scanWifiList issue

* fix(ios): fix parameter name typo

* fix(android,ios): more typo fixes

* fix(android): add check if already connected

* fix(android): cleanup unused params
@fazal26
Copy link

fazal26 commented Jan 24, 2024

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
Copy link
Member

mateogianolio commented Jan 24, 2024

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
Copy link

fazal26 commented Jan 25, 2024

@mateogianolio thanks for reaching out, I've given the app following permissions:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.BLUETOOTH"/> <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
Copy link

fazal26 commented Jan 25, 2024

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
Copy link
Member

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

@fazal26
Copy link

fazal26 commented Jan 25, 2024

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
Copy link

x3beche commented Jul 22, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants