<?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>Connect to device in 2 different ways to distinguish between masters</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/77496/connect-to-device-in-2-different-ways-to-distinguish-between-masters</link><description>My device is the slave, that is being connected (not always in the same order) by 2 masters. 
 I would like to create two different connection ways/points to distinguish between the masters. 
 
 MASTER1 will always connect through &amp;quot;way1.&amp;quot; 
 MASTER 2 will</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 26 Jul 2021 07:34:35 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/77496/connect-to-device-in-2-different-ways-to-distinguish-between-masters" /><item><title>RE: Connect to device in 2 different ways to distinguish between masters</title><link>https://devzone.nordicsemi.com/thread/321713?ContentTypeID=1</link><pubDate>Mon, 26 Jul 2021 07:34:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ecc17b18-6d5c-48b8-97a4-226f4f9ef24c</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;When you configure the advertising payload you can set the handle, and you just need to make sure that you use two unique handle numbers that you can refer to later.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Below is an excerpt from the ble_app_uart example, showing how the handle is set:&lt;br /&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1627284829131v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;In most examples the handle is just set to 1, since there is only one type of advertise packet defined.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In your case you can just use 1 and 2.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connect to device in 2 different ways to distinguish between masters</title><link>https://devzone.nordicsemi.com/thread/321642?ContentTypeID=1</link><pubDate>Sat, 24 Jul 2021 22:04:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:12cee1a1-fcc6-4945-9343-23d3f45d89ee</guid><dc:creator>DS4</dc:creator><description>&lt;p&gt;Thanks, seems like a good&amp;nbsp;solution, and I would like to try it.&lt;/p&gt;
