<?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>the connected callback function is called 3 times when my Periphreal connecte to Central.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/99962/the-connected-callback-function-is-called-3-times-when-my-periphreal-connecte-to-central</link><description>the connected callback function is called multiple times when it connects to the central, how to configure it only get one connected callback call?</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 31 May 2023 02:27:41 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/99962/the-connected-callback-function-is-called-3-times-when-my-periphreal-connecte-to-central" /><item><title>RE: the connected callback function is called 3 times when my Periphreal connecte to Central.</title><link>https://devzone.nordicsemi.com/thread/428295?ContentTypeID=1</link><pubDate>Wed, 31 May 2023 02:27:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:92cffbb9-be0e-48d5-8b8d-36141bc9ccca</guid><dc:creator>steveqin</dc:creator><description>&lt;p&gt;I think I fixed this problem, the reason is I moved the advertisement code into a subfile, it caused this problem, after I move back to the main file, it&amp;#39;s correct now.&lt;/p&gt;
&lt;p&gt;thanks,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: the connected callback function is called 3 times when my Periphreal connecte to Central.</title><link>https://devzone.nordicsemi.com/thread/426580?ContentTypeID=1</link><pubDate>Mon, 22 May 2023 13:00:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df955f75-2d92-4e42-9680-8fed7d9ee7df</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Steve,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you try remove the peripheral role of the application ? Only do central ?&lt;br /&gt;&lt;br /&gt;Maybe you can print out the information inside&amp;nbsp;&lt;span&gt;conn struct in the connected() callback. We want to check if it&amp;#39;s the same connection getting multiple callbacks or it&amp;#39;s different connections.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Could you try testing with a central sample in the SDK to see if you have the same problem ?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: the connected callback function is called 3 times when my Periphreal connecte to Central.</title><link>https://devzone.nordicsemi.com/thread/426532?ContentTypeID=1</link><pubDate>Mon, 22 May 2023 11:41:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:969bf749-a808-4669-8df9-6c7990ccd4cd</guid><dc:creator>steveqin</dc:creator><description>&lt;p&gt;the peripheral code is based on the peripheral uart example, the &amp;quot;connected&amp;quot; printout inside the connected callback function.&lt;/p&gt;
&lt;p&gt;the central code is based on this link&amp;nbsp;&lt;a id="" href="https://github.com/ThatByDesign/zephyr/tree/dual_role/samples/bluetooth/central_hr_peripheral_ht"&gt;https://github.com/ThatByDesign/zephyr/tree/dual_role/samples/bluetooth/central_hr_peripheral_ht&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;the red circle cause multiple peripheral connected.&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:669px;max-width:485px;" height="669" src="https://devzone.nordicsemi.com/resized-image/__size/970x1338/__key/communityserver-discussions-components-files/4/pastedimage1684755676253v1.png" width="485" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;static void connected(struct bt_conn *conn, uint8_t err)&lt;br /&gt;{&lt;br /&gt; char addr[BT_ADDR_LE_STR_LEN];&lt;/p&gt;
&lt;p&gt;if (err) {&lt;br /&gt; LOG_ERR(&amp;quot;Connection failed (err %u)&amp;quot;, err);&lt;br /&gt; return;&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));&lt;br /&gt; LOG_INF(&amp;quot;Connected %s&amp;quot;, log_strdup(addr));&lt;br /&gt; printk(&amp;quot;connected.\n&amp;quot;);&lt;/p&gt;
&lt;p&gt;current_conn = bt_conn_ref(conn);&lt;/p&gt;
&lt;p&gt;// dk_set_led_on(CON_STATUS_LED);&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;static void disconnected(struct bt_conn *conn, uint8_t reason)&lt;br /&gt;{&lt;br /&gt; char addr[BT_ADDR_LE_STR_LEN];&lt;/p&gt;
&lt;p&gt;bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));&lt;/p&gt;
&lt;p&gt;LOG_INF(&amp;quot;Disconnected: %s (reason %u)&amp;quot;, log_strdup(addr), reason);&lt;br /&gt; printk(&amp;quot;disconnected.\n&amp;quot;);&lt;br /&gt; pairebondedFlag = false;&lt;br /&gt; gpio_pin_set_dt(&amp;amp;bleled, 1);&lt;/p&gt;
&lt;p&gt;if (auth_conn) {&lt;br /&gt; bt_conn_unref(auth_conn);&lt;br /&gt; auth_conn = NULL;&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;if (current_conn) {&lt;br /&gt; bt_conn_unref(current_conn);&lt;br /&gt; current_conn = NULL;&lt;br /&gt; // dk_set_led_off(CON_STATUS_LED);&lt;br /&gt; }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;static void security_changed(struct bt_conn *conn, bt_security_t level,&lt;br /&gt; enum bt_security_err err)&lt;br /&gt;{&lt;br /&gt; char addr[BT_ADDR_LE_STR_LEN];&lt;/p&gt;
&lt;p&gt;bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));&lt;/p&gt;
&lt;p&gt;if (!err) {&lt;br /&gt; LOG_INF(&amp;quot;Security changed: %s level %u&amp;quot;, log_strdup(addr),&lt;br /&gt; level);&lt;/p&gt;
&lt;p&gt;printk(&amp;quot;Security changed.\n&amp;quot;);&lt;br /&gt; pairbond_start();&lt;br /&gt; pairebondedFlag = true;&lt;br /&gt; gpio_pin_set_dt(&amp;amp;bleled, 0);&lt;br /&gt; &lt;br /&gt; } else {&lt;br /&gt; LOG_WRN(&amp;quot;Security failed: %s level %u err %d&amp;quot;, log_strdup(addr),&lt;br /&gt; level, err);&lt;/p&gt;
&lt;p&gt;printk(&amp;quot;Secutrity failed.\n&amp;quot;);&lt;br /&gt; bt_conn_disconnect(conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN);&lt;/p&gt;
&lt;p&gt;}&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;BT_CONN_CB_DEFINE(conn_callbacks) = {&lt;br /&gt; .connected = connected,&lt;br /&gt; .disconnected = disconnected,&lt;br /&gt; .security_changed = security_changed,&lt;/p&gt;
&lt;p&gt;};&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: the connected callback function is called 3 times when my Periphreal connecte to Central.</title><link>https://devzone.nordicsemi.com/thread/426475?ContentTypeID=1</link><pubDate>Mon, 22 May 2023 09:10:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:965e00e7-28d4-4f25-8f4d-51268c3e89ba</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Steve,&amp;nbsp;&lt;br /&gt;Do you see the same issue if you test with one of our sample in the SDK ? I assume you are using nRF Connect SDK ?&amp;nbsp;&lt;br /&gt;Could you show your code where you print &amp;quot;connected&amp;quot; out ?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>