<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Connecting ESP32 to NRF52833 with exchange ATT MTU. Connected notification but after a while, nrf52833 automatically terminates the connection.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/96948/connecting-esp32-to-nrf52833-with-exchange-att-mtu-connected-notification-but-after-a-while-nrf52833-automatically-terminates-the-connection</link><description>Hi, I am currently working on a project that requires ESP32 as a client and nrf52833 as a server. I use SDK 17.1.0 with softdevice 7.2.0. 
 When I connect to nrf52833 with my smartphone using app nRF connect, the behaviour of nrf52833 is as follow: 
</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 02 Mar 2023 19:13:18 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/96948/connecting-esp32-to-nrf52833-with-exchange-att-mtu-connected-notification-but-after-a-while-nrf52833-automatically-terminates-the-connection" /><item><title>RE: Connecting ESP32 to NRF52833 with exchange ATT MTU. Connected notification but after a while, nrf52833 automatically terminates the connection.</title><link>https://devzone.nordicsemi.com/thread/413114?ContentTypeID=1</link><pubDate>Thu, 02 Mar 2023 19:13:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2ecdaebc-9b85-4fb9-b3cf-2c4ee7896171</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Ok, I look closely at the logs, and I &lt;em&gt;&lt;strong&gt;think&lt;/strong&gt;&lt;/em&gt; the root cause is the nRF device sent a MTU request and did not get a response. Please check how your ESP32 handle MTU requests.&lt;/p&gt;
&lt;p&gt;A sniffer trace would show us for sure whether that is the case. Please look into it if you can. It can be a very helpful thing.&lt;/p&gt;
&lt;p&gt;By the way, this took such a long time because the logic of&amp;nbsp;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;gatt_evt_handler&lt;/span&gt; in main.c is not&amp;nbsp;very good. It is not&amp;nbsp;entirely your fault since it looks like you merely inherit the troublesome code from the ble_app_uart example.&lt;br /&gt;&lt;span style="font-family:inherit;"&gt;Anyway, &lt;/span&gt;&lt;span style="font-family:inherit;"&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;gatt_evt_handler&lt;/span&gt; is supposed to handle both&amp;nbsp;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;NRF_BLE_GATT_EVT_ATT_MTU_UPDATED&lt;/span&gt;&amp;nbsp;and&amp;nbsp;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;NRF_BLE_GATT_EVT_DATA_LENGTH_UPDATED&lt;/span&gt;. However, even for Data Length update, it logs as if it is MTU update, which easily misleads us. I suggest you update the logic to prevent future headaches.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ESP32 to NRF52833 with exchange ATT MTU. Connected notification but after a while, nrf52833 automatically terminates the connection.</title><link>https://devzone.nordicsemi.com/thread/412870?ContentTypeID=1</link><pubDate>Thu, 02 Mar 2023 03:07:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:da83901d-8625-416c-8050-54b3f60e5340</guid><dc:creator>Duc Ha</dc:creator><description>&lt;p&gt;I will figure it out later &amp;#39;cause I dont have any knowledge about it right now but I have tried to connect to another application like ble_app_blinky and it turned out to be just fine. Here is the log including the debug of nRF52832 (NRF52 DK):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;00&amp;gt; &amp;lt;info&amp;gt; app_timer: RTC: initialized.
00&amp;gt; 
00&amp;gt; &amp;lt;info&amp;gt; app: Blinky example started.
00&amp;gt; 
00&amp;gt; &amp;lt;info&amp;gt; app: Connected
00&amp;gt; 
00&amp;gt; &amp;lt;debug&amp;gt; nrf_ble_gatt: Peer on connection 0x0 requested a data length of 251 bytes.
00&amp;gt; 
00&amp;gt; &amp;lt;debug&amp;gt; nrf_ble_gatt: Updating data length to 27 on connection 0x0.
00&amp;gt; 
00&amp;gt; &amp;lt;debug&amp;gt; nrf_ble_gatt: Data length updated to 27 on connection 0x0.
00&amp;gt; 
00&amp;gt; &amp;lt;debug&amp;gt; nrf_ble_gatt: max_rx_octets: 27
00&amp;gt; 
00&amp;gt; &amp;lt;debug&amp;gt; nrf_ble_gatt: max_tx_octets: 27
00&amp;gt; 
00&amp;gt; &amp;lt;debug&amp;gt; nrf_ble_gatt: max_rx_time: 2120
00&amp;gt; 
00&amp;gt; &amp;lt;debug&amp;gt; nrf_ble_gatt: max_tx_time: 2120
00&amp;gt; 
00&amp;gt; &amp;lt;debug&amp;gt; nrf_ble_gatt: Peer on connection 0x0 requested an ATT MTU of 247 bytes.
00&amp;gt; 
00&amp;gt; &amp;lt;debug&amp;gt; nrf_ble_gatt: Updating ATT MTU to 23 bytes (desired: 23) on connection 0x0.&lt;/pre&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;and ESP32:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;I (6137) GATTC_DEMO: f9 e0 0c f5 4a ca
I (6137) GATTC_DEMO: searched Adv Data Len 23, Scan Response Len 18
I (6147) GATTC_DEMO: searched Device Name Len 14
I (6147) GATTC_DEMO: ESP_SPP_SERVER
I (6157) GATTC_DEMO:

