esp-idf-provisioning-android icon indicating copy to clipboard operation
esp-idf-provisioning-android copied to clipboard

Write to BLE failed

Open tobyloki opened this issue 3 years ago • 12 comments

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.

tobyloki avatar Aug 08 '21 04:08 tobyloki

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

KhushbuShah25 avatar Aug 10 '21 05:08 KhushbuShah25

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

tobyloki avatar Aug 17 '21 00:08 tobyloki

Hi @tobyloki , I am working on this issue.

KhushbuShah25 avatar Aug 18 '21 07:08 KhushbuShah25

@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() {
   ...
});

tobyloki avatar Aug 26 '21 00:08 tobyloki

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.

KhushbuShah25 avatar Aug 26 '21 12:08 KhushbuShah25

@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);

tobyloki avatar Aug 26 '21 19:08 tobyloki

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

FabianTerhorst avatar Feb 01 '23 14:02 FabianTerhorst

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

cliut avatar Feb 05 '23 15:02 cliut

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

One fix is to switch to security0.

FabianTerhorst avatar Feb 05 '23 15:02 FabianTerhorst

@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?

cliut avatar Feb 05 '23 15:02 cliut

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...

d-rahul avatar Dec 01 '23 05:12 d-rahul