<?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>When using nRF MESH, two BLE event handlers being called</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/46331/when-using-nrf-mesh-two-ble-event-handlers-being-called</link><description>Hi, 
 I have set a Mesh Client Node with two BLE services: Mesh Proxy Service and Nordic Uart Service. 
 The problem is that when I send a message to the Mesh Client from nRF Mesh app (for example, binding the Appkey, or the setting the publication address</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 13 May 2019 09:14:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/46331/when-using-nrf-mesh-two-ble-event-handlers-being-called" /><item><title>RE: When using nRF MESH, two BLE event handlers being called</title><link>https://devzone.nordicsemi.com/thread/186610?ContentTypeID=1</link><pubDate>Mon, 13 May 2019 09:14:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fd76fb2a-c373-440b-a841-962345887ef7</guid><dc:creator>david_owtschinnikow</dc:creator><description>&lt;p&gt;&lt;span&gt;Hi&amp;nbsp;&lt;/span&gt;&lt;span&gt;Bj&amp;oslash;rn, the example is working fine with this approach. Thank you for your help.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: When using nRF MESH, two BLE event handlers being called</title><link>https://devzone.nordicsemi.com/thread/186429?ContentTypeID=1</link><pubDate>Fri, 10 May 2019 12:40:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:43b11c01-b876-44d9-a058-354eb077089d</guid><dc:creator>Bj&amp;#248;rn Kvaale</dc:creator><description>&lt;p&gt;I can&amp;#39;t think of anything wrong with having a global_on_ble_evt event handler function, as long as you correctly filter out the events correctly for UART &amp;amp; for the proxy service. Maybe one of these links may be helpful: &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/45878/tutorial-request---proxy-service-and-ble-service-merging"&gt;link 1&lt;/a&gt;, &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/41984/proxy-node-with-ble_uart-coexist/166709"&gt;link 2&lt;/a&gt;, &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/38211/multiple-advertising-sets-error---nrf52832"&gt;link 3&lt;/a&gt;. If you cannot get it working, I can see if I can&amp;nbsp;set off a few hours to see if I can get an example working with GATT proxy &amp;amp; UART.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: When using nRF MESH, two BLE event handlers being called</title><link>https://devzone.nordicsemi.com/thread/185512?ContentTypeID=1</link><pubDate>Mon, 06 May 2019 13:26:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bf0cf8d2-89ba-442a-931f-b9fb97908755</guid><dc:creator>david_owtschinnikow</dc:creator><description>&lt;p&gt;Hi &lt;span&gt;Bj&amp;oslash;rn, thank you for your answer&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The&amp;nbsp;problem&amp;nbsp;with&amp;nbsp;coexist example is that is doesn&amp;#39;t implement Mesh Provisioning service (let&amp;#39;s call it Mesh Proxy), which shares the &amp;quot;write&amp;quot; BLE event with ble_nus. The Mesh Provisioning service adds a new observer and its handler (mesh_gatt_on_ble_evt), so when either nus or mesh proxy write something, both write handlers are called (on_write for NUS&amp;nbsp; and write_evt_handle for Mesh Proxy).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I am debugging the &amp;quot;global_on_ble_evt&amp;quot; (handler for both Mesh proxy and NUS) that I wrote on a previous post, but I&amp;#39;m not sure this is the right way to do it.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: When using nRF MESH, two BLE event handlers being called</title><link>https://devzone.nordicsemi.com/thread/185501?ContentTypeID=1</link><pubDate>Mon, 06 May 2019 12:48:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e4a09edb-7908-4af0-a2d7-2f913b98fe60</guid><dc:creator>Bj&amp;#248;rn Kvaale</dc:creator><description>&lt;p&gt;Sorry for the delayed response. I have been busy with other support activity unfortunately. I totally forgot that we have a &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.meshsdk.v3.1.0/md_examples_sdk_coexist_ble_app_uart_coexist_README.html?cp=5_1_3_5_1"&gt;SDK UART coexistence example here,&lt;/a&gt; which does exactly what you want to do!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;ble_nus has a NRF_SDH_BLE_OBSERVER &amp;amp; a related ble_nus_on_ble_evt event handler. ble_gatt also has a BLE observer with the nrf_ble_gatt_on_ble_evt event handler. I would recommend taking a look at the example for more details.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: When using nRF MESH, two BLE event handlers being called</title><link>https://devzone.nordicsemi.com/thread/184083?ContentTypeID=1</link><pubDate>Fri, 26 Apr 2019 12:53:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3b339bd9-00ca-4ae9-ada1-12649e71166f</guid><dc:creator>david_owtschinnikow</dc:creator><description>&lt;p&gt;Thanks for your reply!&lt;/p&gt;
&lt;p&gt;If I am not wrong,&amp;nbsp;&amp;nbsp;the difference&amp;nbsp;between my project and the one you referenced (&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/29108/how-to-add-mesh-into-nrf5-sdk-v14-1-v15-ble-application"&gt;light switch example with the nordic uart example&lt;/a&gt;) is that this example has only one BLE service (NUS),&amp;nbsp;but mine has two: Mesh Provisioning Service and NUS.&lt;/p&gt;
&lt;p&gt;I now have one &amp;quot;global_on_ble_evt&amp;quot; handler (at the bottom of this post), which handles both services. But I still don&amp;#39;t know where (inside parameters p_ble_evt and/or p_context) is the handle that each ble event addresses; I need this to be able to run different&amp;nbsp;handlers for each ble event, for example BLE_GATTS_EVT_WRITE and BLE_GATTS_EVT_HVN_TX_COMPLETE.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;(I found that my problem is the same as&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/36821/how-to-run-proxy-and-nus-at-the-same-time"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/36821/how-to-run-proxy-and-nus-at-the-same-time&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;What I have done up to now is the following:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have deleted the NUS Observer:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;//NRF_SDH_BLE_OBSERVER(m_nus_obs, BLE_NUS_BLE_OBSERVER_PRIO, ble_nus_on_ble_evt, &amp;amp;m_nus);&lt;/pre&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt; and only work with the observer created for Mesh service:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;NRF_SDH_BLE_OBSERVER(m_gatt_obs, NRF_MESH_GATT_BLE_OBSERVER_PRIO, global_on_ble_evt, &amp;amp;m_gatt);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This observer listens to ble events from Mesh Service and from Nus.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The global_on_ble_evt is the following:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void global_on_ble_evt(ble_evt_t const *p_ble_evt, void *p_context) {

  ble_gatts_evt_write_t const *p_evt_write = &amp;amp;p_ble_evt-&amp;gt;evt.gatts_evt.params.write;
  ble_nus_t *p_nus = (ble_nus_t *)p_context;
  if (p_nus-&amp;gt;tx_handles.value_handle &amp;gt;= 0x2AD0) { //This is a provisional way to distinguish between Mesh service and Nus service
    //MESH SERVICE EVENT
    switch (p_ble_evt-&amp;gt;header.evt_id) {
    case BLE_GAP_EVT_CONNECTED:
      connect_evt_handle(p_ble_evt);
      break;
    case BLE_GAP_EVT_DISCONNECTED:
      disconnect_evt_handle(p_ble_evt);
      break;
#if NRF_SD_BLE_API_VERSION == 6
    case BLE_GAP_EVT_ADV_SET_TERMINATED:
      if (p_ble_evt-&amp;gt;evt.gap_evt.params.adv_set_terminated.reason ==
          BLE_GAP_EVT_ADV_SET_TERMINATED_REASON_TIMEOUT) {
        mesh_gatt_evt_t evt;
        evt.type = MESH_GATT_EVT_TYPE_ADV_TIMEOUT;
        evt.conn_index = p_ble_evt-&amp;gt;evt.gap_evt.conn_handle;
        m_gatt.evt_handler(&amp;amp;evt, m_gatt.p_context);
      }
      break;
#elif NRF_SD_BLE_API_VERSION &amp;lt;= 5
    case BLE_GAP_EVT_TIMEOUT:
      if (p_ble_evt-&amp;gt;evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISING) {
        mesh_gatt_evt_t evt;
        evt.type = MESH_GATT_EVT_TYPE_ADV_TIMEOUT;
        evt.conn_index = p_ble_evt-&amp;gt;evt.gap_evt.conn_handle;
        m_gatt.evt_handler(&amp;amp;evt, m_gatt.p_context);
      }
      break;
#else
#error Unsupported SoftDevice version
#endif
    case BLE_GATTS_EVT_WRITE:
      write_evt_handle(p_ble_evt);
      break;

    case BLE_GATTS_EVT_HVN_TX_COMPLETE:
      tx_complete_handle(p_ble_evt-&amp;gt;evt.gatts_evt.conn_handle);
      break;

    /* TODO: The following events should be handled by an SDK module/the application. */
    case BLE_GATTS_EVT_SYS_ATTR_MISSING: {
      /* This call might have been called already as a result of a failing gatts call, ignore the error code. */
      (void)sd_ble_gatts_sys_attr_set(p_ble_evt-&amp;gt;evt.gatts_evt.conn_handle, NULL, 0, 0);
      break;
    }

    case BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST: {
      ble_gap_data_length_params_t dl_params;
      memset(&amp;amp;dl_params, BLE_GAP_DATA_LENGTH_AUTO, sizeof(dl_params));
      NRF_MESH_ERROR_CHECK(sd_ble_gap_data_length_update(p_ble_evt-&amp;gt;evt.gap_evt.conn_handle,
          &amp;amp;dl_params,
          NULL));
      break;
    }

    case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
      NRF_MESH_ERROR_CHECK(sd_ble_gap_sec_params_reply(p_ble_evt-&amp;gt;evt.gap_evt.conn_handle,
          BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP,
          NULL,
          NULL));
      break;

    case BLE_GAP_EVT_PHY_UPDATE_REQUEST: {
      ble_gap_phys_t const phys =
          {
              .rx_phys = BLE_GAP_PHY_AUTO,
              .tx_phys = BLE_GAP_PHY_AUTO,
          };
      NRF_MESH_ERROR_CHECK(sd_ble_gap_phy_update(p_ble_evt-&amp;gt;evt.gap_evt.conn_handle, &amp;amp;phys));
      break;
    }

    case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST:
      exchange_mtu_req_handle(p_ble_evt);
      break;

    case BLE_GATTS_EVT_SC_CONFIRM:
      break;

    default:
      break;
    }
    if ((p_context == NULL) || (p_ble_evt == NULL)) {
      return;
    }

  } else { //NUS EVENT

    switch (p_ble_evt-&amp;gt;header.evt_id) {
    case BLE_GAP_EVT_CONNECTED:
      on_connect(p_nus, p_ble_evt);
      break;

    case BLE_GATTS_EVT_WRITE:
      on_write(p_nus, p_ble_evt);
      break;

    case BLE_GATTS_EVT_HVN_TX_COMPLETE:
      on_hvx_tx_complete(p_nus, p_ble_evt);
      break;

    default:
      // No implementation needed.
      break;
    }
  }
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;(With both Mesh Service and NUService ble events this function only enters the first if condition).&lt;/p&gt;
&lt;p&gt;With this changes I can provision the node with nRF Mesh app,&amp;nbsp;but the NUS service&amp;nbsp;&lt;span&gt;BLE_GATTS_EVT_WRITE and&amp;nbsp;&lt;/span&gt;&lt;span&gt;BLE_GATTS_EVT_HVN_TX_COMPLETE handlers (&lt;strong&gt;on_write&lt;/strong&gt; and &lt;strong&gt;on_hvx_tx_complete&lt;/strong&gt;) are never&amp;nbsp;run.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;As I mentioned,&amp;nbsp;&lt;span&gt;I still don&amp;#39;t know where (inside parameters p_ble_evt and/or p_context) is the handle that each ble event addresses. Knowing this could let me distinguish between a&amp;nbsp;NUS event and a MESH ble event.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Can you help me?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Thank you very much&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: When using nRF MESH, two BLE event handlers being called</title><link>https://devzone.nordicsemi.com/thread/183455?ContentTypeID=1</link><pubDate>Wed, 24 Apr 2019 12:38:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f770091a-7f23-4033-a277-4a2c090b4670</guid><dc:creator>Bj&amp;#248;rn Kvaale</dc:creator><description>&lt;p&gt;Due to the Easter holiday, response time can be slower than usual. Sorry for any inconvenience caused by this! It seems that both functions interpret the smartphone message as a regular BLE event, even if you are sending to the mesh proxy service characteristic.&lt;/p&gt;
&lt;p&gt;One of our application engineers has made an example combining the &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/29108/how-to-add-mesh-into-nrf5-sdk-v14-1-v15-ble-application"&gt;light switch example with the nordic uart example&lt;/a&gt; like you have done. Having looked at his code, it seems that he has one ble event handler. This makes sense, as both mesh_gatt_on_ble_evt() from the mesh example &amp;amp; ble_nus_on_ble_evt() from Nordic UART service do look very similar (i.e. they have the same function parameters).&lt;/p&gt;
&lt;p&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.meshsdk.v3.1.0/md_doc_getting_started_how_to_nordicSDK.html?cp=5_1_1_10"&gt;This documentation&lt;/a&gt; may also be helpful if you have not seen it yet.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>