I (6157) GATTC_DEMO: searched device ESP_SPP_SERVER

I (6167) GATTC_DEMO: connect to the remote device.
I (6177) GATTC_DEMO: stop scan successfully
I (6277) GATTC_DEMO: ESP_GATTC_CONNECT_EVT conn_id 0, if 1
I (6277) GATTC_DEMO: REMOTE BDA:
I (6277) GATTC_DEMO: f9 e0 0c f5 4a ca
I (6277) GATTC_DEMO: open success
I (6757) GATTC_DEMO: discover service complete conn_id 0
I (6757) GATTC_DEMO: Get service information from remote device
I (6757) GATTC_DEMO: ESP_GATTC_SEARCH_CMPL_EVT
I (6777) GATTC_DEMO: ESP_GATTC_CFG_MTU_EVT, Status 0, MTU 23, conn_id 0
I (26437) GATTC_DEMO: update connection params status = 0, min_int = 80, max_int = 160,conn_int = 160,latency = 0, timeout = 400&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The disconnection didn&amp;#39;t happen anymore. So what do you think? Please let me know.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ESP32 to NRF52833 with exchange ATT MTU. Connected notification but after a while, nrf52833 automatically terminates the connection.</title><link>https://devzone.nordicsemi.com/thread/412837?ContentTypeID=1</link><pubDate>Wed, 01 Mar 2023 19:42:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6f540442-613d-427a-8d99-d8a2f60999e0</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;I don&amp;#39;t have an ESP32 or the understanding of their SDK to reproduce the issue or effectively analyze the ESP32 application. Can you get me a sniffer trace?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ESP32 to NRF52833 with exchange ATT MTU. Connected notification but after a while, nrf52833 automatically terminates the connection.</title><link>https://devzone.nordicsemi.com/thread/412631?ContentTypeID=1</link><pubDate>Wed, 01 Mar 2023 04:14:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6e9b260-a824-48b4-af8e-45b0a8d0b1af</guid><dc:creator>Duc Ha</dc:creator><description>&lt;p&gt;yeah sure =)) I misclicked and I didn&amp;#39;t know how to recover it to 0.&lt;/p&gt;
&lt;p&gt;I assume that the last called function of nrf52 was&amp;nbsp;&lt;pre class="ui-code" data-mode="text"&gt;err_code = sd_ble_gatts_exchange_mtu_reply(conn_handle, p_link-&amp;gt;att_mtu_desired);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;err_code was seemed to be NRF_SUCCESS &amp;#39;cause it didn&amp;#39;t return error:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    if (err_code != NRF_SUCCESS)
    {
        NRF_LOG_ERROR(&amp;quot;sd_ble_gatts_exchange_mtu_reply() returned %s.&amp;quot;, nrf_strerror_get(err_code));
    }&lt;/pre&gt;However, I think it came to this situation:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    // If an ATT_MTU exchange was requested to the peer, defer sending
    // the data length update request and the event to the application until
    // the response for that request is received.
    if (p_link-&amp;gt;att_mtu_exchange_requested)
    {
        return;
    }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I attach the source files of both nrf52 and ESP32. I used Espressif IDE for ESP32 and just ran a basic GATT_client example to connect to nrf52. Please let me know what you think. Thank you!&lt;/p&gt;
