<?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>How to get a timestamp when I receive an advertisement from another nRF51822 device?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/75905/how-to-get-a-timestamp-when-i-receive-an-advertisement-from-another-nrf51822-device</link><description>Hi. 
 I am using Central&amp;#39;s ble_app_uart_c_pca10028_s130 which is a sample of nRF51822. 
 I would like to see the timestamp of the advertisement acquisition I receive from the other machine, or the time elapsed since the first packet was received. 
 I</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 14 Jun 2021 10:11:22 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/75905/how-to-get-a-timestamp-when-i-receive-an-advertisement-from-another-nrf51822-device" /><item><title>RE: How to get a timestamp when I receive an advertisement from another nRF51822 device?</title><link>https://devzone.nordicsemi.com/thread/315076?ContentTypeID=1</link><pubDate>Mon, 14 Jun 2021 10:11:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4e4431a-3013-46ca-81cc-4b1b28380a23</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Todanohito,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I can see that you used&amp;nbsp;app_timer_cnt_get() to get the counter value. It&amp;#39;s fine but beaware that the counter has a maximum limit APP_TIMER_MAX_CNT_VAL. After passing this value it will wrap back to 0. So you need to take that in to account if you do some automated calculation.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a timestamp when I receive an advertisement from another nRF51822 device?</title><link>https://devzone.nordicsemi.com/thread/315021?ContentTypeID=1</link><pubDate>Mon, 14 Jun 2021 04:30:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b4e2bb3e-1528-4b0c-8e42-ced0b807972c</guid><dc:creator>tadanohito</dc:creator><description>&lt;p&gt;Thank you for all the advice.&lt;br /&gt;I&amp;#39;ve solved this problem.&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdbool.h&amp;gt;
#include &amp;quot;nordic_common.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;app_uart.h&amp;quot;
#include &amp;quot;ble_db_discovery.h&amp;quot;
#include &amp;quot;app_timer.h&amp;quot;
#include &amp;quot;app_util.h&amp;quot;
#include &amp;quot;bsp.h&amp;quot;
#include &amp;quot;bsp_btn_ble.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;ble.h&amp;quot;
#include &amp;quot;ble_gap.h&amp;quot;
#include &amp;quot;ble_hci.h&amp;quot;
#include &amp;quot;softdevice_handler.h&amp;quot;
#include &amp;quot;ble_advdata.h&amp;quot;
#include &amp;quot;ble_nus_c.h&amp;quot;

#define CENTRAL_LINK_COUNT      1                               /**&amp;lt; Number of central links used by the application. When changing this number remember to adjust the RAM settings*/
#define PERIPHERAL_LINK_COUNT   0                               /**&amp;lt; Number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/

#if (NRF_SD_BLE_API_VERSION == 3)
#define NRF_BLE_MAX_MTU_SIZE    GATT_MTU_SIZE_DEFAULT           /**&amp;lt; MTU size used in the softdevice enabling and to reply to a BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST event. */
#endif

#define UART_TX_BUF_SIZE        256                             /**&amp;lt; UART TX buffer size. */
#define UART_RX_BUF_SIZE        256                             /**&amp;lt; UART RX buffer size. */

#define NUS_SERVICE_UUID_TYPE   BLE_UUID_TYPE_VENDOR_BEGIN      /**&amp;lt; UUID type for the Nordic UART Service (vendor specific). */

#define APP_TIMER_PRESCALER     0                               /**&amp;lt; Value of the RTC1 PRESCALER register. */
#define APP_TIMER_OP_QUEUE_SIZE 2                               /**&amp;lt; Size of timer operation queues. */

#define SCAN_INTERVAL           0x00A0                          /**&amp;lt; Determines scan interval in units of 0.625 millisecond. */
#define SCAN_WINDOW             0x0050                          /**&amp;lt; Determines scan window in units of 0.625 millisecond. */
#define SCAN_ACTIVE             1                               /**&amp;lt; If 1, performe active scanning (scan requests). */
#define SCAN_SELECTIVE          0                               /**&amp;lt; If 1, ignore unknown devices (non whitelisted). */
#define SCAN_TIMEOUT            0x0000                          /**&amp;lt; Timout when scanning. 0x0000 disables timeout. */

#define MIN_CONNECTION_INTERVAL MSEC_TO_UNITS(20, UNIT_1_25_MS) /**&amp;lt; Determines minimum connection interval in millisecond. */
#define MAX_CONNECTION_INTERVAL MSEC_TO_UNITS(75, UNIT_1_25_MS) /**&amp;lt; Determines maximum connection interval in millisecond. */
#define SLAVE_LATENCY           0                               /**&amp;lt; Determines slave latency in counts of connection events. */
#define SUPERVISION_TIMEOUT     MSEC_TO_UNITS(4000, UNIT_10_MS) /**&amp;lt; Determines supervision time-out in units of 10 millisecond. */

#define UUID16_SIZE             2                               /**&amp;lt; Size of 16 bit UUID */
#define UUID32_SIZE             4                               /**&amp;lt; Size of 32 bit UUID */
#define UUID128_SIZE            16                              /**&amp;lt; Size of 128 bit UUID */






																																			
																																				
																																				
																																				
																																				
static ble_nus_c_t              m_ble_nus_c;                    /**&amp;lt; Instance of NUS service. Must be passed to all NUS_C API calls. */
static ble_db_discovery_t       m_ble_db_discovery;             /**&amp;lt; Instance of database discovery module. Must be passed to all db_discovert API calls */


																																														
/**
 * @brief Connection parameters requested for connection.
 */
