<?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>Advertise battery level in beacon advertising packet</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/78948/advertise-battery-level-in-beacon-advertising-packet</link><description>1. 2. 3. 
 
 I am using the ble_app_beacon example as the starting point for my project. I am working on a project where a number of beacons will advertise its identity and battery level to the central node. My question is : how to modify the beacon advertising</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 29 Jun 2022 06:37:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/78948/advertise-battery-level-in-beacon-advertising-packet" /><item><title>RE: Advertise battery level in beacon advertising packet</title><link>https://devzone.nordicsemi.com/thread/374659?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2022 06:37:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:012a5ded-273f-465a-bfaa-9e4d9c6fa1c5</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;We do not have a Central/Observer implementation for Eddystone, unfortunately. Creating a receiver which can work with all the Eddystone frame formats will require a bit more effort than just a regular beacon scanner.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Advertise battery level in beacon advertising packet</title><link>https://devzone.nordicsemi.com/thread/374654?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2022 05:55:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9fbe1bf6-95fe-47fa-8206-16e3b0c17682</guid><dc:creator>Bhakti Deshpande</dc:creator><description>&lt;p&gt;Thank you&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/vibe"&gt;Vidar Berg&lt;/a&gt;&amp;nbsp;for quick reply. I needed receiver for eddystone beacons. I&amp;nbsp;tried making changes (removed manufacture code filter and all) in receiver code&amp;nbsp;to receive&amp;nbsp;eddystone beacons but as you said it has completely different frame format and only working with&amp;nbsp;&lt;a title="Beacon Transmitter Sample Application" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/ble_sdk_app_beacon.html?cp=8_1_4_2_2_2"&gt;Beacon Transmitter Sample Application&lt;/a&gt;. Can I get&amp;nbsp;the receiver code&amp;nbsp;to receive all type of beacons or eddystone beacons?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Advertise battery level in beacon advertising packet</title><link>https://devzone.nordicsemi.com/thread/374461?ContentTypeID=1</link><pubDate>Tue, 28 Jun 2022 07:44:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8d3bbc72-e675-47a6-b0bb-33567b477fb9</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I made it to scan for the nordic beacon implemented in the &lt;span&gt;&lt;a title="Beacon Transmitter Sample Application" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/ble_sdk_app_beacon.html?cp=8_1_4_2_2_2"&gt;Beacon Transmitter Sample Application&lt;/a&gt;. &lt;/span&gt;The Eddystone Beacon uses an entirely different beacon format and will not work with this code.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Advertise battery level in beacon advertising packet</title><link>https://devzone.nordicsemi.com/thread/374441?ContentTypeID=1</link><pubDate>Tue, 28 Jun 2022 06:32:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f4c2d93f-51ac-4525-b644-2fd2418e2e2d</guid><dc:creator>Bhakti Deshpande</dc:creator><description>&lt;p&gt;I have one &lt;span&gt;nrf52840, which I have configured to transmit beacons&amp;nbsp;using ble_app_eddystone example code. I have another&amp;nbsp;nrf52840 and&amp;nbsp;&lt;/span&gt;I have tried above code in it to scan the beacons&lt;span&gt;&amp;nbsp;but I&amp;nbsp;am unable to see any beacon data on debug terminal. &lt;a href="https://devzone.nordicsemi.com/members/vibe"&gt;Vidar Berg&lt;/a&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/slamshaikh"&gt;ysuleiman&lt;/a&gt;&amp;nbsp;can you please guide me for checking the scanned beacons data?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Bhakti.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Advertise battery level in beacon advertising packet</title><link>https://devzone.nordicsemi.com/thread/338094?ContentTypeID=1</link><pubDate>Tue, 09 Nov 2021 09:50:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e5f976e1-7c7e-41fa-a11f-1f81b79bb8ea</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Sorry, I had forgotten to zero initialize the offset argument in on_adv_report(). This is neccessary to make ble_advdata_search() start parsing the adv. paylod from from the beginning.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**
 * Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA &amp;quot;AS IS&amp;quot; AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
