<?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>Read BLE characteristic with nRF52840-DK and pc-ble-driver</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/78418/read-ble-characteristic-with-nrf52840-dk-and-pc-ble-driver</link><description>For my project in development I need to read characteristics from BLE devices using pc-ble-driver library. 
 I am using a C program, not python bindings. 
 The method I am using is sd_ble_gattc_read passing the characteristic&amp;#39;s handle_value got from sd_ble_gattc_characteristics_discover</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 11 Aug 2021 12:44:41 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/78418/read-ble-characteristic-with-nrf52840-dk-and-pc-ble-driver" /><item><title>RE: Read BLE characteristic with nRF52840-DK and pc-ble-driver</title><link>https://devzone.nordicsemi.com/thread/324482?ContentTypeID=1</link><pubDate>Wed, 11 Aug 2021 12:44:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:108bd33c-fafb-41b8-bcba-65b558b2701e</guid><dc:creator>cheip</dc:creator><description>&lt;p&gt;Solved my issue.&lt;/p&gt;
&lt;p&gt;If you look at my code above, I use a result variable of convenience to store the result of the event.&lt;/p&gt;
&lt;p&gt;If I access&amp;nbsp;the data without that variable, I get the right values.&lt;/p&gt;
&lt;p&gt;Can you please explain that?&lt;/p&gt;
&lt;p&gt;In any case, treat this ticket as solved.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Read BLE characteristic with nRF52840-DK and pc-ble-driver</title><link>https://devzone.nordicsemi.com/thread/324464?ContentTypeID=1</link><pubDate>Wed, 11 Aug 2021 12:00:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a3ef450f-bf7e-43c4-97a8-070f0baeb7d6</guid><dc:creator>cheip</dc:creator><description>&lt;p&gt;I receive corrupted data in&amp;nbsp;ble_gattc_evt_read_rsp_t.data.&lt;/p&gt;
&lt;p&gt;I am not complaining about the length of the data. I can retrieve all 32 bytes of the characteristic value in one way or another, but the bytes are always wrong and different by read to read.&lt;/p&gt;
&lt;p&gt;However, how can I change the default ATT_MTU value?&lt;/p&gt;
&lt;p&gt;One more detail: if I read the characteristic with&amp;nbsp;sd_ble_gattc_char_value_by_uuid_read() in the value field of handle/value struct I obtain only 19 bytes, but always CORRECT as the first 19 bytes of expected value. An explaination on how get the&amp;nbsp;remaining bytes with that method&amp;nbsp;should be fine. Tried to call again&amp;nbsp;&lt;span&gt;sd_ble_gattc_char_value_by_uuid_read() with the handle_range augmented by 1 but I obtain ATTR_NOT_FOUND error.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Read BLE characteristic with nRF52840-DK and pc-ble-driver</title><link>https://devzone.nordicsemi.com/thread/324457?ContentTypeID=1</link><pubDate>Wed, 11 Aug 2021 11:53:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c2357691-9167-470c-abfc-ed2f28d6e055</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What you described about your process to read blob &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v7.3.0/group___b_l_e___g_a_t_t_c___v_a_l_u_e___r_e_a_d___m_s_c.html?cp=4_7_3_1_2_2_3_4"&gt;is correct&lt;/a&gt;. But please clarify when do you receive corrupted data ?&amp;nbsp;&lt;br /&gt;If the ATT_MTU is 23 bytes it&amp;#39;s about right that the first packet you can only receive 22 bytes.&amp;nbsp;&lt;br /&gt;If you want to read with longer data in one read request,&amp;nbsp; you need to request longer ATT_MTU. We support up to 247.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Read BLE characteristic with nRF52840-DK and pc-ble-driver</title><link>https://devzone.nordicsemi.com/thread/324394?ContentTypeID=1</link><pubDate>Wed, 11 Aug 2021 08:19:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:837bcd3e-3b04-49a3-b352-67df0ff7f812</guid><dc:creator>cheip</dc:creator><description>&lt;p&gt;I send in total three&amp;nbsp;&lt;span&gt;sd_ble_gattc_read()&amp;nbsp;, first time with offset 0 and i get the first 22 bytes, then I send a second&amp;nbsp;sd_ble_gattc_read() with offset 22 (length of the result I got) and I get the last 10 bytes. Then I send a thid&amp;nbsp;sd_ble_gattc_read() with offset 32, I get a result with length 0, so I stop the process.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Read BLE characteristic with nRF52840-DK and pc-ble-driver</title><link>https://devzone.nordicsemi.com/thread/324385?ContentTypeID=1</link><pubDate>Wed, 11 Aug 2021 07:51:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4eff8761-d438-45a7-9dc9-41147a485ac0</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;I&amp;#39;m not aware of an example beside the heart rate collector in the repo.&lt;/p&gt;
&lt;p&gt;I would strongly suggest to use a sniffer to catch what the actual read command is sent over the air.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;From what you said I understand that if you send 2&amp;nbsp;&lt;span&gt;sd_ble_gattc_read () with the same offset 0 you actually can get all 32 bytes ?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Have you tried to test with smaller characteristic size ? Says 10 bytes&amp;nbsp; ? This is because by default the ATT_MTU is 23 bytes.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Read BLE characteristic with nRF52840-DK and pc-ble-driver</title><link>https://devzone.nordicsemi.com/thread/324313?ContentTypeID=1</link><pubDate>Tue, 10 Aug 2021 15:59:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cbac335b-0ffe-42fa-b67f-4261c95aad76</guid><dc:creator>cheip</dc:creator><description>&lt;p&gt;I read with offset 0 the first time i call &lt;code&gt;sd_ble_gattc_read&amp;nbsp;&lt;/code&gt;and no, I do not get the correct data. Continuing the reading process with offsets I can get all 32 bytes for the characteristic value.&lt;/p&gt;
&lt;p&gt;Unfortunately I can not give more details on those&amp;nbsp;data I get because they changes from one read and another, like I am reading &amp;quot;random&amp;quot; data.&lt;/p&gt;
&lt;p&gt;Maybe can I find somewhere a working example like the ones I found in pc-ble-driver repository to study a working code?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Read BLE characteristic with nRF52840-DK and pc-ble-driver</title><link>https://devzone.nordicsemi.com/thread/324312?ContentTypeID=1</link><pubDate>Tue, 10 Aug 2021 15:52:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5b2df71e-ca5e-4568-afaf-b09510114396</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;I don&amp;#39;t see anything suspicious here.&amp;nbsp;&lt;br /&gt;But could you describe the corrupted data you receive&amp;nbsp; ? Does it have the correct length ?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;If you don&amp;#39;t do any offset reading but simply read with 0 offset do you see the correct data?&lt;br /&gt;Would strongly suggest to get an extra DK to work as the sniffer, it would make it much easier to debug.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Read BLE characteristic with nRF52840-DK and pc-ble-driver</title><link>https://devzone.nordicsemi.com/thread/324292?ContentTypeID=1</link><pubDate>Tue, 10 Aug 2021 13:55:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:81a8efec-d7da-4c14-8544-ef7881b94964</guid><dc:creator>cheip</dc:creator><description>&lt;p&gt;Thank you&amp;nbsp;for your&amp;nbsp;helpful&amp;nbsp;reply.&lt;/p&gt;
&lt;p&gt;I checked the handle_value and the&amp;nbsp;characteristic value with nRF Connect tool and the handle_value corresponds to the one i discover with my software, and the characteristic value correspond to the value read with my &amp;quot;benchmark&amp;quot; software. So I am pretty sure my program is wrong in some point.&lt;/p&gt;
&lt;p&gt;unfortunately I can not try with the sniffer because I have only one board at the moment.&lt;/p&gt;
&lt;p&gt;I paste here the relevant portions of code if you want to take a look and say to me if you notice&amp;nbsp;any trivial mistake I am doing.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Start read:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt; &lt;/span&gt;&lt;code&gt;&lt;span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint32_t read_start(uint16_t connection_handle, uint16_t value_handle)
{
    printf(&amp;quot;VALUE HANDLE: 0x%04X\n&amp;quot;, value_handle); // this value corresponds
    fflush(stdout);
    
    auto error_code = sd_ble_gattc_read(adapter, connection_handle, value_handle, 0);
    if (error_code != NRF_SUCCESS)
    {
        printf(&amp;quot;ERROR&amp;quot;);
        fflush(stdout);
    }
    
    return error_code;
}&lt;/pre&gt;
&lt;div&gt;&lt;code&gt;&lt;span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;&lt;code&gt;&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Read value&amp;nbsp;event handling:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;&lt;code&gt;&lt;span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;pre class="ui-code" data-mode="c_cpp"&gt;static int offset = 0;
static void on_read_response(ble_gattc_evt_t *const p_ble_gattc_evt)
{
    if (p_ble_gattc_evt-&amp;gt;gatt_status != NRF_SUCCESS)
    {
        printf(&amp;quot;ERROR&amp;quot;);
        fflush(stdout);
        return;
    }
    
    auto result = p_ble_gattc_evt-&amp;gt;params.read_rsp;
    
    for (size_t i = 0; i &amp;lt; result.len; i++)
    {
        printf(&amp;quot;0x%02X &amp;quot;, result.data[i]); // this values are always different from one read to another
        fflush(stdout);
    }
    printf(&amp;quot;\n&amp;quot;);
    fflush(stdout);
    
    if (result.len &amp;gt; 0)
    {
        offset += result.len;
    
        auto error_code = sd_ble_gattc_read(adapter, p_ble_gattc_evt-&amp;gt;conn_handle, result.handle, offset);
        if (error_code != NRF_SUCCESS) {
            printf(&amp;quot;ERROR&amp;quot;);
            fflush(stdout);
        }
    }
}&lt;/pre&gt;
&lt;div&gt;&lt;code&gt;&lt;span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;&lt;code&gt;&lt;/code&gt;&lt;/div&gt;
&lt;div&gt;&lt;code&gt;&lt;span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;code&gt;&lt;span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Read BLE characteristic with nRF52840-DK and pc-ble-driver</title><link>https://devzone.nordicsemi.com/thread/324263?ContentTypeID=1</link><pubDate>Tue, 10 Aug 2021 13:07:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:05752f95-c1b4-4e0f-bd3b-b84547a86bef</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Cheip,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please check and verify that the handle_value (location of the attribute in the attribute table) you got from service discovery is correct. You can verify that using nRF Connect tool on PC.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If it&amp;#39;s the correct handle value (it&amp;#39;s the handle of the value of the characteristic), you may want to capture &lt;a href="https://www.nordicsemi.com/Products/Development-tools/nrf-sniffer-for-bluetooth-le"&gt;a sniffer trace&lt;/a&gt; to check if the&amp;nbsp;read request has the correct value or not as well as checking the read response if the correct value is responded.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>