<?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>Synchronize timestamps between SoC and mobile app</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/52184/synchronize-timestamps-between-soc-and-mobile-app</link><description>Background 
 I am attempting to build a system in which a Nordic NRF52840 SoC, is connected to a mobile app (iOS / Android) via BLE and both devices play back audio-visual feedback in a synchronized manner. Both devices are able to take care of their</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 26 Sep 2019 08:21:54 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/52184/synchronize-timestamps-between-soc-and-mobile-app" /><item><title>RE: Synchronize timestamps between SoC and mobile app</title><link>https://devzone.nordicsemi.com/thread/211972?ContentTypeID=1</link><pubDate>Thu, 26 Sep 2019 08:21:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bc5acfca-7e0c-4aa2-9ed2-d2b9f7896a5d</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;A17: Reducing the connection interval would reduce the delay introduced by packet loss, so it could help in that way. I do not see any other benefit. Regarding packet loss it depends. The center may have a harder time scheduling events the more frequent they are, so in that sense, the likelihood of packet loss may be higher. But I do not see any other problems, except for the obvious increase in average power consumption.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Synchronize timestamps between SoC and mobile app</title><link>https://devzone.nordicsemi.com/thread/211808?ContentTypeID=1</link><pubDate>Wed, 25 Sep 2019 12:22:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1bdf32d0-722f-4fd9-aa08-f9f6f2e29dc9</guid><dc:creator>alejandrohc</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Q17:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Do you think that dynamically reducing the connection interval for the timestamp sync process (to something close to 7ms) would help?&lt;/li&gt;