/**
 * @brief BLE LED Button Service central and client application main file.
 *
 * This file contains the source code for a sample client application using the LED Button service.
 */

#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;quot;nrf_sdh.h&amp;quot;
#include &amp;quot;nrf_sdh_ble.h&amp;quot;
#include &amp;quot;nrf_sdh_soc.h&amp;quot;
#include &amp;quot;nrf_pwr_mgmt.h&amp;quot;
#include &amp;quot;app_timer.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;bsp.h&amp;quot;
#include &amp;quot;bsp_btn_ble.h&amp;quot;
#include &amp;quot;ble.h&amp;quot;
#include &amp;quot;ble_hci.h&amp;quot;
#include &amp;quot;ble_advertising.h&amp;quot;
#include &amp;quot;ble_conn_params.h&amp;quot;
#include &amp;quot;ble_db_discovery.h&amp;quot;
#include &amp;quot;nrf_ble_gatt.h&amp;quot;
#include &amp;quot;nrf_ble_scan.h&amp;quot;

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;


#define CENTRAL_SCANNING_LED            BSP_BOARD_LED_0                     /**&amp;lt; Scanning LED will be on when the device is scanning. */
#define APP_COMPANY_IDENTIFIER          {0x59, 0x00}                              /**&amp;lt; Company identifier for Nordic Semiconductor ASA. as per www.bluetooth.org. */

#define APP_BLE_OBSERVER_PRIO           3                                   /**&amp;lt; Application&amp;#39;s BLE observer priority. You shouldn&amp;#39;t need to modify this value. */

NRF_BLE_SCAN_DEF(m_scan);                                                   /**&amp;lt; Scanning module instance. */



typedef PACKED_STRUCT
{
    uint8_t device_type;
    uint8_t app_adv_data_length;
    ble_uuid128_t beacon_uuid;
    uint8_t  major_value[2];
    uint8_t  minor_value[2];
    uint8_t measured_rssi;
} beacon_info_t;

static beacon_info_t m_beacon_info;


/**@brief Function to handle asserts in the SoftDevice.
 *
 * @details This function will be called in case of an assert in the SoftDevice.
 *
 * @warning This handler is an example only and does not fit a final product. You need to analyze
 *          how your product is supposed to react in case of Assert.
 * @warning On assert from the SoftDevice, the system can only recover on reset.
 *
 * @param[in] line_num     Line number of the failing ASSERT call.
 * @param[in] p_file_name  File name of the failing ASSERT call.
 */
void assert_nrf_callback(uint16_t line_num, const uint8_t * p_file_name)
{
    app_error_handler(0xDEADBEEF, line_num, p_file_name);
}



/**@brief Function for the LEDs initialization.
 *
 * @details Initializes all LEDs used by the application.
 */
static void leds_init(void)
{
    bsp_board_init(BSP_INIT_LEDS);
}


/**@brief Function to start scanning.
 */
static void scan_start(void)
{
    ret_code_t err_code;

    err_code = nrf_ble_scan_start(&amp;amp;m_scan);
    APP_ERROR_CHECK(err_code);
    bsp_board_led_on(CENTRAL_SCANNING_LED);
}


/**@brief Function for initializing the BLE stack.
 *
 * @details Initializes the SoftDevice and the BLE event interrupts.
 */
static void ble_stack_init(void)
{
    ret_code_t err_code;

    err_code = nrf_sdh_enable_request();
    APP_ERROR_CHECK(err_code);

    // Configure the BLE stack using the default settings.
    // Fetch the start address of the application RAM.
    uint32_t ram_start = 0;
    err_code = nrf_sdh_ble_default_cfg_set(1, &amp;amp;ram_start);
    APP_ERROR_CHECK(err_code);

    // Enable BLE stack.
    err_code = nrf_sdh_ble_enable(&amp;amp;ram_start);
    APP_ERROR_CHECK(err_code);
}