static const ble_gap_conn_params_t m_connection_param =
  {
    (uint16_t)MIN_CONNECTION_INTERVAL,  // Minimum connection
    (uint16_t)MAX_CONNECTION_INTERVAL,  // Maximum connection
    (uint16_t)SLAVE_LATENCY,            // Slave latency
    (uint16_t)SUPERVISION_TIMEOUT       // Supervision time-out
  };

/**
 * @brief Parameters used when scanning.
 */
static const ble_gap_scan_params_t m_scan_params =
{
    .active   = 1,
    .interval = SCAN_INTERVAL,
    .window   = SCAN_WINDOW,
    .timeout  = SCAN_TIMEOUT,
    #if (NRF_SD_BLE_API_VERSION == 2)
        .selective   = 0,
        .p_whitelist = NULL,
    #endif
    #if (NRF_SD_BLE_API_VERSION == 3)
        .use_whitelist = 0,
    #endif
};

/**
 * @brief NUS uuid
 */
static const ble_uuid_t m_nus_uuid =
  {
    .uuid = BLE_UUID_NUS_SERVICE,
    .type = NUS_SERVICE_UUID_TYPE
  };

/**@brief Function for 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 to start scanning.
 */
static void scan_start(void)
{
    ret_code_t ret;

    ret = sd_ble_gap_scan_start(&amp;amp;m_scan_params);
    APP_ERROR_CHECK(ret);

    ret = bsp_indication_set(BSP_INDICATE_SCANNING);
    APP_ERROR_CHECK(ret);
}



/**@brief Function for handling database discovery events.
 *
 * @details This function is callback function to handle events from the database discovery module.
 *          Depending on the UUIDs that are discovered, this function should forward the events
 *          to their respective services.
 *
 * @param[in] p_event  Pointer to the database discovery event.
 */
static void db_disc_handler(ble_db_discovery_evt_t * p_evt)
{
    ble_nus_c_on_db_disc_evt(&amp;amp;m_ble_nus_c, p_evt);
}


/**@brief   Function for handling app_uart events.
 *
 * @details This function will receive a single character from the app_uart module and append it to
 *          a string. The string will be be sent over BLE when the last character received was a
 *          &amp;#39;new line&amp;#39; i.e &amp;#39;\r\n&amp;#39; (hex 0x0D) or if the string has reached a length of
 *          @ref NUS_MAX_DATA_LENGTH.
 */
