Page 1 of 1

BLE connection with IOS is disconnected when call esp_ota_begin()

Posted: Thu Aug 19, 2021 7:54 am
by hyunwoo
Hi.

I wrote source code for OAT update via BLE. We use react-native for Update application.

In GAP, ESP32 - peripheral, Phone(Application) - central
In GATT, ESP32- GATTS, Phone - GATTC

Here is sequence of OAT Update.
1. Connect Bluetooth on GAP.
2. Enable notify on ESP32. (Write 0x0001) <- Here
3. ESP32 ready to OTA Update(etc. call esp_ota_begin())
4. Notify it to Phone when ready for OTA update.
5. Phone write(without response) OTA data.
6. ...

Problem
In android, it working good.

But in IOS, the connection is always disconnected when enable notify (2.).
Actually, disconnected when call `esp_ota_begin()` function.
Can you help me?

Write callback for Notify

Code: Select all

case 0x0001:
                    EPS_LOGI(TAG, "Start Notification & OTA Update Request");

                    err = ota_init();
                    if (err == ESP_OK)
                    {
                        memcpy(value, "OK", sizeof(value));
                    }
                    else
                    {
                        memcpy(value, "NO", sizeof(value));
                    }
                    esp_ble_gatts_send_indicate(gatts_service_list_array[OTA_APP_ID].gatts_if,
                                                param->conn_id,
                                                gatts_service_list_array[OTA_APP_ID].characteristic[1].handle,
                                                sizeof(value),
                                                value,
                                                false);
                    ESP_LOGD(TAG, "Sent notification");
                    break;
OTA Start Part

Code: Select all

 esp_partition_iterator_t partition_iterator = esp_partition_find(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_0, "ota_0");
 partition = esp_partition_get(partition_iterator);

 ESP_LOGI(TAG, "label: %s, address = 0x%08X, size = 0x%08X, type = %d, subtype = %d, chip_id = 0x%08X, size = 0x%08X",
                partition->label,
                partition->address,
                partition->size,
                partition->subtype,
                partition->type,
                partition->flash_chip->chip_id,
                partition->flash_chip->size);

// Disconnect In Here!
esp_ota_begin(partition, OTA_PARTITION_SIZE, &ota_handle);

Re: BLE connection with IOS is disconnected when call esp_ota_begin()

Posted: Thu Aug 19, 2021 8:50 am
by WardMas
Hi,
I am curious why you are using (write without response). This is not safe for date reception at ESP32 server characteristic side. I recommend to change the characteristic attribution in the ESP32 and choose write with response at the smartphone side.

Re: BLE connection with IOS is disconnected when call esp_ota_begin()

Posted: Thu Aug 19, 2021 9:07 am
by hyunwoo
Thank you for reply.
As you told, it was so fast in application, so ESP32 skips some OTA data.
Then we using in write(with response) in our app now. That was my misunderstanding.

Back to main topic, when I called `esp_ota_begin()`, the connection with IPhone is broken. (IPhone only)

How can I solve this problem?

Re: BLE connection with IOS is disconnected when call esp_ota_begin()

Posted: Fri Aug 20, 2021 4:15 am
by hyunwoo
I found erasing partition is cause of disconnection.

And the question is changed.
Does erasing partition need for OTA update?
Just overwriting partition make some errors?

Partition header(metadata?) contains information of size, so it isn't that critical.

Re: BLE connection with IOS is disconnected when call esp_ota_begin()

Posted: Fri Aug 20, 2021 5:07 am
by chegewara
hyunwoo wrote: Does erasing partition need for OTA update?
Yes, but there is simple solution. In BLE connection there is "timeout" parameter.

Re: BLE connection with IOS is disconnected when call esp_ota_begin()

Posted: Fri Aug 20, 2021 6:41 am
by hyunwoo
@chegewara
Thank you for reply.
Can you tell me more about "timeout"?

Re: BLE connection with IOS is disconnected when call esp_ota_begin()

Posted: Fri Aug 20, 2021 10:17 am
by chegewara

Re: BLE connection with IOS is disconnected when call esp_ota_begin()

Posted: Thu Sep 02, 2021 3:40 am
by hyunwoo
Thanks!!!!