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

Beacon and Central

Good afternoon.

I have 2 boards NRF51:

  • One as beacon (SDK 9), use example code "nRF51_SDK_9.0.0\examples\ble_peripheral\ble_app_beacon".

  • The other as central (SDK10, softdevice s130), use example code "nRF5_SDK_10.0.0\examples\ble_central\ble_app_uart_c" to read beacons messages.

I have modified central code to be able to read messages:

/**@brief Function for handling the Application's BLE Stack events.
*
* @param[in]   p_ble_evt   Bluetooth stack event.
*/
static void on_ble_evt(ble_evt_t * p_ble_evt)
{
	uint32_t              err_code;
	const ble_gap_evt_t * p_gap_evt = &p_ble_evt->evt.gap_evt;	

	const ble_gap_evt_adv_report_t *p_adv_report = &p_gap_evt->params.adv_report;
	//is_uuid_present(&m_nus_uuid, p_adv_report);

	switch (p_ble_evt->header.evt_id){
	    case BLE_GAP_EVT_ADV_REPORT:
            if(p_adv_report->type == 3){
	    	    printf("rssi: %d, scan_rsp: %d, type: %d, long: %d, ", p_adv_report->rssi, p_adv_report->scan_rsp, p_adv_report->type, p_adv_report->dlen);
	    	    printf("dir: %02x:%02x:%02x:%02x:%02x:%02x \r\n", p_adv_report->peer_addr.addr[5], p_adv_report->peer_addr.addr[4], p_adv_report->peer_addr.addr[3],
	    	    p_adv_report->peer_addr.addr[2], p_adv_report->peer_addr.addr[1], p_adv_report->peer_addr.addr[0]);
		
	    	    for(int i = 0; i < p_adv_report->dlen; i++){
	    			printf("%x", p_adv_report->data[i]); 
	    	    }
	    	    printf("\r\n");					
	    	    printf("------------------------------------------\r\n\n");
		    }
            break;
        ...............
    }
}

Three questions:

  • Point 1. I want beacon sends a string (ex: hello) and the level of battery to, how could I implement this.
  • Point 2. If beacon sends the string and lvl of battery, could I read this with my "on_ble_evt" code or I have to modified it? and this way to read messages is good or there is someone better.
  • Point 3. Should I use the news SDK?

All help is wellcome.

Thank you.

  • Hi,

    1. You can add the string and battery level to the Manufacturer specific data field of the advertising packet. Here is a blog post about how to measure the battery voltage, and you can find an actual example of battery measurement for the nRF51 in this ADC example on GitHub. Note that you will have to update the advertising data on each measurement interval.
    2. When the central receives an advertising packet, you will get a BLE_GAP_EVT_ADV_REPORT event in the on_ble_evt() handler. Here you can parse the package and extract the data, using a method similar to the adv_report_parse() function found in the BLE Multilink central example. If you are scanning a large number of devices (beacons), or do not want to establish a connection between the devices, this is the only method available for passing data.
    3. In general, we recommend using the latest SDK supporting your device for development. If you have already started the development, you will have to consider if the recent SDK support features that you desire before doing a migration. It can be some work to migrate from an old SDK to an new one, so this depends on whether the added value exceeds the required workload.

    Best regards,

    Jørgen

Related