<?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>Turn LED off when not advertising nrf 52840 PCA10059 SDK 15.3</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/51064/turn-led-off-when-not-advertising-nrf-52840-pca10059-sdk-15-3</link><description>Good day 
 Im trying to switch off an LED when my relay/hopper is not advertising. I switch the LED on successfully when transmission starts but I&amp;#39;m struggling to do the sd_ble_gap_adv_stop check to switch the led off. This is a simple relay/hopper and</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 20 Aug 2019 15:19:14 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/51064/turn-led-off-when-not-advertising-nrf-52840-pca10059-sdk-15-3" /><item><title>RE: Turn LED off when not advertising nrf 52840 PCA10059 SDK 15.3</title><link>https://devzone.nordicsemi.com/thread/205112?ContentTypeID=1</link><pubDate>Tue, 20 Aug 2019 15:19:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:db81ecb7-86d4-48f5-8d34-ffa898d89fa0</guid><dc:creator>melt</dc:creator><description>&lt;p&gt;Thank you, Edvin&lt;/p&gt;
&lt;p&gt;I&amp;nbsp;did as suggested. Created a timer that turns the LED off.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Turn LED off when not advertising nrf 52840 PCA10059 SDK 15.3</title><link>https://devzone.nordicsemi.com/thread/204545?ContentTypeID=1</link><pubDate>Fri, 16 Aug 2019 14:36:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:992c15a8-57a4-47db-bb0b-813d77f1093e</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Ok, so you don&amp;#39;t include the files ble_advertising.c/h at all? If you want to use the advertising events, I suggest that you include this file, and use this module. What this does is that it registers ble_advertising_on_ble_evt() as an event handler for the softdevice.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Otherwise, I believe the only way to determine whether you are advertising or not is to start a timer with the same duration as your advertising timeout. Alternatively, don&amp;#39;t set an advertising timeout, but start a timer to manually stop the advertising using sd_ble_gap_adv_stop, and at the same time turn off the LED.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Turn LED off when not advertising nrf 52840 PCA10059 SDK 15.3</title><link>https://devzone.nordicsemi.com/thread/204537?ContentTypeID=1</link><pubDate>Fri, 16 Aug 2019 14:02:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b5140d8c-be32-437b-bdff-874486b1c002</guid><dc:creator>melt</dc:creator><description>&lt;p&gt;correct, that is wehere im turning the LED on + set the timeout&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void advertising_init(void) // no more than 31 bytes 
{  
    uint32_t      err_code;
    ble_advdata_t advdata; // no more than 31 bytes
    uint8_t       flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;

    ble_advdata_manuf_data_t manuf_specific_data;
    manuf_specific_data.company_identifier =  APP_COMPANY_IDENTIFIER;
    manuf_specific_data.data.p_data = (uint8_t *) m_beacon_info;

        if (g_setAdvData) // if a mac address is received from a beacon build a payload consisting of repeater mac + beacon mac
    {  

        //mac address of the repeater (this device) added to payload
        manuf_specific_data.data.p_data [6]=repeater_mac_addr.addr[0]; // Local mac address
        manuf_specific_data.data.p_data [7]=repeater_mac_addr.addr[1]; // Local mac address
        manuf_specific_data.data.p_data [8]=repeater_mac_addr.addr[2]; // Local mac address
        manuf_specific_data.data.p_data [9]=repeater_mac_addr.addr[3]; // Local mac address
        manuf_specific_data.data.p_data [10]=repeater_mac_addr.addr[4]; // Local mac address
        manuf_specific_data.data.p_data [11]=repeater_mac_addr.addr[5]; // Local mac address 
        //cant go higher than 22
       
       //mac address of the beacon (received by this device) added to payload
        manuf_specific_data.data.p_data [12]= Beacon_mac_addr[0]; // Beacon MAC address
        manuf_specific_data.data.p_data [13]= Beacon_mac_addr[1]; // Beacon MAC address
        manuf_specific_data.data.p_data [14]= Beacon_mac_addr[2]; // Beacon MAC address
        manuf_specific_data.data.p_data [15]= Beacon_mac_addr[3]; // Beacon MAC address
        manuf_specific_data.data.p_data [16]= Beacon_mac_addr[4]; // Beacon MAC address
        manuf_specific_data.data.p_data [17]= Beacon_mac_addr[5]; // Beacon MAC address
      
           g_setAdvData = false; // turn off the set adv data and wait for next mac to come
   }

//shows the manuf payload of ble 
/*NRF_LOG_RAW_INFO(&amp;quot;%02x%02X%02X%02X%02X\n&amp;quot;,
                    manuf_specific_data.data.p_data [15], manuf_specific_data.data.p_data [16],
                    manuf_specific_data.data.p_data [17], manuf_specific_data.data.p_data [18],
                    manuf_specific_data.data.p_data [19], manuf_specific_data.data.p_data [20]);*/

NRF_LOG_RAW_INFO(&amp;quot;Re-transmitting initial scanner MAC %02x:%02x:%02x:%02x:%02x:%02x &amp;quot;,initial_scanner_mac_addr[5], initial_scanner_mac_addr[4], initial_scanner_mac_addr[3], initial_scanner_mac_addr[2], initial_scanner_mac_addr[1], initial_scanner_mac_addr[0])
NRF_LOG_RAW_INFO(&amp;quot;Re-transmitting  Beacon found MAC  %02x:%02x:%02x:%02x:%02x:%02x\r\n&amp;quot;,Beacon_mac_addr[0], Beacon_mac_addr[1], Beacon_mac_addr[2], Beacon_mac_addr[3], Beacon_mac_addr[4], Beacon_mac_addr[5])
        
        nrf_gpio_pin_clear(NRF_GPIO_PIN_MAP(1, 9)); // green led  on to show advertising is on the go 
    //   nrf_delay_ms(10);
    //   nrf_gpio_pin_set(NRF_GPIO_PIN_MAP(1, 9)); // green led  off

    manuf_specific_data.data.size   = APP_BEACON_INFO_LENGTH;

    // Build and set advertising data.
    memset(&amp;amp;advdata, 0, sizeof(advdata));

    advdata.name_type             = BLE_ADVDATA_NO_NAME;
    advdata.flags                 = flags;
    advdata.p_manuf_specific_data = &amp;amp;manuf_specific_data;

    // Initialize advertising parameters (used when starting advertising).
    memset(&amp;amp;m_adv_params, 0, sizeof(m_adv_params));

    m_adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
    m_adv_params.p_peer_addr     = NULL;    // Undirected advertisement.
    m_adv_params.filter_policy   = BLE_GAP_ADV_FP_ANY;
    m_adv_params.interval        = NON_CONNECTABLE_ADV_INTERVAL;
    m_adv_params.duration        = 300;       // time out

    err_code = ble_advdata_encode(&amp;amp;advdata, m_adv_data.adv_data.p_data, &amp;amp;m_adv_data.adv_data.len);
    APP_ERROR_CHECK(err_code);

    err_code = sd_ble_gap_adv_set_configure(&amp;amp;m_adv_handle, &amp;amp;m_adv_data, &amp;amp;m_adv_params);
    APP_ERROR_CHECK(err_code);
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Turn LED off when not advertising nrf 52840 PCA10059 SDK 15.3</title><link>https://devzone.nordicsemi.com/thread/204536?ContentTypeID=1</link><pubDate>Fri, 16 Aug 2019 13:48:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fe8360f1-51d2-4851-b255-de815f699718</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;If you are advertising, then that is as a peripheral.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You are probably have a function called advertising_init()?&lt;/p&gt;
&lt;p&gt;does this do something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void advertising_init(void)
{
    uint32_t               err_code;
    ble_advertising_init_t init;

    memset(&amp;amp;init, 0, sizeof(init));

    init.advdata.name_type               = BLE_ADVDATA_FULL_NAME;
    init.advdata.include_appearance      = true;
    init.advdata.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
    init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    init.advdata.uuids_complete.p_uuids  = m_adv_uuids;

    init.config.ble_adv_fast_enabled  = true;
    init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
    init.config.ble_adv_fast_timeout  = APP_ADV_DURATION;

    init.evt_handler = on_adv_evt;

    err_code = ble_advertising_init(&amp;amp;m_advertising, &amp;amp;init);
    APP_ERROR_CHECK(err_code);

    ble_advertising_conn_cfg_tag_set(&amp;amp;m_advertising, APP_BLE_CONN_CFG_TAG);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Is that correct? If not, may I see how you initialize your advertisements?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Turn LED off when not advertising nrf 52840 PCA10059 SDK 15.3</title><link>https://devzone.nordicsemi.com/thread/204535?ContentTypeID=1</link><pubDate>Fri, 16 Aug 2019 13:44:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4465cfbe-12db-4d03-9c0a-e5b62c6f71ed</guid><dc:creator>melt</dc:creator><description>&lt;p&gt;Thanks, Edvin, what if I&amp;#39;m running Central?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I have the below but I&amp;#39;m using non-connectable so none of the below cases seem to be entered.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;//@brief Function for handling BLE events.
 /*
 * @param[in]   p_ble_evt   Bluetooth stack event.
 * @param[in]   p_context   Unused.
 */
static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    ret_code_t            err_code;
    ble_gap_evt_t const * p_gap_evt = &amp;amp;p_ble_evt-&amp;gt;evt.gap_evt;

uint8_array_t adv_data;

    switch (p_ble_evt-&amp;gt;header.evt_id)
    { 
  

        case BLE_GAP_EVT_CONNECTED:
            err_code = ble_nus_c_handles_assign(&amp;amp;m_ble_nus_c, p_ble_evt-&amp;gt;evt.gap_evt.conn_handle, NULL);
            APP_ERROR_CHECK(err_code);

            err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
            APP_ERROR_CHECK(err_code);

            // start discovery of services. The NUS Client waits for a discovery result
            err_code = ble_db_discovery_start(&amp;amp;m_db_disc, p_ble_evt-&amp;gt;evt.gap_evt.conn_handle);
            APP_ERROR_CHECK(err_code);
            break;

        case BLE_GAP_EVT_DISCONNECTED:

            NRF_LOG_INFO(&amp;quot;Disconnected. conn_handle: 0x%x, reason: 0x%x&amp;quot;,
                         p_gap_evt-&amp;gt;conn_handle,
                         p_gap_evt-&amp;gt;params.disconnected.reason);
                      /* nrf_gpio_pin_clear(NRF_GPIO_PIN_MAP(1, 0)); // set red red led
                         nrf_delay_ms(5);
                         nrf_gpio_pin_set(NRF_GPIO_PIN_MAP(1, 0)); // clear red red led*/
                          
            break;

        case BLE_GAP_EVT_TIMEOUT:
            if (p_gap_evt-&amp;gt;params.timeout.src == BLE_GAP_TIMEOUT_SRC_CONN)
            {
                NRF_LOG_INFO(&amp;quot;Connection Request timed out.&amp;quot;);
             /*   nrf_gpio_pin_clear(NRF_GPIO_PIN_MAP(1, 0)); // set red red led
                nrf_delay_ms(5);
                nrf_gpio_pin_set(NRF_GPIO_PIN_MAP(1, 0)); // clear red red led*/
                
            }
            break;

        case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
            // Pairing not supported.
            err_code = 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);
            APP_ERROR_CHECK(err_code);
             nrf_gpio_pin_set(NRF_GPIO_PIN_MAP(1, 9)); // switch off green led
            break;

        case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST:
            // Accepting parameters requested by peer.
            err_code = sd_ble_gap_conn_param_update(p_gap_evt-&amp;gt;conn_handle,
                                                    &amp;amp;p_gap_evt-&amp;gt;params.conn_param_update_request.conn_params);
            APP_ERROR_CHECK(err_code);
            break;

        case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
        {
            NRF_LOG_DEBUG(&amp;quot;PHY update request.&amp;quot;);
            ble_gap_phys_t const phys =
            {
                .rx_phys = BLE_GAP_PHY_AUTO,
                .tx_phys = BLE_GAP_PHY_AUTO,
            };
            err_code = sd_ble_gap_phy_update(p_ble_evt-&amp;gt;evt.gap_evt.conn_handle, &amp;amp;phys);
            APP_ERROR_CHECK(err_code);
        } break;

        case BLE_GATTC_EVT_TIMEOUT:
            // Disconnect on GATT Client timeout event.
            NRF_LOG_DEBUG(&amp;quot;GATT Client Timeout.&amp;quot;);
            err_code = sd_ble_gap_disconnect(p_ble_evt-&amp;gt;evt.gattc_evt.conn_handle,
                                             BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            APP_ERROR_CHECK(err_code);
             
            break;

        case BLE_GATTS_EVT_TIMEOUT:
            // Disconnect on GATT Server timeout event.
            NRF_LOG_DEBUG(&amp;quot;GATT Server Timeout.&amp;quot;);
            err_code = sd_ble_gap_disconnect(p_ble_evt-&amp;gt;evt.gatts_evt.conn_handle,
                                             BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            APP_ERROR_CHECK(err_code);
            
             
            break;
            
// Here we get the BLE data, 
            case BLE_GAP_EVT_ADV_REPORT:
         {//NRF_LOG_RAW_HEXDUMP_INFO (m_scan.scan_buffer.p_data, m_scan.scan_buffer.len);

                adv_data.size = p_gap_evt-&amp;gt;params.adv_report.data.len;

                memmove(RX_Data, p_gap_evt-&amp;gt;params.adv_report.data.p_data, p_gap_evt-&amp;gt;params.adv_report.data.len);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Turn LED off when not advertising nrf 52840 PCA10059 SDK 15.3</title><link>https://devzone.nordicsemi.com/thread/204499?ContentTypeID=1</link><pubDate>Fri, 16 Aug 2019 12:09:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9730e7a0-c3bd-4899-b6d8-c5671a28afda</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Ok, then I suggest you turn off the led in your adverisement callback: on_adv_evt() in main.c (at least that is where it is located in the examples.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;From the ble_peripheral examples you have this function:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief Function for handling advertising events.
 *
 * @param[in] ble_adv_evt  Advertising event.
 */
static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
{
    ret_code_t err_code;

    switch (ble_adv_evt)
    {
        case BLE_ADV_EVT_FAST:
            NRF_LOG_INFO(&amp;quot;Fast advertising&amp;quot;);
            err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
            APP_ERROR_CHECK(err_code);
            break; // BLE_ADV_EVT_FAST

        case BLE_ADV_EVT_IDLE:
            sleep_mode_enter();
            break; // BLE_ADV_EVT_IDLE

        default:
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Add the line that turns off the LED in the BLE_ADV_EVT_IDLE event, which is the one that is called when the advertising times out.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;EDIT: add it&amp;nbsp;&lt;strong&gt;before&lt;/strong&gt; sleep_mode_enter();&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Turn LED off when not advertising nrf 52840 PCA10059 SDK 15.3</title><link>https://devzone.nordicsemi.com/thread/204490?ContentTypeID=1</link><pubDate>Fri, 16 Aug 2019 11:47:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c51b35ec-c3ad-4f12-8d27-95ea02badb93</guid><dc:creator>melt</dc:creator><description>&lt;p&gt;Hi Edvin&lt;/p&gt;
&lt;p&gt;stopping the advertisement is not a problem it seems to stop after the timeout. I would like to turn off the LED I switched on when I started to advertise.&lt;/p&gt;
&lt;p&gt;Im also looking at the following&amp;nbsp;bsp_indication_set(BSP_INDICATE_ADVERTISING);&lt;/p&gt;
&lt;p&gt;could I not use that to indicate advertising and not advertising. have tried&lt;/p&gt;
&lt;p&gt;if (bsp_indication_set(BSP_INDICATE_ADVERTISING))&lt;br /&gt; {nrf_gpio_pin_set(NRF_GPIO_PIN_MAP(1, 9));} // green led off}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Turn LED off when not advertising nrf 52840 PCA10059 SDK 15.3</title><link>https://devzone.nordicsemi.com/thread/204486?ContentTypeID=1</link><pubDate>Fri, 16 Aug 2019 11:40:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:639458f9-cdcc-4672-9075-9fc8cf2ae710</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Do you want to actively stop the advertisement, or do you want to check if the advertisement has timed out?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>