<?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>Is it possible to run code when the device wakes to advertise ?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/16102/is-it-possible-to-run-code-when-the-device-wakes-to-advertise</link><description>Hi, 
 I&amp;#39;d like to check the battery level in my BLE device, and I can set a timer to handle the checking, however this means that Timer 1 would need to powered up, and hence it would take more power 
 I thought perhaps I could attach a callback to run</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 01 Sep 2016 05:17:54 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/16102/is-it-possible-to-run-code-when-the-device-wakes-to-advertise" /><item><title>RE: Is it possible to run code when the device wakes to advertise ?</title><link>https://devzone.nordicsemi.com/thread/61403?ContentTypeID=1</link><pubDate>Thu, 01 Sep 2016 05:17:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bfc13e5d-fb03-4618-a952-d6e72d1e8ee5</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;I am glad to hear. If you are happy with the answer, could you please accept it? You can do that by clicking the circle checkmark to the left of it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to run code when the device wakes to advertise ?</title><link>https://devzone.nordicsemi.com/thread/61402?ContentTypeID=1</link><pubDate>Thu, 01 Sep 2016 00:25:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d3ce36f-6c70-45d4-aa63-28a4bd11efb8</guid><dc:creator>Roger Clark</dc:creator><description>&lt;p&gt;Thanks Einar&lt;/p&gt;
&lt;p&gt;That&amp;#39;s just what I was looking for.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t need to actually read the ADC each time it advertises, but I thought I could simply use a counter and when the device has advertised a predefined number of times , equal to one hour of operation I will read the ADC to get the voltage and then change the advertising data (for next time it advertises)&lt;/p&gt;
&lt;p&gt;This would add very little overhead to normal operation
eg&lt;/p&gt;
&lt;p&gt;if (++counter&amp;gt;MAX_COUNT)
{
counter=0;// counter is volatile int
// Read ADC etc etc&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;Thanks again&lt;/p&gt;
&lt;p&gt;Roger&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it possible to run code when the device wakes to advertise ?</title><link>https://devzone.nordicsemi.com/thread/61401?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2016 12:22:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a957c04d-2999-4194-a484-597dc7279acc</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;There are a few things to note here. Firstly, you can get a event whenever the radio is active, using &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s130.sds/dita/softdevices/s130/radio_notif/radio_notification.html?cp=3_6_2_0_10"&gt;Radio notification&lt;/a&gt;. Secondly, you do not need to use a TIMER in order to perform a task at a regular interval. The low power RTC is perfect for this purpose, and the additional current consumption is neglectable, as it uses the low frequency clock, which is anyway running when you have the SoftDevice enabled (needed for BLE). The &lt;a href="https://devzone.nordicsemi.com/tutorials/19/"&gt;Application timer&lt;/a&gt; library, which uses the RTC, is probably worth looking at.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>