<?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>How to create robust BLE transmission and messages between an embedded device and mobile app for large amounts of data? (General design question)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/114988/how-to-create-robust-ble-transmission-and-messages-between-an-embedded-device-and-mobile-app-for-large-amounts-of-data-general-design-question</link><description>This is a higher-level question because I&amp;#39;m having difficulty finding concise and clear practices for this sort of thing. I don&amp;#39;t want to go implementing something subpar. 
 I have a mobile application which pairs to my embedded device. The device has</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 30 Sep 2024 22:09:10 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/114988/how-to-create-robust-ble-transmission-and-messages-between-an-embedded-device-and-mobile-app-for-large-amounts-of-data-general-design-question" /><item><title>RE: How to create robust BLE transmission and messages between an embedded device and mobile app for large amounts of data? (General design question)</title><link>https://devzone.nordicsemi.com/thread/504445?ContentTypeID=1</link><pubDate>Mon, 30 Sep 2024 22:09:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eb2db3cf-ede8-4637-81a3-052c38ae1fe3</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I am sorry for the late reply.&lt;/p&gt;
&lt;p&gt;Ok, let us try to figure this out. Just in case we want to point at some API, what SDK do you intend to use? The nRF5 SDK (which is the &amp;quot;old&amp;quot; SDK used while the nRF52 series was launched. It works, but is in maintenance mode), or do you want to use the new nRF Connect SDK (&amp;quot;NCS&amp;quot;, which is our &amp;quot;current&amp;quot; SDK). Regardless of what SDK you are using, the BLE stack and protocol is the same, so let&amp;#39;s try to answer your questions:&lt;/p&gt;
[quote user=""]What if the app disconnects during the measurement?[/quote]
&lt;p&gt;Let us save this for later.&lt;/p&gt;
[quote user=""]Packet formatting[/quote]
&lt;p&gt;This depends on your needs. How much data are we talking in a total measurement? And how often is this being sent? If you need a high throughput, chunking the samples together in bigger packets and using a large MTU is preferable, as it gives a larger payload/header ratio. This allows for up to the 1.3MBPS payload throughput, which is the maximum allowed by the current BLE specification.&lt;/p&gt;
[quote user=""]Acknowledgement[/quote]
&lt;p&gt;All packets in BLE are acknowledged, or retransmitted until they are. So this is not really the intention for indications. Notifications should be more than fine for data transfer. Indications, which are application controlled acknowledgment, as you said, are intended for other mechanisms, such as in a doorlock, you can confirm that the door is locked (and not for example jammed) before you send the application acknowledgement back to the central. Using indications instead of notifications gives a significant decrease in throughput.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote user=""]Error checking and handling[/quote]
&lt;p&gt;That is correct. The CRC is checked by the BLE stack before the AKC is sent, so you can know that all data that is acked is also correct.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote user=""]Data reconstruction[/quote]
&lt;p&gt;You are guaranteed that the packets will enter the receiver&amp;#39;s application the same order that they were queued in the transmitter&amp;#39;s application. However, if you&amp;#39;d like, you can add some sequence numbering if you want to know how much data is left. I imagine this can replace the need for a &amp;quot;more data&amp;quot; characteristic, which may take up bandwidth, e.g. by saying that the first byte or two describes how much data is left of the transfer.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote user=""]What if the app disconnects during the measurement?[/quote]
&lt;p&gt;So back to this. I chose to save it for last since it is the question that complicates all of the questions, really. In general, BLE is a lossless protocol. This doesn&amp;#39;t mean that you don&amp;#39;t have packet loss, because you certainly do. But the protocol guarantees that all queued packets are transmitted, &amp;quot;and it will die trying&amp;quot;. So in this case, &amp;quot;die&amp;quot; means disconnect. As long as you queue a packet, and the link is still connected after the supervision timeout period, the packet has been delivered. If the packet was not received within this period, it means that the devices has not received a packet with the correct CRC within this period, and the link is considered disconnected.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So what is the source of your disconnect? Dead battery? The devices are moving too far apart? An increase in RF noise? Depending on the reason, you may or may not want to introduce saving data to flash. If you don&amp;#39;t think power loss is a likely issue, then I wouldn&amp;#39;t bother saving data to flash, as long as you are able to store a large enough buffer in RAM. However, if you experience a disconnect, you may want to keep track of what data that is actually sent and ACKed. For this, we have callbacks that you can use to determine what packets that was successfully ACKed (what API and callbacks depends on your SDK). If the issue is that they have a poor connection, I would try to increase the supervision timeout, since this will make them try to communicate for longer before disconnecting the link. The disadvantage of this is that it takes longer for the disconnection to happen and your app to &amp;quot;know&amp;quot;, but the advantage is that all your queued packets are still queued, and you don&amp;#39;t have to deal with the disconnect/connect handling, and figure out what packets that wasn&amp;#39;t ACKed.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Really, it depends on the consequences of your partially transmitted measurements. What is the impact of a disconnect? Can you do another measurement, and throw away the old one?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Hopefully this gives the answer to some of your questions. Perhaps you can elaborate a bit more on the consequences of a partially received measurement? It is possible to store the data in flash, but if the consequences aren&amp;#39;t that high, the application structure is way easier if you don&amp;#39;t need to think about this.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>