BLE connection with IOS is disconnected when call esp_ota_begin()

hyunwoo
Posts: 15
Joined: Tue May 04, 2021 6:54 am

BLE connection with IOS is disconnected when call esp_ota_begin()

Postby hyunwoo » Thu Aug 19, 2021 7:54 am

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

User avatar
WardMas
Posts: 75
Joined: Fri Jun 19, 2020 9:09 am

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

Postby WardMas » Thu Aug 19, 2021 8:50 am

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.
You can always visit my YouTube channel for embedded systems related tutorials
https://youtube.com/user/wardzx1

hyunwoo
Posts: 15
Joined: Tue May 04, 2021 6:54 am

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

Postby hyunwoo » Thu Aug 19, 2021 9:07 am

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?

hyunwoo
Posts: 15
Joined: Tue May 04, 2021 6:54 am

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

Postby hyunwoo » Fri Aug 20, 2021 4:15 am

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.

chegewara
Posts: 2358
Joined: Wed Jun 14, 2017 9:00 pm

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

Postby chegewara » Fri Aug 20, 2021 5:07 am

hyunwoo wrote: Does erasing partition need for OTA update?
Yes, but there is simple solution. In BLE connection there is "timeout" parameter.

hyunwoo
Posts: 15
Joined: Tue May 04, 2021 6:54 am

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

Postby hyunwoo » Fri Aug 20, 2021 6:41 am

@chegewara
Thank you for reply.
Can you tell me more about "timeout"?


hyunwoo
Posts: 15
Joined: Tue May 04, 2021 6:54 am

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

Postby hyunwoo » Thu Sep 02, 2021 3:40 am

Thanks!!!!

Who is online

Users browsing this forum: Bryght-Richard and 76 guests