static void on_adv_report(ble_gap_evt_adv_report_t const * p_adv_report)
{
    uint16_t length;
    uint16_t offset=0;
    uint16_t major_value;

    uint8_t company_identifier[] = APP_COMPANY_IDENTIFIER;
    
    length = ble_advdata_search(p_adv_report-&amp;gt;data.p_data,
                                p_adv_report-&amp;gt;data.len,
                                &amp;amp;offset,
                                BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA);
    
	/* Print manufacturer data if found */
    if (length &amp;gt; 0)
    {
        if (!(memcmp(&amp;amp;p_adv_report-&amp;gt;data.p_data[offset], company_identifier, sizeof(company_identifier))))
        {
            memcpy(&amp;amp;m_beacon_info, &amp;amp;p_adv_report-&amp;gt;data.p_data[offset + sizeof(company_identifier)],
                sizeof(m_beacon_info));

            major_value = (m_beacon_info.major_value[1]) | ( m_beacon_info.major_value[0] &amp;lt;&amp;lt; 8);
            NRF_LOG_INFO(&amp;quot;Major value: 0x%x&amp;quot;, major_value);
        }
    }

}



/**@brief Function for handling Scaning events.
 *
 * @param[in]   p_scan_evt   Scanning event.
 */
static void scan_evt_handler(scan_evt_t const * p_scan_evt)
{

    switch(p_scan_evt-&amp;gt;scan_evt_id)
    {
        case NRF_BLE_SCAN_EVT_NOT_FOUND:
            on_adv_report(p_scan_evt-&amp;gt;params.p_not_found);
            break;
        default:
          break;
    }
}





/**@brief Function for initializing the log.
 */
static void log_init(void)
{
    ret_code_t err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();
}


/**@brief Function for initializing the timer.
 */
static void timer_init(void)
{
    ret_code_t err_code = app_timer_init();
    APP_ERROR_CHECK(err_code);
}


/**@brief Function for initializing the Power manager. */
static void power_management_init(void)
{
    ret_code_t err_code;
    err_code = nrf_pwr_mgmt_init();
    APP_ERROR_CHECK(err_code);
}


static void scan_init(void)
{
    ret_code_t          err_code;
    nrf_ble_scan_init_t init_scan;
    ble_gap_scan_params_t params;

    memset(&amp;amp;params, 0, sizeof(params));

    params.active  = 1;
    params.interval = NRF_BLE_SCAN_SCAN_INTERVAL;
    params.window = NRF_BLE_SCAN_SCAN_WINDOW;
    params.timeout = NRF_BLE_SCAN_SCAN_DURATION;
    params.filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL;
    params.scan_phys = NRF_BLE_SCAN_SCAN_PHY;

    memset(&amp;amp;init_scan, 0, sizeof(init_scan));

    init_scan.conn_cfg_tag     = 1;
    init_scan.p_scan_param     = &amp;amp;params;

    err_code = nrf_ble_scan_init(&amp;amp;m_scan, &amp;amp;init_scan, scan_evt_handler);
    APP_ERROR_CHECK(err_code);

}



/**@brief Function for handling the idle state (main loop).
 *
 * @details Handle any pending log operation(s), then sleep until the next event occurs.
 */
static void idle_state_handle(void)
{
    NRF_LOG_FLUSH();
    nrf_pwr_mgmt_run();
}


