<?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>Periodically changing the MAC address on nRF51822 Beacon Kit</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/7303/periodically-changing-the-mac-address-on-nrf51822-beacon-kit</link><description>Hi, 
 I am able to change the MAC address of the beacon using the call sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &amp;amp;gap_addr), where gap_addr is of type BLE_GAP_ADDR_TYPE_RANDOM_STATIC. 
 Now what I want to do is to change the MAC address periodically</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 28 May 2015 09:21:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/7303/periodically-changing-the-mac-address-on-nrf51822-beacon-kit" /><item><title>RE: Periodically changing the MAC address on nRF51822 Beacon Kit</title><link>https://devzone.nordicsemi.com/thread/25828?ContentTypeID=1</link><pubDate>Thu, 28 May 2015 09:21:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bee42b74-6d63-493a-b7b9-5577efcb1a6a</guid><dc:creator>Ulrich Myhre</dc:creator><description>&lt;p&gt;Sorry for the confusion, I took the API calls from my head and forgot a parameter. Fixed it in the original post.
The APP defines in the SDK are actually used during run-time, which is why they make a change. The SoftDevice is pre-built and static, and will not alter behavior by just changing any defines. The default define is just there for you to be able to reset the address switching time back to its default setting without having to look up/hardcode whatever that value is (and update if the default updates).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Periodically changing the MAC address on nRF51822 Beacon Kit</title><link>https://devzone.nordicsemi.com/thread/25821?ContentTypeID=1</link><pubDate>Thu, 28 May 2015 02:16:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0bfa0feb-f2fd-4389-ad64-b68357b12df9</guid><dc:creator>Sarah</dc:creator><description>&lt;p&gt;Yes, you&amp;#39;re right, it causes no problems now. I was probably uploading an old version of my code still. Thanks a lot!
I was wondering why it is that changing the define line doesn&amp;#39;t work in this case? I had changed the define line for APP_BEACON_DEFAULT_ADV_INTERVAL_MS before and that had worked.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Periodically changing the MAC address on nRF51822 Beacon Kit</title><link>https://devzone.nordicsemi.com/thread/25824?ContentTypeID=1</link><pubDate>Thu, 28 May 2015 02:11:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:17b3af3d-37a9-4a70-9cc3-e1e12dcef57c</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;probably because you it returned an error code, there are 5 documented, I&amp;#39;m going to guess NRF_ERROR_INVALID_PARAM. Your code&amp;#39;s wrong anyway, the opt_id is not the value of the option it is, as I wrote earlier, BLE_GAP_OPT_PRIVACY&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;err_code = sd_ble_opt_set( BLE_GAP_OPT_PRIVACY, &amp;amp;opt );
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;if you have to comment out APP_ERROR_CHECK() then you are just ignoring errors.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Periodically changing the MAC address on nRF51822 Beacon Kit</title><link>https://devzone.nordicsemi.com/thread/25823?ContentTypeID=1</link><pubDate>Thu, 28 May 2015 02:05:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:71706f57-5d2f-4c16-b22a-5d366a6e9877</guid><dc:creator>Sarah</dc:creator><description>&lt;p&gt;That seems to be working now. Thanks so much @rols and @ulrich. Why is it that APP_ERROR_CHECK() function call in the middle breaking the code, though?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Periodically changing the MAC address on nRF51822 Beacon Kit</title><link>https://devzone.nordicsemi.com/thread/25822?ContentTypeID=1</link><pubDate>Thu, 28 May 2015 02:01:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:29191947-03bd-46e6-9f56-c0a991eb19ea</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Looks like it always needed a parameter. Not the most beautifully documented unusually, the clue is in the definition of ble_opt_t &lt;a href="https://developer.nordicsemi.com/nRF51_SDK/nRF51_SDK_v7.x.x/doc/7.1.0/s110/html/a00315.html"&gt;here&lt;/a&gt;. BLE_GAP_OPT_PRIVACY appears to the one you want for this.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Periodically changing the MAC address on nRF51822 Beacon Kit</title><link>https://devzone.nordicsemi.com/thread/25825?ContentTypeID=1</link><pubDate>Thu, 28 May 2015 01:57:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:977cba7c-bfca-4243-8b00-5c4f2380c14d</guid><dc:creator>Sarah</dc:creator><description>&lt;p&gt;Thanks so much for your answer, Ulrich. In SDK 7.1, sd_ble_opt_set() expects two arguments. One is an option id, the other one is the ble_opt_t structure. In my case, the opt id needs to be opt.gap_opt.privacy.interval_s . Is that right? I tried your code with that, and if I don&amp;#39;t comment out APP_ERROR_CHECK(err_code) line, the beacon doesn&amp;#39;t work. When I comment it out, it does work, but it doesn&amp;#39;t seem to change the MAC id for the given interval. It seems to be changing randomly. Do you have any idea why? Below is how my code looks like now:&lt;/p&gt;
&lt;p&gt;void periodically_change_mac_address(){
ble_gap_addr_t gap_address;
uint8_t err_code;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    // Change MAC update interval
ble_opt_t opt = {0};
opt.gap_opt.privacy.interval_s = 5;
err_code = sd_ble_opt_set(opt.gap_opt.privacy.interval_s, &amp;amp;opt);
//APP_ERROR_CHECK(err_code);

// Change MAC address
gap_address.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE;
err_code = sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_AUTO, &amp;amp;gap_address);
APP_ERROR_CHECK(err_code);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Periodically changing the MAC address on nRF51822 Beacon Kit</title><link>https://devzone.nordicsemi.com/thread/25826?ContentTypeID=1</link><pubDate>Wed, 27 May 2015 22:38:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d3f7548-a449-48eb-9827-1ff6bce75b1e</guid><dc:creator>Ulrich Myhre</dc:creator><description>&lt;p&gt;Okay, that will not work as expected. The define is not picked up by the SoftDevice in any way, and is just meant to provide the default (initial) parameter that is used. To change the default, you have to call sd_ble_opt_set() like in the edited answer. If not, it will just change every 15 minutes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Periodically changing the MAC address on nRF51822 Beacon Kit</title><link>https://devzone.nordicsemi.com/thread/25827?ContentTypeID=1</link><pubDate>Wed, 27 May 2015 21:35:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:44120355-1611-438b-9f14-9db445cd052a</guid><dc:creator>Sarah</dc:creator><description>&lt;p&gt;I just changed this default line #define BLE_GAP_DEFAULT_PRIVATE_ADDR_CYCLE_INTERVAL_S (60 * 15)  to #define BLE_GAP_DEFAULT_PRIVATE_ADDR_CYCLE_INTERVAL_S (5). I did not use sd_ble_opt_set() function. It looks like this is where the problem is, changing the above default value in the code has no effect. If I wait for 15 minutes, then the MAC address changes. How do I fix this?&lt;/p&gt;
&lt;p&gt;Below is my code for the periodic change. Like I said before, I observe a change in MAC address only when I press SW2 button.&lt;/p&gt;
&lt;p&gt;void periodically_change_mac_address()
{&lt;/p&gt;
&lt;p&gt;ble_gap_addr_t gap_address;
uint8_t err_code;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;gap_address.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE;

err_code = sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_AUTO, &amp;amp;gap_address);
APP_ERROR_CHECK(err_code);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Periodically changing the MAC address on nRF51822 Beacon Kit</title><link>https://devzone.nordicsemi.com/thread/25820?ContentTypeID=1</link><pubDate>Wed, 27 May 2015 21:09:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f725849a-9410-4e50-8f6f-58fcc27fe05a</guid><dc:creator>Ulrich Myhre</dc:creator><description>&lt;p&gt;Hi Sarah,&lt;/p&gt;
&lt;p&gt;The address should change even while advertising, so there is no need to set up any timers for this. Just to make sure: Are you calling sd_ble_opt_set() with gap_opt.privacy.interval_s set to 5, or just changing the define?&lt;/p&gt;
&lt;p&gt;To change the default address rotation time (15 minutes) you have to do something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ble_opt_t opt = {0};
opt.gap_opt.privacy.interval_s = TIME_IN_SECONDS_HERE;
err_code = sd_ble_opt_set(BLE_GAP_OPT_PRIVACY, &amp;amp;opt);
APP_ERROR_CHECK(err_code);
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>