This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf51822 starts advertising on disconnect. How to stop it??

I have advertising in s130 set to BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED. The idea is to advertise until a connection event is received. In reality the user will pull the finger out of the pulse ox turning it off if no connection takes place. 

In any case, when a connection takes place and the measurement is transferred, I disconnect and write data to flash and that is it. However, the chip starts advertising again even though I did not ask it to. In fact I specifically call 

sd_ble_gap_adv_stop();  // just to make sure

in both the connection event and in the disconnect event

Since that did not work I added 

err_code = sd_ble_gap_adv_data_set(data_buffer, 0, scan_rsp_buffer, 0); // CAN'T have flags and name duplicated
APP_ERROR_CHECK(err_code);

to the connection event to clear the data so the peer would not respond to it if the chip was still stupid enough to start advertising again. That did not work. It still starts advertising and still sends the original advertisement.

How can I shut this thing up?

By the way what do you mean by an advertising type of BLE_GAP_ADV_TYPE_ADV_SCAN_IND

My interpretation of this is that the device will respond to scan requests and this is connectable, but your documentation states

"An application can start an advertising procedure for broadcasting purposes while a connection is active. After a BLE_GAP_EVT_CONNECTED event is received, this function may therefore be called to start a broadcast advertising procedure. The advertising procedure cannot however be connectable (it must be of type BLE_GAP_ADV_TYPE_ADV_SCAN_IND or BLE_GAP_ADV_TYPE_ADV_NONCONN_IND)."

There you state that a scannable advertisement is not connectable. What do you mean by 'scannable'?

Parents Reply Children
  • Hi,

    brianreinhold said:
    So I wasn't sure what BLE_GAP_ADV_TYPE_ADV_SCAN_IND did and how it differed from BLE_GAP_ADV_TYPE_ADV_IND.

    I see. It is unfortunately not clear from the API documentation. To be specific BLE_GAP_ADV_TYPE_ADV_SCAN_IND is scannable, undirected and non-connectable. BLE_GAP_ADV_TYPE_ADV_IND is non-scannable, undirected and connectable.

  • Well, I set the type to BLE_GAP_ADV_TYPE_ADV_IND and it is scannable; the chip responds to a scan request. I don't recall what happens if I set the type to BLE_GAP_ADV_TYPE_ADV_SCAN_IND.

    I see for SoftDevice s130 I have these:

    #define BLE_GAP_ADV_TYPE_ADV_IND 0x00 /**< Connectable undirected. */
    #define BLE_GAP_ADV_TYPE_ADV_DIRECT_IND 0x01 /**< Connectable directed. */
    #define BLE_GAP_ADV_TYPE_ADV_SCAN_IND 0x02 /**< Scannable undirected. */
    #define BLE_GAP_ADV_TYPE_ADV_NONCONN_IND 0x03 /**< Non connectable undirected. */

    But there is no mention here that the 'SCAN" option is not connectable.

    But in s140v6 I have these which is a little more extensive and clearer:

    #define BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED                   0x01   /**< Connectable and scannable undirected
                                                                                            advertising events. */
    #define BLE_GAP_ADV_TYPE_CONNECTABLE_NONSCANNABLE_DIRECTED_HIGH_DUTY_CYCLE  0x02   /**< Connectable non-scannable directed advertising
                                                                                            events. Advertising interval is less that 3.75 ms.
                                                                                            Use this type for fast reconnections.
                                                                                            @note Advertising data is not supported. */
    #define BLE_GAP_ADV_TYPE_CONNECTABLE_NONSCANNABLE_DIRECTED                  0x03   /**< Connectable non-scannable directed advertising
                                                                                            events.
                                                                                            @note Advertising data is not supported. */
    #define BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED                0x04   /**< Non-connectable scannable undirected
                                                                                            advertising events. */
    #define BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED             0x05   /**< Non-connectable non-scannable undirected
                                                                                            advertising events. */
    #define BLE_GAP_ADV_TYPE_EXTENDED_CONNECTABLE_NONSCANNABLE_UNDIRECTED       0x06   /**< Connectable non-scannable undirected advertising
                                                                                            events using extended advertising PDUs. */
    #define BLE_GAP_ADV_TYPE_EXTENDED_CONNECTABLE_NONSCANNABLE_DIRECTED         0x07   /**< Connectable non-scannable directed advertising
                                                                                            events using extended advertising PDUs. */
    #define BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_SCANNABLE_UNDIRECTED       0x08   /**< Non-connectable scannable undirected advertising
                                                                                            events using extended advertising PDUs.
                                                                                            @note Only scan response data is supported. */
    #define BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_SCANNABLE_DIRECTED         0x09   /**< Non-connectable scannable directed advertising
                                                                                            events using extended advertising PDUs.
                                                                                            @note Only scan response data is supported. */
    #define BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED    0x0A   /**< Non-connectable non-scannable undirected advertising
                                                                                            events using extended advertising PDUs. */
    #define BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_NONSCANNABLE_DIRECTED      0x0B   /**< Non-connectable non-scannable directed advertising
                                                                                            events using extended advertising PDUs. */
    

Related