void uart_event_handle(app_uart_evt_t * p_event)
{
    static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
    static uint8_t index = 0;

    switch (p_event-&amp;gt;evt_type)
    {
        /**@snippet [Handling data from UART] */
        case APP_UART_DATA_READY:
            UNUSED_VARIABLE(app_uart_get(&amp;amp;data_array[index]));
            index++;

            if ((data_array[index - 1] == &amp;#39;\n&amp;#39;) || (index &amp;gt;= (BLE_NUS_MAX_DATA_LEN)))
            {
                while (ble_nus_c_string_send(&amp;amp;m_ble_nus_c, data_array, index) != NRF_SUCCESS)
                {
                    // repeat until sent.
                }
                index = 0;
            }
            break;
        /**@snippet [Handling data from UART] */
        case APP_UART_COMMUNICATION_ERROR:
            APP_ERROR_HANDLER(p_event-&amp;gt;data.error_communication);
            break;

        case APP_UART_FIFO_ERROR:
            APP_ERROR_HANDLER(p_event-&amp;gt;data.error_code);
            break;

        default:
            break;
    }
}


/**@brief Callback handling NUS Client events.
 *
 * @details This function is called to notify the application of NUS client events.
 *
 * @param[in]   p_ble_nus_c   NUS Client Handle. This identifies the NUS client
 * @param[in]   p_ble_nus_evt Pointer to the NUS Client event.
 */

/**@snippet [Handling events from the ble_nus_c module] */
static void ble_nus_c_evt_handler(ble_nus_c_t * p_ble_nus_c, const ble_nus_c_evt_t * p_ble_nus_evt)
{
    uint32_t err_code;
    switch (p_ble_nus_evt-&amp;gt;evt_type)
    {
        case BLE_NUS_C_EVT_DISCOVERY_COMPLETE:
            err_code = ble_nus_c_handles_assign(p_ble_nus_c, p_ble_nus_evt-&amp;gt;conn_handle, &amp;amp;p_ble_nus_evt-&amp;gt;handles);
            APP_ERROR_CHECK(err_code);

            err_code = ble_nus_c_rx_notif_enable(p_ble_nus_c);
            APP_ERROR_CHECK(err_code);
            printf(&amp;quot;The device has the Nordic UART Service\r\n&amp;quot;);
            break;

        case BLE_NUS_C_EVT_NUS_RX_EVT:
            for (uint32_t i = 0; i &amp;lt; p_ble_nus_evt-&amp;gt;data_len; i++)
            {
                while (app_uart_put( p_ble_nus_evt-&amp;gt;p_data[i]) != NRF_SUCCESS);
            }
            break;

        case BLE_NUS_C_EVT_DISCONNECTED:
            printf(&amp;quot;Disconnected\r\n&amp;quot;);
            scan_start();
            break;
    }
}
/**@snippet [Handling events from the ble_nus_c module] */

/**@brief Function for putting the chip into sleep mode.
 *
 * @note This function will not return.
 */
static void sleep_mode_enter(void)
{
    uint32_t err_code = bsp_indication_set(BSP_INDICATE_IDLE);
    APP_ERROR_CHECK(err_code);

    // Prepare wakeup buttons.
    err_code = bsp_btn_ble_sleep_mode_prepare();
    APP_ERROR_CHECK(err_code);

    // Go to system-off mode (this function will not return; wakeup will cause a reset).
    err_code = sd_power_system_off();
    APP_ERROR_CHECK(err_code);
}

/**@brief Reads an advertising report and checks if a uuid is present in the service list.
 *
 * @details The function is able to search for 16-bit, 32-bit and 128-bit service uuids.
 *          To see the format of a advertisement packet, see
 *          https://www.bluetooth.org/Technical/AssignedNumbers/generic_access_profile.htm
 *
 * @param[in]   p_target_uuid The uuid to search fir
 * @param[in]   p_adv_report  Pointer to the advertisement report.
 *
 * @retval      true if the UUID is present in the advertisement report. Otherwise false
 */
static bool is_uuid_present(const ble_uuid_t *p_target_uuid,
                            const ble_gap_evt_adv_report_t *p_adv_report)
{
    uint32_t err_code;
    uint32_t index = 0;
    uint8_t *p_data = (uint8_t *)p_adv_report-&amp;gt;data;
    ble_uuid_t extracted_uuid;

    while (index &amp;lt; p_adv_report-&amp;gt;dlen)
    {
        uint8_t field_length = p_data[index];
        uint8_t field_type   = p_data[index + 1];

        if ( (field_type == BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_MORE_AVAILABLE)
           || (field_type == BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_COMPLETE)
           )
        {
            for (uint32_t u_index = 0; u_index &amp;lt; (field_length / UUID16_SIZE); u_index++)
            {
                err_code = sd_ble_uuid_decode(  UUID16_SIZE,
                                                &amp;amp;p_data[u_index * UUID16_SIZE + index + 2],
                                                &amp;amp;extracted_uuid);
                if (err_code == NRF_SUCCESS)
                {
                    if ((extracted_uuid.uuid == p_target_uuid-&amp;gt;uuid)
                        &amp;amp;&amp;amp; (extracted_uuid.type == p_target_uuid-&amp;gt;type))
                    {
                        return true;
                    }
                }
            }
        }

        else if ( (field_type == BLE_GAP_AD_TYPE_32BIT_SERVICE_UUID_MORE_AVAILABLE)
                || (field_type == BLE_GAP_AD_TYPE_32BIT_SERVICE_UUID_COMPLETE)
                )
        {
            for (uint32_t u_index = 0; u_index &amp;lt; (field_length / UUID32_SIZE); u_index++)
            {
                err_code = sd_ble_uuid_decode(UUID16_SIZE,
                &amp;amp;p_data[u_index * UUID32_SIZE + index + 2],
                &amp;amp;extracted_uuid);
                if (err_code == NRF_SUCCESS)
                {
                    if ((extracted_uuid.uuid == p_target_uuid-&amp;gt;uuid)
                        &amp;amp;&amp;amp; (extracted_uuid.type == p_target_uuid-&amp;gt;type))
                    {
                        return true;
                    }
                }
            }
        }

        else if ( (field_type == BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_MORE_AVAILABLE)
                || (field_type == BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE)
                )
        {
            err_code = sd_ble_uuid_decode(UUID128_SIZE,
                                          &amp;amp;p_data[index + 2],
                                          &amp;amp;extracted_uuid);
            if (err_code == NRF_SUCCESS)
            {
                if ((extracted_uuid.uuid == p_target_uuid-&amp;gt;uuid)
                    &amp;amp;&amp;amp; (extracted_uuid.type == p_target_uuid-&amp;gt;type))
                {
                    return true;
                }
            }
        }
        index += field_length + 1;
    }
    return false;
}

/**@brief Function for handling the Application&amp;#39;s BLE Stack events.
 *
 * @param[in] p_ble_evt  Bluetooth stack event.
 */
//uint32_t cnt;
APP_TIMER_DEF(my_timer_id1);
#define BATTERY_LEVEL_MEAS_INTERVAL      APP_TIMER_TICKS(10, APP_TIMER_PRESCALER)  /**&amp;lt; Battery level measurement interval (ticks). */
#include &amp;quot;nrf_drv_clock.h&amp;quot;
#include &amp;quot;app_timer.h&amp;quot;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#define NRF_LOG_MODULE_NAME &amp;quot;APP&amp;quot;
#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#define 	APP_TIMER_CLOCK_FREQ   32768
static void repeated_timer_handler(void * p_context)
{
uint32_t 	nrf_drv_gpiote_out_toggle();
//nrf_drv_gpiote_out_toggle(LED_1);
//cnt++;
										  


}
static void timers_init(void)
{
uint32_t              err_code;
// Create timers.
err_code = app_timer_create(&amp;amp;my_timer_id1,APP_TIMER_MODE_REPEATED, repeated_timer_handler);
APP_ERROR_CHECK(err_code);
// Start application timers.
err_code = app_timer_start(my_timer_id1, BATTERY_LEVEL_MEAS_INTERVAL, NULL);
APP_ERROR_CHECK(err_code);
}
static void on_ble_evt(ble_evt_t * p_ble_evt)
{
    uint32_t              err_code;
    const ble_gap_evt_t * p_gap_evt = &amp;amp;p_ble_evt-&amp;gt;evt.gap_evt;

	
																						

    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_ADV_REPORT:
        {
ble_gap_addr_t pa = p_gap_evt-&amp;gt;params.adv_report.peer_addr;
int8_t rssi = p_gap_evt-&amp;gt;params.adv_report.rssi;
printf(&amp;quot;Mac Address: %02x:%02x:%02x:%02x:%02x:%02x \r\n&amp;quot;, pa.addr[5], pa.addr[4], pa.addr[3], pa.addr[2], pa.addr[1], pa.addr[0]);
printf(&amp;quot;RSSI %d \r\n&amp;quot;, rssi);

double timenow = app_timer_cnt_get()/APP_TIMER_CLOCK_FREQ ;
printf(&amp;quot;time now: %f\r\n&amp;quot;, (double) timenow);
																																															
																																															
																																												
																																													
            const ble_gap_evt_adv_report_t * p_adv_report = &amp;amp;p_gap_evt-&amp;gt;params.adv_report;
            if (is_uuid_present(&amp;amp;m_nus_uuid, p_adv_report))
            {

                err_code = sd_ble_gap_connect(&amp;amp;p_adv_report-&amp;gt;peer_addr,
                                              &amp;amp;m_scan_params,
                                              &amp;amp;m_connection_param);

                if (err_code == NRF_SUCCESS)
                {
                    // scan is automatically stopped by the connect
                    err_code = bsp_indication_set(BSP_INDICATE_IDLE);
                    APP_ERROR_CHECK(err_code);
                    printf(&amp;quot;Connecting to target %02x%02x%02x%02x%02x%02x\r\n&amp;quot;,
                             p_adv_report-&amp;gt;peer_addr.addr[0],
                             p_adv_report-&amp;gt;peer_addr.addr[1],
                             p_adv_report-&amp;gt;peer_addr.addr[2],
                             p_adv_report-&amp;gt;peer_addr.addr[3],
                             p_adv_report-&amp;gt;peer_addr.addr[4],
                             p_adv_report-&amp;gt;peer_addr.addr[5]
                             );
                }
            }
        }break; // BLE_GAP_EVT_ADV_REPORT

        case BLE_GAP_EVT_CONNECTED:
            //NRF_LOG_DEBUG(&amp;quot;Connected to target\r\n&amp;quot;);
            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_ble_db_discovery, p_ble_evt-&amp;gt;evt.gap_evt.conn_handle);
            APP_ERROR_CHECK(err_code);
            break; // BLE_GAP_EVT_CONNECTED
        case BLE_GAP_EVT_TIMEOUT:
            if (p_gap_evt-&amp;gt;params.timeout.src == BLE_GAP_TIMEOUT_SRC_SCAN)
            {
                //NRF_LOG_DEBUG(&amp;quot;Scan timed out.\r\n&amp;quot;);
                scan_start();
            }
            else if (p_gap_evt-&amp;gt;params.timeout.src == BLE_GAP_TIMEOUT_SRC_CONN)
            {
                printf(&amp;quot;Connection Request timed out.\r\n&amp;quot;);
            }
            break; // BLE_GAP_EVT_TIMEOUT

        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);
            break; // BLE_GAP_EVT_SEC_PARAMS_REQUEST

        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; // BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST

        case BLE_GATTC_EVT_TIMEOUT:
            // Disconnect on GATT Client timeout event.
            //NRF_LOG_DEBUG(&amp;quot;GATT Client Timeout.\r\n&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; // BLE_GATTC_EVT_TIMEOUT

        case BLE_GATTS_EVT_TIMEOUT:
            // Disconnect on GATT Server timeout event.
            //NRF_LOG_DEBUG(&amp;quot;GATT Server Timeout.\r\n&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; // BLE_GATTS_EVT_TIMEOUT

#if (NRF_SD_BLE_API_VERSION == 3)
        case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST:
            err_code = sd_ble_gatts_exchange_mtu_reply(p_ble_evt-&amp;gt;evt.gatts_evt.conn_handle,
                                                       NRF_BLE_MAX_MTU_SIZE);
            APP_ERROR_CHECK(err_code);
            break; // BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST
#endif

        default:
            break;
    }
}