int main(void)
{
    // Initialize.
    log_init();
    timer_init();
    leds_init();
    power_management_init();
    ble_stack_init();
    scan_init();

    // Start execution.
    NRF_LOG_INFO(&amp;quot;Beacon scanner example started.&amp;quot;);
    scan_start();

    // Turn on the LED to signal scanning.
    bsp_board_led_on(CENTRAL_SCANNING_LED);

    // Enter main loop.
    for (;;)
    {
        idle_state_handle();
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Advertise battery level in beacon advertising packet</title><link>https://devzone.nordicsemi.com/thread/337713?ContentTypeID=1</link><pubDate>Fri, 05 Nov 2021 13:38:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:da5f6f36-9852-4a54-a04a-a2fcfd934fbc</guid><dc:creator>ysuleiman</dc:creator><description>&lt;p&gt;Thanks for the reply Vidar. The beacon information is read by nRF Connect Android app as soon as the beacons are supplied power. But the scanner example that you have given in the first reply doesn&amp;#39;t readily read these beacons while it seems to be reading the beacon data from surrounding beacons from various wearables (I am guessing). But surprisingly it read one of my beacons for just one time and I don&amp;#39;t know what made it read it. Can you please show me the right direction to pursue? Why doesn&amp;#39;t this scanner example thoroughly read the my beacons as nRF Connect does?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Advertise battery level in beacon advertising packet</title><link>https://devzone.nordicsemi.com/thread/336480?ContentTypeID=1</link><pubDate>Thu, 28 Oct 2021 12:37:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e1b6ac93-7ea7-4e44-9ee5-1c2a4a1bee01</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;You can use our nRF connect app on Android or iOS to inspect the Beacon payloads. Have you tried that to see if all of your beacons have the same packet format (i.e. do they all include the manufcaturer field)?&lt;/p&gt;
[quote user="slamshaikh"]What if the beacon advertisement packet contained the text? Would this example then display the text as it is or would still display in hex regardless?[/quote]
&lt;p&gt;I&amp;#39;m only printing out the hex values of the manufacturer field inside the beacon payload. If you have text strings in the payload, then you will need to parse the packet first to find out where the string is located.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Advertise battery level in beacon advertising packet</title><link>https://devzone.nordicsemi.com/thread/336247?ContentTypeID=1</link><pubDate>Wed, 27 Oct 2021 14:01:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e1ca4e06-3202-4b00-86cd-6638b2e8e167</guid><dc:creator>ysuleiman</dc:creator><description>&lt;p&gt;Thank you so much for the reply, Vidar. I tried the scanner example given here. It doesn&amp;#39;t readily read the surrounding beacon&amp;nbsp;after&amp;nbsp;I compile and download it. It says &amp;quot;Beacon scanner example started.&amp;quot; and then no beacon information is displayed. Only for once though (I don&amp;#39;t know exactly why, I waited it out though), it displayed &amp;quot;Data from manufacturer field&amp;quot; and yet it only displayed information from one beacon. Do I have to change some configuration or rewrite the code so that more than one beacon information is displayed? Can you please suggest what configuration I must change or what code changes I must do? I guess the beacon information is advertised in hex (hence in binary) that&amp;#39;s why it is scanned and read as hex. What if the beacon advertisement packet contained the text? Would this example then display the text as it is or would still display in hex regardless? I am asking this because this information will be used by the end-user.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Advertise battery level in beacon advertising packet</title><link>https://devzone.nordicsemi.com/thread/326766?ContentTypeID=1</link><pubDate>Thu, 26 Aug 2021 11:57:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:73d0eaaa-9243-4733-9fa4-9bb72aadeeae</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Attached below is a modified version of the ble_app_beacon I made earlier to demonstrate how to update advertising payload on-the-fly. This may be a better starting point since you will need to update the packet every time there is a change in battery level.&amp;nbsp; You may also be interested in the demo sample I uploaded in this post: &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/71940/low-power-mode-using-saadc-with-ble_app_beacon"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/71940/low-power-mode-using-saadc-with-ble_app_beacon&lt;/a&gt;&amp;nbsp; in case you&amp;#39;re going to use the SAADC to sample the battery voltage.&lt;/p&gt;
&lt;p&gt;1. Each beacon will have it&amp;#39;s own unique Bluetooth address so I guess you could use that as I unique identifier. The Bluetooth address will be derived from FICR.&lt;span&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/ficr.html?cp=4_2_0_12_0_13#register.DEVICEADDR-0"&gt;DEVICEADDR[n]&lt;/a&gt; unless you are explicitly setting a different in Bluetooth address in your code. You also have the APP_MAJOR_VALUE and APP_MINOR_VALUE fields in the beacon payload which you can use for identification. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;2. We do not have a Beacon scanner example included in the SDK, but here is some code may help you get started:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**
 * Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA &amp;quot;AS IS&amp;quot; AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
/**
 * @brief BLE LED Button Service central and client application main file.
 *
 * This file contains the source code for a sample client application using the LED Button service.
 */

#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;quot;nrf_sdh.h&amp;quot;
#include &amp;quot;nrf_sdh_ble.h&amp;quot;
#include &amp;quot;nrf_sdh_soc.h&amp;quot;
#include &amp;quot;nrf_pwr_mgmt.h&amp;quot;
#include &amp;quot;app_timer.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;bsp.h&amp;quot;
#include &amp;quot;bsp_btn_ble.h&amp;quot;
#include &amp;quot;ble.h&amp;quot;
#include &amp;quot;ble_hci.h&amp;quot;
#include &amp;quot;ble_advertising.h&amp;quot;
#include &amp;quot;ble_conn_params.h&amp;quot;
#include &amp;quot;ble_db_discovery.h&amp;quot;
#include &amp;quot;nrf_ble_gatt.h&amp;quot;
#include &amp;quot;nrf_ble_scan.h&amp;quot;

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;


#define CENTRAL_SCANNING_LED            BSP_BOARD_LED_0                     /**&amp;lt; Scanning LED will be on when the device is scanning. */


#define APP_BLE_OBSERVER_PRIO           3                                   /**&amp;lt; Application&amp;#39;s BLE observer priority. You shouldn&amp;#39;t need to modify this value. */

NRF_BLE_SCAN_DEF(m_scan);                                                   /**&amp;lt; Scanning module instance. */


/**@brief Function to handle asserts in the SoftDevice.
 *
 * @details This function will be called in case of an assert in the SoftDevice.
 *
 * @warning This handler is an example only and does not fit a final product. You need to analyze
 *          how your product is supposed to react in case of Assert.
 * @warning On assert from the SoftDevice, the system can only recover on reset.
 *
 * @param[in] line_num     Line number of the failing ASSERT call.
 * @param[in] p_file_name  File name of the failing ASSERT call.
 */
void assert_nrf_callback(uint16_t line_num, const uint8_t * p_file_name)
{
    app_error_handler(0xDEADBEEF, line_num, p_file_name);
}



/**@brief Function for the LEDs initialization.
 *
 * @details Initializes all LEDs used by the application.
 */
static void leds_init(void)
{
    bsp_board_init(BSP_INIT_LEDS);
}


/**@brief Function to start scanning.
 */
static void scan_start(void)
{
    ret_code_t err_code;

    err_code = nrf_ble_scan_start(&amp;amp;m_scan);
    APP_ERROR_CHECK(err_code);
    bsp_board_led_on(CENTRAL_SCANNING_LED);
}


/**@brief Function for initializing the BLE stack.
 *
 * @details Initializes the SoftDevice and the BLE event interrupts.
 */
static void ble_stack_init(void)
{
    ret_code_t err_code;

    err_code = nrf_sdh_enable_request();
    APP_ERROR_CHECK(err_code);

    // Configure the BLE stack using the default settings.
    // Fetch the start address of the application RAM.
    uint32_t ram_start = 0;
    err_code = nrf_sdh_ble_default_cfg_set(1, &amp;amp;ram_start);
    APP_ERROR_CHECK(err_code);

    // Enable BLE stack.
    err_code = nrf_sdh_ble_enable(&amp;amp;ram_start);
    APP_ERROR_CHECK(err_code);
}


static void on_adv_report(ble_gap_evt_adv_report_t const * p_adv_report)
{
    uint16_t length;
    uint16_t offset;
    
    length = ble_advdata_search(p_adv_report-&amp;gt;data.p_data,
                                p_adv_report-&amp;gt;data.len,
                                &amp;amp;offset,
                                BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA);
    
	/* Print manufacturer data if found */
    if (length &amp;gt; 0)
    {
        NRF_LOG_INFO(&amp;quot;Data from manufacturer field&amp;quot;);
        NRF_LOG_HEXDUMP_INFO(&amp;amp;p_adv_report-&amp;gt;data.p_data[offset], length);
    }

    }
}



/**@brief Function for handling Scaning events.
 *
 * @param[in]   p_scan_evt   Scanning event.
 */
static void scan_evt_handler(scan_evt_t const * p_scan_evt)
{

    switch(p_scan_evt-&amp;gt;scan_evt_id)
    {
        case NRF_BLE_SCAN_EVT_NOT_FOUND:
            on_adv_report(p_scan_evt-&amp;gt;params.p_not_found);
            break;
        default:
          break;
    }
}





/**@brief Function for initializing the log.
 */
static void log_init(void)
{
    ret_code_t err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();
}


/**@brief Function for initializing the timer.
 */
static void timer_init(void)
{
    ret_code_t err_code = app_timer_init();
    APP_ERROR_CHECK(err_code);
}


/**@brief Function for initializing the Power manager. */
static void power_management_init(void)
{
    ret_code_t err_code;
    err_code = nrf_pwr_mgmt_init();
    APP_ERROR_CHECK(err_code);
}


static void scan_init(void)
{
    ret_code_t          err_code;
    nrf_ble_scan_init_t init_scan;
    ble_gap_scan_params_t params;

    memset(&amp;amp;params, 0, sizeof(params));

    params.active  = 1;
    params.interval = NRF_BLE_SCAN_SCAN_INTERVAL;
    params.window = NRF_BLE_SCAN_SCAN_WINDOW;
    params.timeout = NRF_BLE_SCAN_SCAN_DURATION;
    params.filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL;
    params.scan_phys = NRF_BLE_SCAN_SCAN_PHY;

    memset(&amp;amp;init_scan, 0, sizeof(init_scan));

    init_scan.conn_cfg_tag     = 1;
    init_scan.p_scan_param     = &amp;amp;params;

    err_code = nrf_ble_scan_init(&amp;amp;m_scan, &amp;amp;init_scan, scan_evt_handler);
    APP_ERROR_CHECK(err_code);

}



/**@brief Function for handling the idle state (main loop).
 *
 * @details Handle any pending log operation(s), then sleep until the next event occurs.
 */
static void idle_state_handle(void)
{
    NRF_LOG_FLUSH();
    nrf_pwr_mgmt_run();
}


int main(void)
{
    // Initialize.
    log_init();
    timer_init();
    leds_init();
    power_management_init();
    ble_stack_init();
    scan_init();

    // Start execution.
    NRF_LOG_INFO(&amp;quot;Beacon scanner example started.&amp;quot;);
    scan_start();

    // Turn on the LED to signal scanning.
    bsp_board_led_on(CENTRAL_SCANNING_LED);

    // Enter main loop.
    for (;;)
    {
        idle_state_handle();
    }
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;You can copy paste this into the main.c file for the ble_central-&amp;gt;ble_app_blinky_c example to try it out. This code should simply print the the manufacturer data for every beacon it finds. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;3. There is no encryption so everyone can read the advertising payload. Is that a security concern for your application?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span&gt;Attachment&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/3058.nRF5_5F00_SDK17.0.2_5F00_ble_5F00_app_5F00_beacon_5F00_update.zip"&gt;devzone.nordicsemi.com/.../3058.nRF5_5F00_SDK17.0.2_5F00_ble_5F00_app_5F00_beacon_5F00_update.zip&lt;/a&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Vidar&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Edit: &lt;/strong&gt;There is a bug in the attached example that can lead to invalid data in the manufacturer field. The fix is to add the &amp;#39;static&amp;#39; keyword to the manuf_specific_data variable defintion in advertising_init():&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt; static ble_advdata_manuf_data_t manuf_specific_data;&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>