&lt;p&gt;Can you tell me how can I read the handle number from&amp;nbsp;my advertisement packets?&lt;/p&gt;
&lt;p&gt;Its location, or an API I can use to get/set it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connect to device in 2 different ways to distinguish between masters</title><link>https://devzone.nordicsemi.com/thread/321472?ContentTypeID=1</link><pubDate>Fri, 23 Jul 2021 06:32:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:220b4d65-afcf-4eba-90f7-95d70fd31d26</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;You make a fair point, there is a risk if the master connects to you just as you are changing advertise type.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I took a closer look at the ble_gap_evt_connected_t struct:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**@brief Event structure for @ref BLE_GAP_EVT_CONNECTED. */
typedef struct
{
  ble_gap_addr_t        peer_addr;              /**&amp;lt; Bluetooth address of the peer device. If the peer_addr resolved: @ref ble_gap_addr_t::addr_id_peer is set to 1
                                                     and the address is the device&amp;#39;s identity address. */
  uint8_t               role;                   /**&amp;lt; BLE role for this connection, see @ref BLE_GAP_ROLES */
  ble_gap_conn_params_t conn_params;            /**&amp;lt; GAP Connection Parameters. */
  uint8_t               adv_handle;             /**&amp;lt; Advertising handle in which advertising has ended.
                                                     This variable is only set if role is set to @ref BLE_GAP_ROLE_PERIPH. */
  ble_gap_adv_data_t    adv_data;               /**&amp;lt; Advertising buffers corresponding to the terminated
                                                     advertising set. The advertising buffers provided in
                                                     @ref sd_ble_gap_adv_set_configure are now released.
                                                     This variable is only set if role is set to @ref BLE_GAP_ROLE_PERIPH. */
} ble_gap_evt_connected_t;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;It seems that when the master connects to you you will get the advertising handle and data corresponding to the advertising packet that the master connected to.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This means that if your two types of advertising use two unique advertising handles, you should be able to safely determine which advertising packet the master responded to by looking at this field in the connected event.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please note I haven&amp;#39;t tested this myself, since your use case is not a very common one.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connect to device in 2 different ways to distinguish between masters</title><link>https://devzone.nordicsemi.com/thread/321229?ContentTypeID=1</link><pubDate>Thu, 22 Jul 2021 06:22:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:edaf793c-652a-4c6f-875c-8112bb52167e</guid><dc:creator>DS4</dc:creator><description>&lt;p&gt;This solution sounds great, but I feel it might not be prefect.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;quot;&lt;span style="font-family:&amp;#39;times new roman&amp;#39;, times;"&gt;On the slave side you will need to reconfigure the BLE device address periodically. Whenever the connected event occurs you know that the master that connected to you did it over the currently configured BLE device address (which you can map to MAC1 and MAC2).&amp;quot;&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;My concern about this solution is of a race.&lt;/p&gt;
&lt;p&gt;By the time the connection ISR occurs, I may already change the system MAC.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Is there a way to get this 100% accurate?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Maybe a different ISR? Or a&amp;nbsp; way to read the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;destination&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;MAC address from the masters packets? Or any other way..&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connect to device in 2 different ways to distinguish between masters</title><link>https://devzone.nordicsemi.com/thread/320667?ContentTypeID=1</link><pubDate>Mon, 19 Jul 2021 11:41:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6f8953f8-5df6-4f93-a954-da64840b8893</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The most reliable way to do this is to change the BLE device address on the advertising side, instead of just changing a value in the advertising payload.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When the application on the master side tells the stack to establish a connection you use the BLE device address to decide which advertiser to connect to, so this is the most reliable way to ensure that the master connects to the right advertiser.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;On the slave side you will need to reconfigure the BLE device address periodically. Whenever the connected event occurs you know that the master that connected to you did it over the currently configured BLE device address (which you can map to MAC1 and MAC2).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connect to device in 2 different ways to distinguish between masters</title><link>https://devzone.nordicsemi.com/thread/320549?ContentTypeID=1</link><pubDate>Sun, 18 Jul 2021 06:27:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d004df90-5a52-4399-b8b2-3a00ac03aacd</guid><dc:creator>DS4</dc:creator><description>&lt;p&gt;Hi thanks again,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The peer address is how the master saved my address?&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;What I meant is supposedly I am advertising alternating &amp;quot;MAC1&amp;quot; and &amp;quot;MAC2&amp;quot;.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Started advertising.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Salve gets an ISR connection.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;How can the slave know (100%), if this ISR master connected through MAC1 or MAC2?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connect to device in 2 different ways to distinguish between masters</title><link>https://devzone.nordicsemi.com/thread/320375?ContentTypeID=1</link><pubDate>Fri, 16 Jul 2021 08:23:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cfbf4876-276d-429a-b98b-b7631f0df4af</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;When you establish a connection the BLE_GAP_EVT_CONNECTED event will occur, and in this event you can read out the BLE address of the peer device that you just connected to.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Assuming the ble_event_handler is implemented as in the standard examples you can get access to the peer address like this:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;p_ble_evt-&amp;gt;evt.gap_evt.params.connected.peer_addr&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connect to device in 2 different ways to distinguish between masters</title><link>https://devzone.nordicsemi.com/thread/320299?ContentTypeID=1</link><pubDate>Thu, 15 Jul 2021 14:12:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ff109163-f920-434e-a8c8-db04959407ff</guid><dc:creator>DS4</dc:creator><description>&lt;p&gt;Thanks!&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Propriety characteristic can definitely work.&lt;/p&gt;
&lt;p&gt;But our goal is to keep it simple on the master side, and do the work on the slave.&lt;/p&gt;
&lt;p&gt;(We considered&amp;nbsp;scanning and reading the masters ID characteristics)&lt;/p&gt;
&lt;p&gt;But before that would like to test the alternation method.&lt;/p&gt;
&lt;p&gt;For that it is important for me to know through which MAC the master&amp;#39;s were &lt;span style="text-decoration:underline;"&gt;initially connected.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Can I get that info? if yes, how?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connect to device in 2 different ways to distinguish between masters</title><link>https://devzone.nordicsemi.com/thread/320240?ContentTypeID=1</link><pubDate>Thu, 15 Jul 2021 12:07:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:14690b40-33eb-46ac-91d0-86be659e2da0</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Can&amp;#39;t you just have MASTER1 and MASTER2 send a data packet once the connection have been established, to identify themselves to the slave as either MASTER1 or MASTER2?&lt;/p&gt;
&lt;p&gt;To do this you can set up a proprietary characteristic for this specific purpose, and the master can send a data update on this characteristic.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It should also be possible to do as you say and have the slave alternate between two advertise packets,&amp;nbsp;but this would make the code on the slave side a bit more complex.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>