/**@brief Function for dispatching a BLE stack event to all modules with a BLE stack event handler.
 *
 * @details This function is called from the scheduler in the main loop after a BLE stack event has
 *          been received.
 *
 * @param[in] p_ble_evt  Bluetooth stack event.
 */
static void ble_evt_dispatch(ble_evt_t * p_ble_evt)
{
    on_ble_evt(p_ble_evt);
    bsp_btn_ble_on_ble_evt(p_ble_evt);
    ble_db_discovery_on_ble_evt(&amp;amp;m_ble_db_discovery, p_ble_evt);
    ble_nus_c_on_ble_evt(&amp;amp;m_ble_nus_c,p_ble_evt);
}

/**@brief Function for initializing the BLE stack.
 *
 * @details Initializes the SoftDevice and the BLE event interrupt.
 */
static void ble_stack_init(void)
{
    uint32_t err_code;

    nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;

    // Initialize the SoftDevice handler module.
    SOFTDEVICE_HANDLER_INIT(&amp;amp;clock_lf_cfg, NULL);

    ble_enable_params_t ble_enable_params;
    err_code = softdevice_enable_get_default_config(CENTRAL_LINK_COUNT,
                                                    PERIPHERAL_LINK_COUNT,
                                                    &amp;amp;ble_enable_params);
    APP_ERROR_CHECK(err_code);

    //Check the ram settings against the used number of links
    CHECK_RAM_START_ADDR(CENTRAL_LINK_COUNT,PERIPHERAL_LINK_COUNT);

    // Enable BLE stack.
#if (NRF_SD_BLE_API_VERSION == 3)
    ble_enable_params.gatt_enable_params.att_mtu = NRF_BLE_MAX_MTU_SIZE;
#endif
    err_code = softdevice_enable(&amp;amp;ble_enable_params);
    APP_ERROR_CHECK(err_code);

    // Register with the SoftDevice handler module for BLE events.
    err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
    APP_ERROR_CHECK(err_code);
}

/**@brief Function for handling events from the BSP module.
 *
 * @param[in] event  Event generated by button press.
 */
