<?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>BLE Fragmentation data loss</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/119438/ble-fragmentation-data-loss</link><description>I am using an nRF52840 processor within a Particle Argon IoT module. I am polling a third party BLE peripheral (Shelly relay) for status data once a minute. The data packet that device responds with is 779 bytes long. I am consistently losing 3 bytes</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 04 Mar 2025 12:59:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/119438/ble-fragmentation-data-loss" /><item><title>RE: BLE Fragmentation data loss</title><link>https://devzone.nordicsemi.com/thread/525714?ContentTypeID=1</link><pubDate>Tue, 04 Mar 2025 12:59:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9bbd2b2e-6337-4181-8299-d7aa558a4be2</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Bare hyggelig &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&amp;nbsp;Good luck with your project!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Fragmentation data loss</title><link>https://devzone.nordicsemi.com/thread/525706?ContentTypeID=1</link><pubDate>Tue, 04 Mar 2025 12:28:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3bd7d79c-0b58-40c1-9d81-ed2a2c4d4002</guid><dc:creator>Tbnilsen</dc:creator><description>&lt;p&gt;Thanks Vidar! You have been most helpful. I&amp;rsquo;ll pass this thread onto Particle support. In fairness to them their documentation does state that their BLE implementation supports maximum 244 byte packets. So technically I&amp;rsquo;m violating that. I have been able to modify a copy of their latest OS and at least allow my application to receive these fragmented packets. Ha det bra!&lt;/p&gt;
&lt;p&gt;Terje Berg Nilsen.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Fragmentation data loss</title><link>https://devzone.nordicsemi.com/thread/525637?ContentTypeID=1</link><pubDate>Tue, 04 Mar 2025 06:45:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6e3edec-c06d-4ee0-aef6-1422aae6982e</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hallo,&lt;/p&gt;
&lt;p&gt;Yes, with a MTU of 247 bytes, you can receive a read response with up to 246 bytes of payload. Regarding fragmentation, it seems like it&amp;nbsp;must&amp;nbsp;be handled at the application layer on both devices. The maximum attribute value length in a&amp;nbsp;bluetooth characteristic is 512 bytes,&amp;nbsp;which makes it impossible to receive the full 779 bytes of data in one read, even with a long read.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I also had a look at the hal_ble_gatt_client_read() implementation and see that it only issues &amp;quot;ATT_READ_REQ&amp;quot; requests (i.e. it does not perform multiple read request with offsets). The response to this request is ATT_READ_RSP (notice that there is only 1 byte overhead in&amp;nbsp;this response):&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/pastedimage1741068417026v3.png" alt=" " /&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/particle-iot/device-os/blob/507ab1517a8720af4e3bd20a6c6cc66f81cfc1f1/hal/src/nRF52840/ble_hal.cpp#L3239"&gt;ttps://github.com/particle-iot/device-os/blob/507ab1517a8720af4e3bd20a6c6cc66f81cfc1f1/hal/src/nRF52840/ble_hal.cpp#L3239&lt;/a&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Fragmentation data loss</title><link>https://devzone.nordicsemi.com/thread/525589?ContentTypeID=1</link><pubDate>Mon, 03 Mar 2025 18:46:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2bb8f0d9-bc72-4960-b540-de6ecbfe116c</guid><dc:creator>Tbnilsen</dc:creator><description>&lt;p&gt;Vidar,&lt;/p&gt;
&lt;p&gt;When you say the payload for a read response can be up to MTU - 1, does that mean if the negotiated MTU is 247 and the peripheral is sending a response large enough to require fragmentation it&amp;#39;s possible to get data fragments (payload) of 246 or less? (I.e. 245,244)? This would certainly explain my problem since the Particle OS layer does not allow packets greater than MTU - 3.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Fragmentation data loss</title><link>https://devzone.nordicsemi.com/thread/525575?ContentTypeID=1</link><pubDate>Mon, 03 Mar 2025 16:29:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6c3d1eb-d991-4b08-b381-10d0a67392f8</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Unfortunately, we don&amp;#39;t have an offline version of the SD API documentation available. I think it&amp;#39;s difficult to&amp;nbsp;speculate what the root cause of this issue without some debugging or code review. This is why I initially suggested capturing sniffer&amp;nbsp;trace to analyze the packet exchange on-air. This allows you to verify&amp;nbsp;if the read requests and responses are as expected. If they are, you would know that the bytes are being lost at the application level.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Fragmentation data loss</title><link>https://devzone.nordicsemi.com/thread/525527?ContentTypeID=1</link><pubDate>Mon, 03 Mar 2025 13:44:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3bd31d43-5de6-4a09-b3dc-4fee3a6eeb14</guid><dc:creator>Tbnilsen</dc:creator><description>&lt;p&gt;Hallo Vidar,&lt;/p&gt;
&lt;p&gt;any chance I can get a copy of the nRF52840 SoftDevice API doc?&lt;/p&gt;
&lt;p&gt;Also, do you have an opinion on how such a discrepancy could arise (other than a direct &amp;quot;it was set wrongly&amp;quot;)? Is there something in the fragmentation algorithm that could explain this?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Fragmentation data loss</title><link>https://devzone.nordicsemi.com/thread/525459?ContentTypeID=1</link><pubDate>Mon, 03 Mar 2025 09:39:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c3efc908-7dce-414c-a44a-9b376c39328a</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Thank you for reporting back and providing an explanation to&amp;nbsp;the issue you observed.&amp;nbsp;As you may know, the&amp;nbsp;default att MTU for BLE devices is always 23 bytes. The longer MTU&amp;nbsp;in this case&amp;nbsp;is negotiated between the devices&amp;nbsp;after the connection is established. The payload for a read response can be up to MTU - 1 byte ATT header while for a write or read request it is MTU - 3 bytes.&lt;/p&gt;
&lt;p&gt;Softdevice API documentation for future reference&lt;/p&gt;
&lt;p&gt;-&amp;nbsp; &lt;a href="https://docs.nordicsemi.com/bundle/s140_v7.3.0_api/page/group_b_l_e_g_a_t_t_c_f_u_n_c_t_i_o_n_s.html#ga813daa5810a1d2ed31d2d6fe49d3ef11"&gt;sd_ble_gattc_read&lt;/a&gt;()&lt;/p&gt;
&lt;p&gt;-&amp;nbsp;&lt;a href="https://docs.nordicsemi.com/bundle/s140_v7.3.0_api/page/group_b_l_e_g_a_t_t_c_v_a_l_u_e_r_e_a_d_m_s_c.html"&gt;GATTC Characteristic or Descriptor Value Read&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Fragmentation data loss</title><link>https://devzone.nordicsemi.com/thread/525382?ContentTypeID=1</link><pubDate>Sat, 01 Mar 2025 12:00:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:400dc341-916c-44f8-a07e-93778a4eaf4c</guid><dc:creator>Tbnilsen</dc:creator><description>&lt;p&gt;Vidar,&lt;/p&gt;
&lt;p&gt;I was able to change Particle&amp;#39;s OS to allow getValue reads of more than 244 bytes each call. After I did that, each call to getValue returned 245 bytes (I asked for the length my buffer can hold (1024) each call). Looping through, I now get the full message length (in this test case the message was 798 bytes and I got 245+245+245+63).&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve observed that limiting read requests (ultimately) to SoftDevice, any value short of 245 causes loss of data. For example reading 244 each time loses 1 byte each full buffer return. Reading only 200 each call loses 45, etc.&lt;/p&gt;
&lt;p&gt;Does SoftDevice have a bug? Or is this a documented (or implied) feature that must be adhered to for proper fragmented BLE coms. I have also informed Particle about this. Not sure who repairs this.&lt;/p&gt;
&lt;p&gt;EDIT: Is this maybe an MTU issue? I tried finding the API for SoftDevice so I can read up on its use, but I was not successful.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;EDIT2: It &lt;strong&gt;&lt;em&gt;is&lt;/em&gt;&lt;/strong&gt; an MTU issue. Apparently, Particle believes it has set it for a payload of 244 bytes each fragment, when SoftDevice has it as 245. So 1 byte is always lost per full fragment regardless of what the MTU is set to in Particle.&lt;/p&gt;
&lt;p&gt;I consider this a Particle issue and not a SoftDevice one.&amp;nbsp; Thanks for your time Vidar. (Tusen takk).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Fragmentation data loss</title><link>https://devzone.nordicsemi.com/thread/525372?ContentTypeID=1</link><pubDate>Sat, 01 Mar 2025 00:32:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:87e5b693-e009-4478-ab31-4006d9ebc442</guid><dc:creator>Tbnilsen</dc:creator><description>&lt;p&gt;Sorry, looks like there&amp;rsquo;s another layer in the Particle OS before SoftDevice. I&amp;rsquo;ll be looking into that further.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;That said, I&amp;rsquo;d really like to get some insight into how a layer such as Particle&amp;rsquo;s OS should conduct itself when dealing with a fragmented packet being received from a peripheral device.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Fragmentation data loss</title><link>https://devzone.nordicsemi.com/thread/525361?ContentTypeID=1</link><pubDate>Fri, 28 Feb 2025 21:12:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1899b023-fc21-4265-b28f-690e60e4b87b</guid><dc:creator>Tbnilsen</dc:creator><description>&lt;p&gt;Here&amp;#39;s their code (Particle). I call this member function getValue() four times in rapid succession asking for 244 bytes of data. I get 3 full packets of 244 bytes, and one final packet of 44 bytes for a total of 776 bytes. The message is supposed to be 779 bytes long. When I examine that data I see that the 245th, 490th, and 735th bytes are missing. (BLE_MAX_ATTR_PACKET_SIZE is 244).&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class="ui-code" data-mode="text"&gt;ssize_t BleCharacteristic::getValue(uint8_t* buf, size_t len) const {
    if (buf == nullptr || len == 0) {
        return SYSTEM_ERROR_INVALID_ARGUMENT;
    }
    len = std::min(len, (size_t)BLE_MAX_ATTR_VALUE_PACKET_SIZE);
    if (impl()-&amp;gt;connHandle() != BLE_INVALID_CONN_HANDLE){
        return hal_ble_gatt_client_read(impl()-&amp;gt;connHandle(), impl()-&amp;gt;attrHandles().value_handle, buf, len, nullptr);
    }
    else if (impl()-&amp;gt;isLocal()) {
        return hal_ble_gatt_server_get_characteristic_value(impl()-&amp;gt;attrHandles().value_handle, buf, len, nullptr);
    }
    return SYSTEM_ERROR_INVALID_STATE;
}&lt;/pre&gt;
&lt;div&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;I don&amp;#39;t know if &lt;span style="font-family:&amp;#39;comic sans ms&amp;#39;, &amp;#39;comic sans&amp;#39;, sans-serif;"&gt;&lt;span&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;hal_ble_gatt_client_read&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;is your SoftDevice layer being called, but I think so. Is there something special that needs to happen for fragmented packages?&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Fragmentation data loss</title><link>https://devzone.nordicsemi.com/thread/525360?ContentTypeID=1</link><pubDate>Fri, 28 Feb 2025 20:59:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:04665740-f7d3-440e-8e70-b44fdf87cb77</guid><dc:creator>Tbnilsen</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve actually done that - the data is moving across BLE correctly. As stated, I used a PC to verify that. I&amp;#39;m now leaning towards the Particle OS layer that interacts with your stack. Their source is open and see that they call&amp;nbsp;&lt;strong&gt;hal_ble_gatt_client_read()&lt;/strong&gt; which I believe is your stack. They limit each call to that to 244 byte buffer. I think they didn&amp;#39;t implement the requirements on their end for receiving fragmented packets.&lt;/p&gt;
&lt;p&gt;Do you have any documentation for me where I can read up on how to use your stack and specifically on fragmentation?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Fragmentation data loss</title><link>https://devzone.nordicsemi.com/thread/525349?ContentTypeID=1</link><pubDate>Fri, 28 Feb 2025 18:12:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cc191bed-3ed2-4149-943f-dd87f3327c04</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;The easiest way to troubleshoot this would likely be by capturing a&amp;nbsp;bluetooth sniffer trace and&amp;nbsp;compare the packet exchange when it works and when it doesn&amp;#39;t. Our&amp;nbsp;&lt;a href="https://www.nordicsemi.com/Products/Development-tools/nRF-Sniffer-for-Bluetooth-LE"&gt;nRF Sniffer for Bluetooth LE&lt;/a&gt;&amp;nbsp;is a low cost option, but it requires that you have a&amp;nbsp;&lt;a href="https://www.nordicsemi.com/Products/Development-hardware/nRF52840-Dongle"&gt;nRF52840 Dongle&lt;/a&gt;&amp;nbsp;or one of the other supported boards laying around. Is the code to poll the sensor provided by Particle or is it something you have written. Either way, it would be nice to see the code showing how it is implemented if possible. I&amp;#39;m not aware of any known bugs in the stack that could explain the data loss.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>