&lt;p&gt;nRF52 source: s140, pca10100, SDK 17.1.0, Softdevice 7.2.0, based on ble_app_uart&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/Firm_5F00_no_5F00_fota_5F00_cus_5F00_serv_5F00_send_5F00_file.rar"&gt;devzone.nordicsemi.com/.../Firm_5F00_no_5F00_fota_5F00_cus_5F00_serv_5F00_send_5F00_file.rar&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;ESP32 source: Espressif v5.0, gatt_client example&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/gatt_5F00_client.rar"&gt;devzone.nordicsemi.com/.../gatt_5F00_client.rar&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ESP32 to NRF52833 with exchange ATT MTU. Connected notification but after a while, nrf52833 automatically terminates the connection.</title><link>https://devzone.nordicsemi.com/thread/412617?ContentTypeID=1</link><pubDate>Tue, 28 Feb 2023 23:27:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:40bddc82-df7c-4614-b6f1-b526b51c80e0</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi Duc,&lt;/p&gt;
&lt;p&gt;My colleague Sigurd explained this event in another DevZone case:&lt;/p&gt;
[quote userid="15146" url="~/f/nordic-q-a/44842/ble_gattc_evt_timeout-event-on-the-server/176669"]The&amp;nbsp;BLE_GATTC_EVT_TIMEOUT is issued when a GATT procedure, i.e. writing or reading an Attribute times out. It could also be that the ESP32 does not repsond to a ATT MTU exchange. See this &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s112.api.v5.1.0/group___b_l_e___g_a_t_t_c___t_i_m_e_o_u_t___m_s_c.html?cp=2_3_0_1_2_2_2_3_14"&gt;MSC&lt;/a&gt;.[/quote]
&lt;p&gt;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s140.api.v7.2.0%2Fgroup___b_l_e___g_a_t_t_c___t_i_m_e_o_u_t___m_s_c.html"&gt;Here&lt;/a&gt;&amp;nbsp;is the Message Sequence Chart for S140 v7.2.0, which you are probably using. It is the exact same anyway.&lt;/p&gt;
&lt;p&gt;It is likely that the nRF device sends some GATT requests to the ESP32 device, which is the ESP32 firmware isn&amp;#39;t setup to serve.&lt;/p&gt;
&lt;p&gt;You should look closely at what happen before the disconnection. What functions did the nRFapplication call? See if there are any GATT requests that your ESP32 application is not handling correctly.&lt;/p&gt;
&lt;p&gt;If tracing the code is not fruitful, you might also want to look into a sniffer trace. Either&amp;nbsp;the &lt;a href="https://infocenter.nordicsemi.com/topic/ug_sniffer_ble/UG/sniffer_ble/intro.html"&gt;nRF Sniffer&lt;/a&gt; and or&amp;nbsp;Ellisys sniffer trace should work. You can examine it yourself or&amp;nbsp;attach it here and I can take a look.&lt;/p&gt;
&lt;p&gt;By the way, you probably didn&amp;#39;t mean to downvote yourself with your previous reply?&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ESP32 to NRF52833 with exchange ATT MTU. Connected notification but after a while, nrf52833 automatically terminates the connection.</title><link>https://devzone.nordicsemi.com/thread/412135?ContentTypeID=1</link><pubDate>Mon, 27 Feb 2023 02:45:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d0689e2d-6fe3-46eb-996d-c90b27fc96a8</guid><dc:creator>Duc Ha</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/vthieu"&gt;Hieu&lt;/a&gt;&amp;nbsp; It gets the&amp;nbsp;BLE_GATTC_EVT_TIMEOUT event of ble_evt_handler. So what is this about and how can I fix this. Thank you!&lt;/p&gt;
&lt;p&gt;Duc&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ESP32 to NRF52833 with exchange ATT MTU. Connected notification but after a while, nrf52833 automatically terminates the connection.</title><link>https://devzone.nordicsemi.com/thread/411803?ContentTypeID=1</link><pubDate>Fri, 24 Feb 2023 01:08:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:afbaa027-7a1f-46a8-95bf-18c6bca86797</guid><dc:creator>Duc Ha</dc:creator><description>&lt;p&gt;Thank you, I will see what I can do and reply to you as soon as possible&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ESP32 to NRF52833 with exchange ATT MTU. Connected notification but after a while, nrf52833 automatically terminates the connection.</title><link>https://devzone.nordicsemi.com/thread/411722?ContentTypeID=1</link><pubDate>Thu, 23 Feb 2023 15:41:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:50ac9d0f-d5b1-4720-bd85-da3d72ccfb09</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;P.s, when you upload your log or code, please use the Insert&amp;gt;Code feature of DevZone.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1677166899005v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ESP32 to NRF52833 with exchange ATT MTU. Connected notification but after a while, nrf52833 automatically terminates the connection.</title><link>https://devzone.nordicsemi.com/thread/411721?ContentTypeID=1</link><pubDate>Thu, 23 Feb 2023 15:39:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cbe50bff-8e31-485e-892a-09baa8925c6c</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Sorry, I misread your log and thought that data length was not updated. I see now that it has been updated to 251.&lt;/p&gt;
&lt;p&gt;I think you already know this, but please keep in mind that Data Length and ATT MTU are two different things.&lt;/p&gt;
&lt;p&gt;One of the most common reasons for disconnection&amp;nbsp;after a few seconds is that some connection parameter negotiations were not successful, and one device essentially decide that without agreement on that parameter, it cannot support the connection, and disconnect.&lt;/p&gt;
&lt;p&gt;There are two approaches we could take here:&lt;/p&gt;
&lt;p&gt;1. You can set a breakpoint before all calls to&amp;nbsp;sd_ble_gap_disconnect() in the nRF device, and see at which point the disconnection happens.&lt;/p&gt;
&lt;p&gt;2. In your SoftDevice event handler, usually named&amp;nbsp;ble_evt_handler in examples, you can&amp;nbsp;log&amp;nbsp;p_ble_evt-&amp;gt;header.evt_id. Then we can focus in the events before disconnection happens.&lt;/p&gt;
&lt;p&gt;If you could, and if the issue is not clear after you try one, please try both, and let me know the result.&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ESP32 to NRF52833 with exchange ATT MTU. Connected notification but after a while, nrf52833 automatically terminates the connection.</title><link>https://devzone.nordicsemi.com/thread/411703?ContentTypeID=1</link><pubDate>Thu, 23 Feb 2023 14:55:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:07bab7d4-505e-42d6-8055-43067026a2d7</guid><dc:creator>Duc Ha</dc:creator><description>&lt;p&gt;In this situation, It seems that ESP32 has requested ATT MTU with GATTC_CFG_MTU_EVT and the nrf52833 received the request and updating ATT MTU but I dont get the part that it automatically terminated the connection. Please help me out.&lt;/p&gt;
&lt;p&gt;Duc&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ESP32 to NRF52833 with exchange ATT MTU. Connected notification but after a while, nrf52833 automatically terminates the connection.</title><link>https://devzone.nordicsemi.com/thread/411698?ContentTypeID=1</link><pubDate>Thu, 23 Feb 2023 14:38:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:22d643d7-e26a-4a40-8f79-0efcd54c8fc7</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi Duc,&lt;/p&gt;
&lt;p&gt;How does your ESP32 handle the request for data length update? That is not reflected in the log you shared here.&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>