void bsp_event_handler(bsp_event_t event)
{
    uint32_t err_code;
    switch (event)
    {
        case BSP_EVENT_SLEEP:
            sleep_mode_enter();
            break;

        case BSP_EVENT_DISCONNECT:
            err_code = sd_ble_gap_disconnect(m_ble_nus_c.conn_handle,
                                             BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            if (err_code != NRF_ERROR_INVALID_STATE)
            {
                APP_ERROR_CHECK(err_code);
            }
            break;

        default:
            break;
    }
}

/**@brief Function for initializing the UART.
 */
static void uart_init(void)
{
    uint32_t err_code;

    const app_uart_comm_params_t comm_params =
      {
        .rx_pin_no    = RX_PIN_NUMBER,
        .tx_pin_no    = TX_PIN_NUMBER,
        .rts_pin_no   = RTS_PIN_NUMBER,
        .cts_pin_no   = CTS_PIN_NUMBER,
        .flow_control = APP_UART_FLOW_CONTROL_ENABLED,
        .use_parity   = false,
        .baud_rate    = UART_BAUDRATE_BAUDRATE_Baud115200
      };

    APP_UART_FIFO_INIT(&amp;amp;comm_params,
                        UART_RX_BUF_SIZE,
                        UART_TX_BUF_SIZE,
                        uart_event_handle,
                        APP_IRQ_PRIORITY_LOWEST,
                        err_code);

    APP_ERROR_CHECK(err_code);
}

/**@brief Function for initializing the NUS Client.
 */
static void nus_c_init(void)
{
    uint32_t         err_code;
    ble_nus_c_init_t nus_c_init_t;

    nus_c_init_t.evt_handler = ble_nus_c_evt_handler;

    err_code = ble_nus_c_init(&amp;amp;m_ble_nus_c, &amp;amp;nus_c_init_t);
    APP_ERROR_CHECK(err_code);
		
																														//	uint32_t sd_ble_gap_rssi_start	(	uint16_t 	conn_handle, uint8_t 	threshold_dbm, uint8_t 	skip_count);	
																														//	uint32_t sd_ble_gap_rssi_stop	(	uint16_t 	conn_handle	);	
}

/**@brief Function for initializing buttons and leds.
 */
static void buttons_leds_init(void)
{
    bsp_event_t startup_event;

    uint32_t err_code = bsp_init(BSP_INIT_LED,
                                 APP_TIMER_TICKS(100, APP_TIMER_PRESCALER),
                                 bsp_event_handler);
    APP_ERROR_CHECK(err_code);

    err_code = bsp_btn_ble_init(NULL, &amp;amp;startup_event);
    APP_ERROR_CHECK(err_code);
}


/** @brief Function for initializing the Database Discovery Module.
 */
static void db_discovery_init(void)
{
    uint32_t err_code = ble_db_discovery_init(db_disc_handler);
    APP_ERROR_CHECK(err_code);
}

/** @brief Function for the Power manager.
 */
static void power_manage(void)
{
    uint32_t err_code = sd_app_evt_wait();
    APP_ERROR_CHECK(err_code);
}
																																											
int main(void)
{

    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, NULL);
																																										
		uart_init();
    buttons_leds_init();
    db_discovery_init();
    ble_stack_init();
    nus_c_init();

    // Start scanning for peripherals and initiate connection
    // with devices that advertise NUS UUID.
    printf(&amp;quot;Uart_c Scan started\r\n&amp;quot;);
    scan_start();
		
    for (;;)
    {   
			 
			power_manage();
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a timestamp when I receive an advertisement from another nRF51822 device?</title><link>https://devzone.nordicsemi.com/thread/314415?ContentTypeID=1</link><pubDate>Wed, 09 Jun 2021 09:44:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:23945b99-4918-48fe-8531-f9945f264642</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Tadanohito,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please try to study how the app_timer works. You would need to make a program that be able to perform a task periodically for example turning off and on a LED or do other task.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Have you tried to follow the app_timer tutorial ?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t understand why you define the counter cnt as float. Why don&amp;#39;t you just define it as uint ? for example uint32_t&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Note that the counter is only to count the time,&amp;nbsp;it doesn&amp;#39;t matter if the packet is missing or not, it just count the time.&amp;nbsp;&lt;br /&gt;You don&amp;#39;t have to use 2 seconds period, you can change it to shorter, for example 1ms.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a timestamp when I receive an advertisement from another nRF51822 device?</title><link>https://devzone.nordicsemi.com/thread/314133?ContentTypeID=1</link><pubDate>Tue, 08 Jun 2021 09:09:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e3e859e1-53f8-4d6b-9e92-b3b8f69018d4</guid><dc:creator>tadanohito</dc:creator><description>&lt;p&gt;Thanks.&lt;/p&gt;
&lt;p&gt;There are no program compilation errors, but there are some problems.&lt;/p&gt;
&lt;p&gt;There were a few things I would like to ask about in your answer.&lt;/p&gt;
&lt;p&gt;Please forgive my questions.&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt;&lt;span&gt;Do you see the LED toggle every 2 seconds ?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;No, The central terminal has an LED blinking irregularly.&lt;/p&gt;
&lt;p&gt;When I checked the packets with teraterm, there were some garbled characters.&lt;/p&gt;
&lt;p&gt;Is it because I am receiving packets at intervals shorter than 2 seconds?&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt;When you receive an advertising packet, you can print this counter variable out.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This means that the value of the counter is (1,2.... .n) and I can calculate n&amp;times;2[s] or n&amp;times;10[ms]?&lt;/p&gt;
&lt;p&gt;Does that carry the risk of not being able to figure out the time when the packet is missing from the acquisition?&lt;/p&gt;
&lt;p&gt;P.S.&lt;/p&gt;
&lt;p&gt;What&amp;#39;s wrong with my program?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;..............
	float cnt;
APP_TIMER_DEF(my_timer_id1);
#define BATTERY_LEVEL_MEAS_INTERVAL      APP_TIMER_TICKS(2000, APP_TIMER_PRESCALER)  /**&amp;lt; Battery level measurement interval (ticks). */
#include &amp;quot;nrf_drv_clock.h&amp;quot;
#include &amp;quot;app_timer.h&amp;quot;

static void repeated_timer_handler(void * p_context)
{
uint32_t 	nrf_drv_gpiote_out_toggle();
nrf_drv_gpiote_out_toggle(LED_1);
cnt++;

}

static void on_ble_evt(ble_evt_t * p_ble_evt)
{
    uint32_t              err_code;
    const ble_gap_evt_t * p_gap_evt = &amp;amp;p_ble_evt-&amp;gt;evt.gap_evt;

	
																				

    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_ADV_REPORT:
        {
        				ble_gap_addr_t pa = p_gap_evt-&amp;gt;params.adv_report.peer_addr;
        				int8_t rssi = p_gap_evt-&amp;gt;params.adv_report.rssi;
        				printf(&amp;quot;Mac Address: %02x:%02x:%02x:%02x:%02x:%02x \r\n&amp;quot;, pa.addr[5], pa.addr[4], pa.addr[3], pa.addr[2], pa.addr[1], pa.addr[0]);
        				printf(&amp;quot;RSSI %d \r\n&amp;quot;, rssi);
        				
        				 // Create timers.
        				err_code = app_timer_create(&amp;amp;my_timer_id1,APP_TIMER_MODE_REPEATED, repeated_timer_handler);
        				APP_ERROR_CHECK(err_code);
        				
        				// Start application timers.
        				err_code = app_timer_start(my_timer_id1, BATTERY_LEVEL_MEAS_INTERVAL, NULL);
        				APP_ERROR_CHECK(err_code);
        				
        				printf(&amp;quot;%f \r\n&amp;quot;, cnt);
        
        const ble_gap_evt_adv_report_t * p_adv_report = &amp;amp;p_gap_evt-&amp;gt;params.adv_report;
        .............&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a timestamp when I receive an advertisement from another nRF51822 device?</title><link>https://devzone.nordicsemi.com/thread/314116?ContentTypeID=1</link><pubDate>Tue, 08 Jun 2021 08:32:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c31a1fd1-5071-48c0-ae8d-3860e3423c72</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Do you see the LED toggle every 2 seconds ?&amp;nbsp;&lt;br /&gt;If you do see the LED toggle, you can start to count time. You just increase the counter (a uint variable that you define) +1 inside&amp;nbsp;repeated_timer_handler(). This way you can start counting time.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;When you receive an advertising packet, you can print this counter variable out.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If 2 seconds is too long, you can change the counter to 10ms for example.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a timestamp when I receive an advertisement from another nRF51822 device?</title><link>https://devzone.nordicsemi.com/thread/314070?ContentTypeID=1</link><pubDate>Tue, 08 Jun 2021 06:06:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c8eba36-9a62-42f5-b19b-2893e04b340f</guid><dc:creator>tadanohito</dc:creator><description>&lt;p&gt;Thanks.&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt;&lt;span&gt;Why do you want to add&amp;nbsp;&lt;/span&gt;&lt;span&gt;sensorsim.c ?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;This is because I used the default battery_level_meas_timeout_handler of &amp;quot;ble_app_hrs&amp;quot;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I would like to observe the time variability of RSSI, is there anything I should set in the timeout handler?&lt;/p&gt;
&lt;p&gt;I quoted &amp;quot;repeated_timer_handler&amp;quot; as timeout handler() from your link.&lt;/p&gt;
&lt;p&gt;The code looks like the following.&amp;nbsp;This is only part of the code. The rest of the code is the same as &amp;quot;ble_app_uart_c&amp;quot; in central.&lt;/p&gt;
&lt;p&gt;I would like to display the timer as the packet arrives from peripheral, what should I printf()?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;APP_TIMER_DEF(my_timer_id1);
#define BATTERY_LEVEL_MEAS_INTERVAL      APP_TIMER_TICKS(2000, APP_TIMER_PRESCALER)  /**&amp;lt; Battery level measurement interval (ticks). */

static void repeated_timer_handler(void * p_context)
{
nrf_drv_gpiote_out_toggle(LED_1);
}
																																										
static void on_ble_evt(ble_evt_t * p_ble_evt)
{
    uint32_t              err_code;
    const ble_gap_evt_t * p_gap_evt = &amp;amp;p_ble_evt-&amp;gt;evt.gap_evt;


    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_ADV_REPORT:
        {
//get RSSI and MAC address
ble_gap_addr_t pa = p_gap_evt-&amp;gt;params.adv_report.peer_addr;
int8_t rssi = p_gap_evt-&amp;gt;params.adv_report.rssi;
printf(&amp;quot;Mac Address: %02x:%02x:%02x:%02x:%02x:%02x \r\n&amp;quot;, pa.addr[5], pa.addr[4], pa.addr[3], pa.addr[2], pa.addr[1], pa.addr[0]);
printf(&amp;quot;RSSI %d \r\n&amp;quot;, rssi);

// Create timers.
err_code = app_timer_create(&amp;amp;my_timer_id1,APP_TIMER_MODE_REPEATED, repeated_timer_handler);
APP_ERROR_CHECK(err_code);

// Start application timers.
err_code = app_timer_start(my_timer_id1, BATTERY_LEVEL_MEAS_INTERVAL, NULL);
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: How to get a timestamp when I receive an advertisement from another nRF51822 device?</title><link>https://devzone.nordicsemi.com/thread/313983?ContentTypeID=1</link><pubDate>Mon, 07 Jun 2021 14:54:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d8760f7c-8c38-4a97-bc96-c7d22fe7531a</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;br /&gt;Why do you want to add&amp;nbsp;&lt;span&gt;sensorsim.c ?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;What you need to do is to just enable an app_timer and then you can try to blink an LED for example.&amp;nbsp;&lt;br /&gt;Maybe this tutorial can help:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/nordic/short-range-guides/b/software-development-kit/posts/application-timer-tutorial"&gt;https://devzone.nordicsemi.com/nordic/short-range-guides/b/software-development-kit/posts/application-timer-tutorial&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Please look into the example and the code I quoted. You just need to call&amp;nbsp;APP_TIMER_DEF(m_battery_timer_id); . Replace&amp;nbsp;&amp;nbsp;m_battery_timer_id with your own app timer id you want to call. Then call the functions I quoted in my previous reply.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Inside&amp;nbsp;battery_level_meas_timeout_handler() you can do what ever you want, it will occur every second.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a timestamp when I receive an advertisement from another nRF51822 device?</title><link>https://devzone.nordicsemi.com/thread/313801?ContentTypeID=1</link><pubDate>Mon, 07 Jun 2021 02:59:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:056432a2-70ba-4958-8b93-9bd151adf39d</guid><dc:creator>tadanohito</dc:creator><description>&lt;p&gt;Thanks.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;quot;sensorsim.h&amp;quot;				
#include &amp;quot;ble_bas.h&amp;quot;
#define BATTERY_LEVEL_MEAS_INTERVAL      APP_TIMER_TICKS(2000, APP_TIMER_PRESCALER)  /**&amp;lt; Battery level measurement interval (ticks). */
#define MIN_BATTERY_LEVEL                81                                          /**&amp;lt; Minimum simulated battery level. */
#define MAX_BATTERY_LEVEL                100                                         /**&amp;lt; Maximum simulated 7battery level. */
#define BATTERY_LEVEL_INCREMENT          1                                           /**&amp;lt; Increment between each simulated battery level measurement. */

#define NRF_LOG_MODULE_NAME &amp;quot;APP&amp;quot;
#include &amp;quot;nrf_log.h&amp;quot;																																														
static sensorsim_cfg_t   m_battery_sim_cfg;               /**&amp;lt; Battery Level sensor simulator configuration. */
static sensorsim_state_t m_battery_sim_state;             /**&amp;lt; Battery Level sensor simulator state. */	
static uint16_t  m_conn_handle = BLE_CONN_HANDLE_INVALID; /**&amp;lt; Handle of the current connection. */
static ble_bas_t m_bas;                                   /**&amp;lt; Structure used to identify the battery service. */
static void sensor_simulator_init(void)
{
m_battery_sim_cfg.min          = MIN_BATTERY_LEVEL;
m_battery_sim_cfg.max          = MAX_BATTERY_LEVEL;
m_battery_sim_cfg.incr         = BATTERY_LEVEL_INCREMENT;
m_battery_sim_cfg.start_at_max = true;

sensorsim_init(&amp;amp;m_battery_sim_state, &amp;amp;m_battery_sim_cfg);

}

static void battery_level_update(void)
{
uint32_t err_code;
uint8_t  battery_level;

battery_level = (uint8_t)sensorsim_measure(&amp;amp;m_battery_sim_state, &amp;amp;m_battery_sim_cfg);

err_code = ble_bas_battery_level_update(&amp;amp;m_bas, battery_level);
if ((err_code != NRF_SUCCESS) &amp;amp;&amp;amp;
(err_code != NRF_ERROR_INVALID_STATE) &amp;amp;&amp;amp;
(err_code != BLE_ERROR_NO_TX_PACKETS) &amp;amp;&amp;amp;
(err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
)
{
APP_ERROR_HANDLER(err_code);
}
}
static void battery_level_meas_timeout_handler(void * p_context)
{
UNUSED_PARAMETER(p_context);
battery_level_update();
}&lt;/pre&gt;I tried to use &amp;quot;app_timer_start&amp;quot;. I copied the following code from &amp;quot;ble_app_hrs&amp;quot;.&lt;/p&gt;
&lt;p&gt;Then I added &amp;quot;sensorsim.c&amp;quot; to &amp;quot;nRF_Libraries&amp;quot; and &amp;quot;ble_bas.c&amp;quot; to &amp;quot;nRF_BLE_Services&amp;quot; of the project.&lt;/p&gt;
&lt;p&gt;Then I added these paths to &amp;quot;Setup Compiler&amp;quot;. However, I got the following error.&lt;br /&gt;. \build\nrf51422_xxac.axf: Error: L6218E: Undefined symbol ble_bas_battery_level_update (preferred from main.o).&lt;/p&gt;
&lt;p&gt;How can I solve this problem?&lt;/p&gt;
&lt;p&gt;I searched for this error, but could not find a solution.&lt;/p&gt;
&lt;p&gt;I found that &amp;quot;ble_bas_battery_level_update&amp;quot; is written in &amp;quot;ble_bas.c&amp;quot;.&lt;/p&gt;
&lt;p&gt;I tried &amp;quot;Go To Definition Of &amp;#39;ble_bas....update&amp;#39;&amp;quot;, but it came up undefined.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m sorry for asking for help so many times.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a timestamp when I receive an advertisement from another nRF51822 device?</title><link>https://devzone.nordicsemi.com/thread/313564?ContentTypeID=1</link><pubDate>Fri, 04 Jun 2021 07:49:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:68472b16-1ff1-415f-8120-48d66fa15698</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Have you looked at the ble_app_hrs example ?&amp;nbsp;&lt;br /&gt;For example here is the battery measuring timer declared:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    err_code = app_timer_create(&amp;amp;m_battery_timer_id,
                                APP_TIMER_MODE_REPEATED,
                                battery_level_meas_timeout_handler);
    APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Here is how it started:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    // Start application timers.
    err_code = app_timer_start(m_battery_timer_id, BATTERY_LEVEL_MEAS_INTERVAL, NULL);
    APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The interval is declared to 2 seconds (timeout_ticks):&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define BATTERY_LEVEL_MEAS_INTERVAL         APP_TIMER_TICKS(2000)   &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And the timeout handler is like this:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**@brief Function for handling the Battery measurement timer timeout.
 *
 * @details This function will be called each time the battery level measurement timer expires.
 *
 * @param[in] p_context  Pointer used for passing some arbitrary information (context) from the
 *                       app_start_timer() call to the timeout handler.
 */
static void battery_level_meas_timeout_handler(void * p_context)
{
    UNUSED_PARAMETER(p_context);
    battery_level_update();
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You can use a variable to count time (second, minute, hour etc) inside the handler.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a timestamp when I receive an advertisement from another nRF51822 device?</title><link>https://devzone.nordicsemi.com/thread/313534?ContentTypeID=1</link><pubDate>Fri, 04 Jun 2021 04:46:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64197a4b-c422-439f-8cfb-e95d62e96def</guid><dc:creator>tadanohito</dc:creator><description>&lt;p&gt;How do I set the timeout_handler in err_code = app_timer_create(&amp;amp;my_timer_id, mode, timeout_handler) and&amp;nbsp; timeout_ticks in app_timer_start (app_timer_id_t timer_id,uint32_t timeout_ticks,&amp;nbsp;void * p_context )?&lt;/p&gt;
&lt;p&gt;Are timeout_ticks arbitrarily determined?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a timestamp when I receive an advertisement from another nRF51822 device?</title><link>https://devzone.nordicsemi.com/thread/313165?ContentTypeID=1</link><pubDate>Wed, 02 Jun 2021 14:30:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:66bf83c1-96f5-4763-b66c-a8beb5ff25c7</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;You can start first with printing out RTC1-&amp;gt;COUNTER value when you print out the RSSI, it should give you a timestamp. I think your case the RTC running at 32768Hz.&amp;nbsp;&lt;br /&gt;Please look into other example (for example ble_app_hrs) and find how the app_timer is used , look for app_timer_init() and app_timer_start() function.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a timestamp when I receive an advertisement from another nRF51822 device?</title><link>https://devzone.nordicsemi.com/thread/313156?ContentTypeID=1</link><pubDate>Wed, 02 Jun 2021 14:08:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fd252ce5-c8e6-4b99-be5b-344974f179c7</guid><dc:creator>tadanohito</dc:creator><description>&lt;p&gt;Thank you for your answer.&lt;/p&gt;
&lt;p&gt;Sorry,&amp;nbsp;I&amp;#39;m new to nordic programming, so I can&amp;#39;t understand where and how to set the function to insert in this program.&lt;/p&gt;
&lt;p&gt;I&amp;#39;d appreciate it if you could tell me how to use those functions, if you don&amp;#39;t mind.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a timestamp when I receive an advertisement from another nRF51822 device?</title><link>https://devzone.nordicsemi.com/thread/313125?ContentTypeID=1</link><pubDate>Wed, 02 Jun 2021 13:08:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3f2a6d2b-e392-49e8-9f4e-04a0799ff062</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Tadanohito,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you don&amp;#39;t plan to have very precise You can use the app_timer to count time. You can set up your own timer and use a variable to count time. You can also simply use RTC1-&amp;gt;COUNTER to get the timestamp. Note that the RTC&amp;#39;s counter is 24 bit and usually it runs at 16384Hz so it will wrap around after 1024 seconds.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a timestamp when I receive an advertisement from another nRF51822 device?</title><link>https://devzone.nordicsemi.com/thread/313088?ContentTypeID=1</link><pubDate>Wed, 02 Jun 2021 12:08:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bfe743f3-21af-46b3-b0bc-e3e09e05223e</guid><dc:creator>awneil</dc:creator><description>[quote userid="104934" url="~/f/nordic-q-a/75905/how-to-get-a-timestamp-when-i-receive-an-advertisement-from-another-nrf51822-device/313083#313083"]just some elapsed time count[/quote]
&lt;p&gt;So just have a timer running at a suitable rate, and read its value when required&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a timestamp when I receive an advertisement from another nRF51822 device?</title><link>https://devzone.nordicsemi.com/thread/313083?ContentTypeID=1</link><pubDate>Wed, 02 Jun 2021 11:57:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:50779dfc-4963-4cb9-b1bc-2d36a1bd8ed4</guid><dc:creator>tadanohito</dc:creator><description>&lt;p&gt;Thank you for your answer.&lt;/p&gt;
&lt;p&gt;It&amp;#39;s the latter,&amp;nbsp;&lt;span&gt;just some elapsed time count.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I accessed the link, but I can&amp;#39;t figure out how to insert the nrfx ?&amp;nbsp; function.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a timestamp when I receive an advertisement from another nRF51822 device?</title><link>https://devzone.nordicsemi.com/thread/313069?ContentTypeID=1</link><pubDate>Wed, 02 Jun 2021 11:29:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:047cf914-5923-4f79-90a4-8c992d1d951c</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;What kind of &amp;quot;timestamp&amp;quot; are you looking for&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&amp;quot;wall-clock&amp;quot; time - year, month, day, hour, second, ... ?&lt;/li&gt;
&lt;li&gt;just some elapsed time count?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;what kind of accuracy &amp;amp; resolution do you need?&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/73786/timestamp-using-rtc-real-time-clock-for-nordic-thingy-52"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/73786/timestamp-using-rtc-real-time-clock-for-nordic-thingy-52&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>