espressif / esp-idf-provisioning-android

Android Provisioning application for ESP-IDF Unified provisioning
Apache License 2.0
194 stars 129 forks source link

Write to BLE failed #51

Open tobyloki opened 2 years ago

tobyloki commented 2 years ago

My BLE provisioning flow is as follows:

  1. I start the provisioning process by scanning for BLE devices.
  2. I connect to the device.
  3. I make a request via provisionManager.getEspDevice().sendDataToCustomEndPoint and get back some data from the device.
  4. Then I connect to a Wifi network and provision.

Here's my test case:

  1. I run the provisioning flow listed above once with an incorrect WiFi password.
  2. The provisioning fails and the ESP32 automatically resets, and I restart the provisioning flow again.
  3. On the second run-through of the provisioning flow I get the below error on step 3.
2021-08-07 21:01:44.132 29608-29627/com.test W/System.err: java.lang.Exception: Write to BLE failed
2021-08-07 21:01:44.133 29608-29627/com.test W/System.err:     at com.espressif.provisioning.transport.BLETransport$1.onCharacteristicWrite(BLETransport.java:354)
2021-08-07 21:01:44.134 29608-29627/com.test W/System.err:     at android.bluetooth.BluetoothGatt$1$7.run(BluetoothGatt.java:473)
2021-08-07 21:01:44.134 29608-29627/com.test W/System.err:     at android.bluetooth.BluetoothGatt.runOrQueueCallback(BluetoothGatt.java:860)
2021-08-07 21:01:44.135 29608-29627/com.test W/System.err:     at android.bluetooth.BluetoothGatt.access$200(BluetoothGatt.java:45)
2021-08-07 21:01:44.135 29608-29627/com.test W/System.err:     at android.bluetooth.BluetoothGatt$1.onCharacteristicWrite(BluetoothGatt.java:468)
2021-08-07 21:01:44.136 29608-29627/com.test W/System.err:     at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:265)
2021-08-07 21:01:44.138 29608-29627/com.test W/System.err:     at android.os.Binder.execTransactInternal(Binder.java:1021)
2021-08-07 21:01:44.139 29608-29627/com.test W/System.err:     at android.os.Binder.execTransact(Binder.java:994)
2021-08-07 21:01:44.140 29608-29608/com.test W/System.err: java.lang.Exception: Write to BLE failed
2021-08-07 21:01:44.141 29608-29608/com.test W/System.err:     at com.espressif.provisioning.transport.BLETransport$1.onCharacteristicWrite(BLETransport.java:354)
2021-08-07 21:01:44.141 29608-29608/com.test W/System.err:     at android.bluetooth.BluetoothGatt$1$7.run(BluetoothGatt.java:473)
2021-08-07 21:01:44.142 29608-29608/com.test W/System.err:     at android.bluetooth.BluetoothGatt.runOrQueueCallback(BluetoothGatt.java:860)
2021-08-07 21:01:44.143 29608-29608/com.test W/System.err:     at android.bluetooth.BluetoothGatt.access$200(BluetoothGatt.java:45)
2021-08-07 21:01:44.144 29608-29608/com.test W/System.err:     at android.bluetooth.BluetoothGatt$1.onCharacteristicWrite(BluetoothGatt.java:468)
2021-08-07 21:01:44.144 29608-29608/com.test W/System.err:     at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:265)
2021-08-07 21:01:44.145 29608-29608/com.test W/System.err:     at android.os.Binder.execTransactInternal(Binder.java:1021)
2021-08-07 21:01:44.145 29608-29608/com.test W/System.err:     at android.os.Binder.execTransact(Binder.java:994)
2021-08-07 21:01:44.145 29608-29608/com.test I/BLELandingViewModel: Write to BLE failed
2021-08-07 21:01:44.167 29608-29974/com.test W/libEGL: EGLNativeWindowType 0x71767b7d10 disconnect failed
2021-08-07 21:01:44.207 29608-29608/com.test I/MultiWindowDecorSupport: updateCaptionType >> DecorView@f010a[], isFloating: true, isApplication: true, hasWindowDecorCaption: false, hasWindowControllerCallback: false

I am using implementation 'com.github.espressif:esp-idf-provisioning-android:lib-2.0.9' in my applications gradle file.

Why does this error occur and how can I fix it? I also tried rescanning for BLE networks again, and it then returned 0 devices. I'm not sure why it returned 1 device on the first scan and then 0 on the second.

KhushbuShah25 commented 2 years ago

Hi @tobyloki , thanks for reporting the issue. Will check this.

tobyloki commented 2 years ago

@khushbushah2302 Hi. Have you found a solution to this problem?

KhushbuShah25 commented 2 years ago

Hi @tobyloki , I am working on this issue.

tobyloki commented 2 years ago

@khushbushah2302 After investigating further, I've found that the source of the problem is provisionManager.getEspDevice().sendDataToCustomEndPoint. It seems to work fine on the first invocation. But when I call it a second time, it gives me the error. Could you verify if this is true on your end?


final String data = "asdf";
provisionManager.getEspDevice().sendDataToCustomEndPoint("custom-data", data.getBytes(), new ResponseListener() {
   ...
});
KhushbuShah25 commented 2 years ago

Hi @tobyloki , In provisionManager.getEspDevice().sendDataToCustomEndPoint, first argument is device endpoint name.
You have sent "custom-data" instead of endpoint. Have you used actual endpoint value or data in first argument ? App will try to find BLE Characteristic whose descriptor value is this endpoint ("custom-data" in your case). App will give error if it is unable to find Characteristic with the given descriptor value. We are using this same API in ESP RainMaker project.

tobyloki commented 2 years ago

@khushbushah2302 In my ESP32's code, I had configured the endpoint as "custom-data". So I think what I've done should be correct.

wifi_prov_mgr_endpoint_create("custom-data");
/* Start provisioning service */
ESP_ERROR_CHECK(wifi_prov_mgr_start_provisioning(security, pop, service_name, service_key));

/* The handler for the optional endpoint created above.
 * This call must be made after starting the provisioning, and only if the endpoint
 * has already been created above.
 */
wifi_prov_mgr_endpoint_register("custom-data", custom_prov_data_handler, NULL);
FabianTerhorst commented 1 year ago

@tobyloki You still have the issue or you got it resolved? I have the same issue now.

cliut commented 1 year ago

@tobyloki You still have the issue? I have the same issue now.

FabianTerhorst commented 1 year ago

@tobyloki You still have the issue? I have the same issue now.

One fix is to switch to security0.

cliut commented 1 year ago

@tobyloki You still have the issue? I have the same issue now.

One fix is to switch to security0.

Already built the firmware and ios app using security1. So want to keep using security1. Is there any way to fix this in security1?

d-rahul commented 7 months ago

I am also facing issues related to Security1 but it looks like the Espressif team is not interested in working on the provisioning library... @KhushbuShah25 "I am working on this issue." still are you working? How long it will take...

valientegaston commented 2 weeks ago

Same issue here with security 2. Any clue? Thanks