&lt;li&gt;I know that it is now also supported by iOS, but am afraid that it would cause more packets to get lost / not arrive during that smaller time frame.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Other than that, all of my questions have been addressed and I thank you for your helpful advice.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Synchronize timestamps between SoC and mobile app</title><link>https://devzone.nordicsemi.com/thread/211139?ContentTypeID=1</link><pubDate>Mon, 23 Sep 2019 08:25:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d22aee5f-42ad-44c1-bd87-a838e283d592</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;A11: No. There is no standard way, so there is no way of doing this together with a phone.&lt;/p&gt;
&lt;p&gt;A12: It is not possible to pop packets from the Tx queue on the nRF side. Once the packets are queued the will be sent at some point (unless there is a connection supervision timeout).&lt;/p&gt;
&lt;p&gt;A13: No updates. It is still not supported by the SoftDevice.&lt;/p&gt;
&lt;p&gt;A14: The pseudo-random delay is only used for advertisement packets, not for connection events.&lt;/p&gt;
&lt;p&gt;A15(13): It depends on the link configuration (the packets per connection depends on several factors such as packet lengths, event duration, and buffer sizes). You can only control the nRF side, as the BLE stack on the phone is less configurable. So ideally &amp;quot;Yes&amp;quot;, and you should remember that even if you test with one phone, a different phone can behave differently.&lt;/p&gt;
&lt;p&gt;A16(14): I have not heard about it being an issue with indications, and it seems less likely since the ack has to come the whole way round before a new packet is transmitted. But in any case, this is just a strange behavior we have seen a few times within the phone, and not something that you can observe on the BLE link. It is difficult to predict what may happen on the API between the application and BLE stack on the phone side since that is totally out of our control.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Synchronize timestamps between SoC and mobile app</title><link>https://devzone.nordicsemi.com/thread/210987?ContentTypeID=1</link><pubDate>Fri, 20 Sep 2019 14:34:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:57c67f12-ca56-4fd2-a128-8ff71b4d72e9</guid><dc:creator>alejandrohc</dc:creator><description>&lt;p&gt;Hi Einar, thank you for your responses, they&amp;#39;re very informative.&lt;/p&gt;
&lt;p&gt;A1: Great to know I&amp;#39;m on the right track.&lt;/p&gt;
&lt;p&gt;A3: I see, did not consider that the protocol is retrying the transmission of packages for me.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Q11: I&lt;/strong&gt;s there any other way of transmitting data without the protocol automatically retransmitting lost packages? This way I could send a series of packages, where the one with the lowest offset wins. Dropped and therefore outdated packages would then not further clutter the queue either (I am thinking of something like &lt;a href="https://www.pluralsight.com/content/dam/pluralsight/resources/blog/2007/10/networking-basics-tcp-udp-tcpip-osi-models/wp/img/TCP7.jpg"&gt;UDP vs. TCP&lt;/a&gt; in the web).&lt;/p&gt;
&lt;p&gt;A4: Yes, it is the exact same firmware on the SoC. &lt;strong&gt;Q12: &lt;/strong&gt;&lt;span&gt;How can one pop packages from the queue? That &lt;/span&gt;&lt;span&gt;would help me to cancel the message if it&amp;#39;s too late already.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;strong&gt;Q13: &lt;/strong&gt;Do you have any news about the &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/27425/determine-characteristic-handle-that-caused-ble_gatts_evt_hvn_tx_complete/139447#139447"&gt;potential way &lt;/a&gt;of knowing which characteristic sent out a packet? With that information I could notify the mobile phone if the packet was sent out too late.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;A5: &lt;strong&gt;Q14: &lt;/strong&gt;Is that pseudo-random delay exclusive to the advertisement packets or are notifications also susceptible to that due to the transmission window?&lt;/p&gt;
&lt;p&gt;A6, A7: Interesting.&lt;br /&gt;A8: Will definitely try to not transmit packets from the SoC to the phone during the timestamp synchronisations. &lt;strong&gt;Q13:&lt;/strong&gt;&amp;nbsp;Should I also make sure no packets are transmitted from the phone to the SoC? That would be harder to do, particularly in iOS since &lt;span&gt;I&lt;/span&gt; don&amp;#39;t control its services ANCS and CTS for push notifications and time correspondingly.&lt;br /&gt;A9: Some phones changing the order of the notifications sounds critical, will then not assume that the packets are always sent in a specific order. I think this is not an issue for Indication &lt;strong&gt;Q14: &lt;/strong&gt;right?&lt;/p&gt;
&lt;p&gt;A10: That&amp;#39;s a very interesting post indeed, I&amp;#39;ve looked at it in detail. In an ideal world, I&amp;#39;d be able to develop a BLE dongle what connects over USB to the mobile device and also runs a Nordic Semi SoC with a custom radio notification protocol... but that&amp;#39;s a dream for another time.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Synchronize timestamps between SoC and mobile app</title><link>https://devzone.nordicsemi.com/thread/210114?ContentTypeID=1</link><pubDate>Tue, 17 Sep 2019 12:13:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8894ecc3-91b1-441c-8bdb-2159390b498b</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;A1: Yes. If&amp;nbsp;sd_ble_gatts_hvx() returns&amp;nbsp;NRF_SUCCESS, the packet has been queued.&amp;nbsp;It will return&amp;nbsp;NRF_ERROR_RESOURCES if the queue is full.&lt;/p&gt;
&lt;p&gt;A2: The notifications are transmitted int the order there were transmitted. But if you also send other BLE data, there may be some other packets that were queued before, and if so, these will be transmitted before. This is the most likely explanation for variation within a connection event.&lt;/p&gt;
&lt;p&gt;A3:&amp;nbsp;The most probable reason for seeing delays which are multiple of a connection interval is packet loss, which leads to retransmission the next connection event (and so on, until the packet is successfully transferred or there is a supervision timeout). It could also be that if you are transmitting a lot of data and/or the link does not support &amp;quot;enough&amp;quot; packets per connection event, the packet is delayed until the next event in this case as well.&lt;/p&gt;
&lt;p&gt;A4: Is this with the exact same firmware on the nRF side? The number of packets you can queue depends on the SoftDevice configuration. If not, then perhaps there is a problem with your test, for instance, that packets are popped from the queue while you are filling it (in the middle of a connection event), and therefore you can fill more? But in another case, you are doing the test outside a connection event? This is just one possible explanation.&lt;/p&gt;
&lt;p&gt;A5: I am not in a position to recommend one or the other. However, putting the timestamp in the advertisement packet also has the limitation that there is a time from when you read the timestamp to when you transmit the advertisement. A particularly important point here is that advertisement packets are transmitted with a pseudo-random 0-10 ms delay, which may not be acceptable.&lt;/p&gt;
&lt;p&gt;A6: No good/obvious alternatives. Since you are communicating with a phone, you have to use standard BLE, so using, for instance, ESB (which has been recommended to some customers before) is not an option in this case.&lt;/p&gt;
&lt;p&gt;A7: Yes. The nRF is capable of handling several roles concurrently, and advertising while maintaining a connection is no problem.&lt;/p&gt;
&lt;p&gt;A8: Yes, using notifications in a connection seems sensible, and looks like the best approach in my mind. The accuracy depends on several factors. You will get the best accuracy if you don&amp;#39;t transmit other BLE data and you syncronize the clocks regularly. Then you can filter out synchronization packets that have a jump in the time since they are probably bad (a result of packet loss). Inaccuracies due to other packets being queued before is a bit more difficult to predict, but perhaps you could make sure that you never queue other data until after having queued the synchronization notification.&lt;/p&gt;
&lt;p&gt;A9: This one is difficult. It can vary from phone to phone and may change over time (with SW updates). So I cannot make any promises on the phone side. We have also seen earlier that some phones may change the order of the notifications. But this is unfortunately out of our control.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;A10: Not really. You may find &lt;a href="https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/wireless-timer-synchronization-among-nrf5-devices"&gt;Wireless timer synchronization among nRF5 devices&lt;/a&gt;&amp;nbsp;interesting, as it describes the problems you are seeing. But the proposed solution cannot be used between an nRF and a phone since the phones do not support ESB.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>