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

I want to sense bluetooth RF without connecting/pairing/bonding

I want to sense bluetooth from any distance the radio can detect and without connecting, pairing or bonding. Simply turn led2 on while the nrf51822 senses RF and when it no longer senses RF simply turn led2 off!. No interaction is needed except for the application turning led2 on/off to get scan response or advertising.

Tried to integrate beacon code but i'm using UART for some of my other functions. For some reason they will not compile together if I take out the includes that came with BLE_beacon it compiles fine but without the beacon functionality, as to be expected.

Any recommendations would be helpful. I have used your examples here on the zone from multiple sources. But maybe someone knows a simple answer to this simple question. but almost all are from a perspective of connection then conditional action.

The code I currently have will turn led2 on if connection occurs and turn led2 off when connection terminates. Not a bluetooth sw engineer by any means.

I'm attaching code with multiple examples commented out.

sincerely, your humble struggling servant.code.cpp

Parents
  • Hi,

    If you create a central/observer, you will get a BLE_GAP_EVT_ADV_REPORT event in your BLE event handler. You can use this to set the LED each time you receive an advertising packet from any device. If you want to limit the LED indication to a single device within range, you have to parse the package for devicename/device address. To switch off the LED, you can create a single-shot timer, that will turn off the LED after a given amount of time after receving the advertisement report. Remember to stop the timer if you receive a new advertisement packet. You need to set the timout for the timer long enough to make sure you cover the longest advertisement interval of devices within range to make ensure the led will not turn off between receiving advertisement packets.

    You can take a look at the BLE Heart Rate Collector Example in our SDK. Here is an example of what your BLE event handler can contain:

    static void on_ble_evt(ble_evt_t * p_ble_evt)
    {
        uint32_t                err_code;
    
    	if (p_ble_evt->header.evt_id == BLE_GAP_EVT_ADV_REPORT)
    	{
    		err_code = app_timer_stop(m_ble_activity_timer_id);
    		APP_ERROR_CHECK(err_code);
    		
    		nrf_drv_gpiote_out_clear(LED_3); // Turn LED on
    
    		err_code = app_timer_start(m_ble_activity_timer_id, APP_TIMER_TICKS(timer_timeout, APP_TIMER_PRESCALER), NULL);
    		APP_ERROR_CHECK(err_code);
    
    	}
    }
    

    You also need to add the other variables and create the timer and timer handler:

    APP_TIMER_DEF(m_ble_activity_timer_id);
    static timer_timeout = 1000;
    
    static void ble_activity_timer_handler(void * p_context)
    {
        nrf_drv_gpiote_out_set(LED_3); 	// Turn LED off
    }
    
    int main(void)
    {
        uint32_t err_code = app_timer_create(&m_ble_activity_timer_id,
    										 APP_TIMER_MODE_SINGLE_SHOT,
    										 ble_activity_timer_handler);
        APP_ERROR_CHECK(err_code);
    
    }
    

    It looks from your code like you are using mBed. I'm not sure about how to do this in mBed, but the principle should be the same. You can take a look at the BLE_Observer example, which should help you well on the way!

    Best regards,

    Jørgen

Reply
  • Hi,

    If you create a central/observer, you will get a BLE_GAP_EVT_ADV_REPORT event in your BLE event handler. You can use this to set the LED each time you receive an advertising packet from any device. If you want to limit the LED indication to a single device within range, you have to parse the package for devicename/device address. To switch off the LED, you can create a single-shot timer, that will turn off the LED after a given amount of time after receving the advertisement report. Remember to stop the timer if you receive a new advertisement packet. You need to set the timout for the timer long enough to make sure you cover the longest advertisement interval of devices within range to make ensure the led will not turn off between receiving advertisement packets.

    You can take a look at the BLE Heart Rate Collector Example in our SDK. Here is an example of what your BLE event handler can contain:

    static void on_ble_evt(ble_evt_t * p_ble_evt)
    {
        uint32_t                err_code;
    
    	if (p_ble_evt->header.evt_id == BLE_GAP_EVT_ADV_REPORT)
    	{
    		err_code = app_timer_stop(m_ble_activity_timer_id);
    		APP_ERROR_CHECK(err_code);
    		
    		nrf_drv_gpiote_out_clear(LED_3); // Turn LED on
    
    		err_code = app_timer_start(m_ble_activity_timer_id, APP_TIMER_TICKS(timer_timeout, APP_TIMER_PRESCALER), NULL);
    		APP_ERROR_CHECK(err_code);
    
    	}
    }
    

    You also need to add the other variables and create the timer and timer handler:

    APP_TIMER_DEF(m_ble_activity_timer_id);
    static timer_timeout = 1000;
    
    static void ble_activity_timer_handler(void * p_context)
    {
        nrf_drv_gpiote_out_set(LED_3); 	// Turn LED off
    }
    
    int main(void)
    {
        uint32_t err_code = app_timer_create(&m_ble_activity_timer_id,
    										 APP_TIMER_MODE_SINGLE_SHOT,
    										 ble_activity_timer_handler);
        APP_ERROR_CHECK(err_code);
    
    }
    

    It looks from your code like you are using mBed. I'm not sure about how to do this in mBed, but the principle should be the same. You can take a look at the BLE_Observer example, which should help you well on the way!

    Best regards,

    Jørgen

Children
No Data
Related