<?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>I want to use NCS to acquire RSSI with a total of two nRF51s, one central and one peripheral.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/77744/i-want-to-use-ncs-to-acquire-rssi-with-a-total-of-two-nrf51s-one-central-and-one-peripheral</link><description>I want to use ncs to get the RSSI at 10ms intervals. 
 For example, central receives an empty packet from peripheral at 10ms interval. 
 I would like to know if there is a sample project or code that has the necessary connection intervals, functions for</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 05 Aug 2021 15:26:57 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/77744/i-want-to-use-ncs-to-acquire-rssi-with-a-total-of-two-nrf51s-one-central-and-one-peripheral" /><item><title>RE: I want to use NCS to acquire RSSI with a total of two nRF51s, one central and one peripheral.</title><link>https://devzone.nordicsemi.com/thread/323593?ContentTypeID=1</link><pubDate>Thu, 05 Aug 2021 15:26:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:61c1b937-7c0f-4eaa-bf21-288c2fc10f12</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can not use that function to read the RSSI when using the Bluetooth stack unfortunately. &lt;br /&gt;All that function is doing is reading the RSSISAMPLE register of the radio, but this has to be done by the Bluetooth stack, and not from the application.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For some pointers regarding reading RSSI from the Bluetooth stack you can have a look at this case:&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/70264/measuring-ble-connection-rssi-with-ncs"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/70264/measuring-ble-connection-rssi-with-ncs&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Please note that this has not been tested with the nRF51 series, so you might have to migrate to the nRF52 in order to get proper support for this.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I want to use NCS to acquire RSSI with a total of two nRF51s, one central and one peripheral.</title><link>https://devzone.nordicsemi.com/thread/322749?ContentTypeID=1</link><pubDate>Sat, 31 Jul 2021 13:37:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0b7201f6-0d36-4327-bed3-0042d058b0a6</guid><dc:creator>tadanohito</dc:creator><description>&lt;p&gt;Thanks.&lt;/p&gt;
&lt;p&gt;For &amp;quot;radio_rssi_get&amp;quot;, there is &amp;quot;uint32_t radio_rssi_get(void)&amp;quot; in &amp;quot;radio.c&amp;quot;.&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/aaa.JPG" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I want to use NCS to acquire RSSI with a total of two nRF51s, one central and one peripheral.</title><link>https://devzone.nordicsemi.com/thread/322635?ContentTypeID=1</link><pubDate>Fri, 30 Jul 2021 10:16:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3b861e2f-1b99-4d7f-9845-1f88f747c6f9</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am still not able to build the code, because the radio_rssi_get() function is missing:&lt;br /&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1627639304165v1.png" alt=" " /&gt;&lt;br /&gt;Is this a function you made yourself, or can it be found in one of the standard libraries?&lt;/p&gt;
[quote user="tadanohito"]1. The timestamp is no longer missing, but the display of teraterm is frequently wrong.[/quote]
&lt;p&gt;I will check this when I can get the code to run.&amp;nbsp;&lt;/p&gt;
[quote user="tadanohito"]2. Is it correct to understand that I can find the time by dividing the timestamp value by 32768 (clock frequency)?&amp;nbsp;[/quote]
&lt;p&gt;Most likely that is the case, yes, but this depends on the project configuration. There are makro&amp;#39;s that you can use to convert the cycles to seconds, as described here:&lt;br /&gt;&lt;a href="https://docs.zephyrproject.org/1.9.0/kernel/timing/clocks.html"&gt;https://docs.zephyrproject.org/1.9.0/kernel/timing/clocks.html&lt;/a&gt;&lt;/p&gt;
[quote user="tadanohito"]3.&amp;nbsp;&amp;nbsp;I believe that the program in my peripheral records the rssi and timestamp in response to polling from Central, but am I correct in my understanding?[/quote]
&lt;p&gt;As mentioned above I would like to be able to run the code first, in order to see how it works in practice.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
[quote user="tadanohito"]4. How can I fix the polling interval of central to 7.5ms?[/quote]
&lt;p&gt;&amp;nbsp;My colleague Simon shared a method for doing this in this case:&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/77381/sending-multiple-notify-packets-per-connection-interval"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/77381/sending-multiple-notify-packets-per-connection-interval&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Please note that in order to set the connection interval to 7.5ms instead of 15ms you should use a value of 6 instead of 12.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I want to use NCS to acquire RSSI with a total of two nRF51s, one central and one peripheral.</title><link>https://devzone.nordicsemi.com/thread/322265?ContentTypeID=1</link><pubDate>Wed, 28 Jul 2021 13:49:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9dd63b3c-e9d8-47d1-824b-89478cd8c10b</guid><dc:creator>tadanohito</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/8015.peripheral_5F00_uart.zip"&gt;devzone.nordicsemi.com/.../8015.peripheral_5F00_uart.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I use &amp;quot;build_nrf51dongle_nrf51422&amp;quot;&amp;gt;&amp;gt;&amp;quot;peripheral_uart&amp;quot;,and &amp;quot;central_uart&amp;quot;.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/4786.central_5F00_uart.zip"&gt;devzone.nordicsemi.com/.../4786.central_5F00_uart.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/_507D9C67_.JPG" /&gt;&lt;/p&gt;
&lt;p&gt;The code has changed again since last time.&lt;/p&gt;
&lt;p&gt;The question also changes a little. Sorry.&lt;/p&gt;
&lt;p&gt;The problem is as follows.&lt;/p&gt;
&lt;p&gt;1. The timestamp is no longer missing, but the display of teraterm is frequently wrong.&lt;/p&gt;
&lt;p&gt;2. Is it correct to understand that I can find the time by dividing the timestamp value by 32768 (clock frequency)?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;3.&amp;nbsp;&amp;nbsp;I believe that the program in my peripheral records the rssi and timestamp in response to polling from Central, but am I correct in my understanding?&lt;/p&gt;
&lt;p&gt;4. How can I fix the polling interval of central to 7.5ms?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I want to use NCS to acquire RSSI with a total of two nRF51s, one central and one peripheral.</title><link>https://devzone.nordicsemi.com/thread/322183?ContentTypeID=1</link><pubDate>Wed, 28 Jul 2021 09:48:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cbaaad5f-93a9-4ae8-a261-435f13269cb3</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I can try to run your code on my side, but it seems you didn&amp;#39;t include all the code, such as the implementation of the &lt;em&gt;radio_rssi_get()&lt;/em&gt; function?&lt;/p&gt;
&lt;p&gt;Are you able to just add your source files as attachments, instead of copy pasting the code into the case?&lt;/p&gt;
&lt;p&gt;Then it is easier for me to include it in a local project and see if I can get the code running.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I want to use NCS to acquire RSSI with a total of two nRF51s, one central and one peripheral.</title><link>https://devzone.nordicsemi.com/thread/321913?ContentTypeID=1</link><pubDate>Tue, 27 Jul 2021 01:09:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:87738b82-4056-4b7e-9c09-543a52bdb666</guid><dc:creator>tadanohito</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2018 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */

/** @file
 *  @brief Nordic UART Bridge Service (NUS) sample
 */
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;zephyr/types.h&amp;gt;
#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;drivers/uart.h&amp;gt;

#include &amp;lt;device.h&amp;gt;
#include &amp;lt;soc.h&amp;gt;

#include &amp;lt;bluetooth/bluetooth.h&amp;gt;
#include &amp;lt;bluetooth/uuid.h&amp;gt;
#include &amp;lt;bluetooth/gatt.h&amp;gt;
#include &amp;lt;bluetooth/hci.h&amp;gt;

#include &amp;lt;bluetooth/services/nus.h&amp;gt;

#include &amp;lt;dk_buttons_and_leds.h&amp;gt;

#include &amp;lt;settings/settings.h&amp;gt;

#include &amp;lt;stdio.h&amp;gt;

#include &amp;lt;logging/log.h&amp;gt;

#define LOG_MODULE_NAME peripheral_uart
LOG_MODULE_REGISTER(LOG_MODULE_NAME);

#define STACKSIZE CONFIG_BT_NUS_THREAD_STACK_SIZE
#define PRIORITY 7

#define DEVICE_NAME CONFIG_BT_DEVICE_NAME
#define DEVICE_NAME_LEN	(sizeof(DEVICE_NAME) - 1)

#define RUN_STATUS_LED DK_LED1
#define RUN_LED_BLINK_INTERVAL 1000

#define CON_STATUS_LED DK_LED2

#define KEY_PASSKEY_ACCEPT DK_BTN1_MSK
#define KEY_PASSKEY_REJECT DK_BTN2_MSK

#define UART_BUF_SIZE CONFIG_BT_NUS_UART_BUFFER_SIZE
#define UART_WAIT_FOR_BUF_DELAY K_MSEC(50)
#define UART_WAIT_FOR_RX CONFIG_BT_NUS_UART_RX_WAIT_TIME

static K_SEM_DEFINE(ble_init_ok, 0, 1);

static struct bt_conn *current_conn;
static struct bt_conn *auth_conn;

static const struct device *uart;
static struct k_delayed_work uart_work;

struct uart_data_t {
	void *fifo_reserved;
	uint8_t data[UART_BUF_SIZE];
	uint16_t len;
};

static K_FIFO_DEFINE(fifo_uart_tx_data);
static K_FIFO_DEFINE(fifo_uart_rx_data);

static const struct bt_data ad[] = {
	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
	BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
};

static const struct bt_data sd[] = {
	BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),
};
/*
device型はname,config設定のアドレス，API構造体のアドレス，コモンデバイスの状態のアドレス，デバイスインスタンスのプライベートデータのアドレス
デバイスに関連するハンドルへの任意のポインタを持つ

uart_evnetは現在のイベントに関する情報を含む構造体
*/
static void uart_cb(const struct device *dev, struct uart_event *evt, void *user_data)
{
	ARG_UNUSED(dev);

	static uint8_t *current_buf;
	static size_t aborted_len;
	static bool buf_release;
	struct uart_data_t *buf;
	static uint8_t *aborted_buf;

	switch (evt-&amp;gt;type) {
	case UART_TX_DONE:
		if ((evt-&amp;gt;data.tx.len == 0) ||
		    (!evt-&amp;gt;data.tx.buf)) {
			return;
		}

		if (aborted_buf) {
			buf = CONTAINER_OF(aborted_buf, struct uart_data_t,
					   data);
			aborted_buf = NULL;
			aborted_len = 0;
		} else {
			buf = CONTAINER_OF(evt-&amp;gt;data.tx.buf, struct uart_data_t,
					   data);
		}

		k_free(buf);

		buf = k_fifo_get(&amp;amp;fifo_uart_tx_data, K_NO_WAIT);
		if (!buf) {
			return;
		}

		if (uart_tx(uart, buf-&amp;gt;data, buf-&amp;gt;len, SYS_FOREVER_MS)) {
			LOG_WRN(&amp;quot;Failed to send data over UART&amp;quot;);
		}

		break;

	case UART_RX_RDY:
		buf = CONTAINER_OF(evt-&amp;gt;data.rx.buf, struct uart_data_t, data);
		buf-&amp;gt;len += evt-&amp;gt;data.rx.len;
		buf_release = false;

		if (buf-&amp;gt;len == UART_BUF_SIZE) {
			k_fifo_put(&amp;amp;fifo_uart_rx_data, buf);
		} else if ((evt-&amp;gt;data.rx.buf[buf-&amp;gt;len - 1] == &amp;#39;\n&amp;#39;) ||
			  (evt-&amp;gt;data.rx.buf[buf-&amp;gt;len - 1] == &amp;#39;\r&amp;#39;)) {
                        /* k_fifo_putは第二引数のbufを    
                          fifo先入れ先出しのアドレスに追加している
                        */   
			k_fifo_put(&amp;amp;fifo_uart_rx_data, buf);
			current_buf = evt-&amp;gt;data.rx.buf;
			buf_release = true;
			uart_rx_disable(uart);
		}

		break;

	case UART_RX_DISABLED:
		buf = k_malloc(sizeof(*buf));
		if (buf) {
			buf-&amp;gt;len = 0;
		} else {
			LOG_WRN(&amp;quot;Not able to allocate UART receive buffer&amp;quot;);
			k_delayed_work_submit(&amp;amp;uart_work,
					      UART_WAIT_FOR_BUF_DELAY);
			return;
		}

		uart_rx_enable(uart, buf-&amp;gt;data, sizeof(buf-&amp;gt;data),
			       UART_WAIT_FOR_RX);

		break;

	case UART_RX_BUF_REQUEST:
		buf = k_malloc(sizeof(*buf));
		if (buf) {
			buf-&amp;gt;len = 0;
			uart_rx_buf_rsp(uart, buf-&amp;gt;data, sizeof(buf-&amp;gt;data));
		} else {
			LOG_WRN(&amp;quot;Not able to allocate UART receive buffer&amp;quot;);
		}

		break;

	case UART_RX_BUF_RELEASED:
		buf = CONTAINER_OF(evt-&amp;gt;data.rx_buf.buf, struct uart_data_t,
				   data);
		if (buf_release &amp;amp;&amp;amp; (current_buf != evt-&amp;gt;data.rx_buf.buf)) {
			k_free(buf);
			buf_release = false;
			current_buf = NULL;
		}

		break;

	case UART_TX_ABORTED:
			if (!aborted_buf) {
				aborted_buf = (uint8_t *)evt-&amp;gt;data.tx.buf;
			}

			aborted_len += evt-&amp;gt;data.tx.len;
			buf = CONTAINER_OF(aborted_buf, struct uart_data_t,
					   data);

			uart_tx(uart, &amp;amp;buf-&amp;gt;data[aborted_len],
				buf-&amp;gt;len - aborted_len, SYS_FOREVER_MS);

		break;

	default:
		break;
	}
}

static void uart_work_handler(struct k_work *item)
{
	struct uart_data_t *buf;

	buf = k_malloc(sizeof(*buf));
	if (buf) {
		buf-&amp;gt;len = 0;
	} else {
		LOG_WRN(&amp;quot;Not able to allocate UART receive buffer&amp;quot;);
		k_delayed_work_submit(&amp;amp;uart_work, UART_WAIT_FOR_BUF_DELAY);
		return;
	}

	uart_rx_enable(uart, buf-&amp;gt;data, sizeof(buf-&amp;gt;data), UART_WAIT_FOR_RX);
}

static int uart_init(void)
{
	int err;
	struct uart_data_t *rx;

	uart = device_get_binding(DT_LABEL(DT_NODELABEL(uart0)));
	if (!uart) {
		return -ENXIO;
	}

	rx = k_malloc(sizeof(*rx));
	if (rx) {
		rx-&amp;gt;len = 0;
	} else {
		return -ENOMEM;
	}

	k_delayed_work_init(&amp;amp;uart_work, uart_work_handler);

	err = uart_callback_set(uart, uart_cb, NULL);
	if (err) {
		return err;
	}

	return uart_rx_enable(uart, rx-&amp;gt;data, sizeof(rx-&amp;gt;data), 50);
}

static void connected(struct bt_conn *conn, uint8_t err)
{
	char addr[BT_ADDR_LE_STR_LEN];

	if (err) {
		LOG_ERR(&amp;quot;Connection failed (err %u)&amp;quot;, err);
		return;
	}

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
	LOG_INF(&amp;quot;Connected %s&amp;quot;, log_strdup(addr));

	current_conn = bt_conn_ref(conn);

	dk_set_led_on(CON_STATUS_LED);
}

static void disconnected(struct bt_conn *conn, uint8_t reason)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	LOG_INF(&amp;quot;Disconnected: %s (reason %u)&amp;quot;, log_strdup(addr), reason);

	if (auth_conn) {
		bt_conn_unref(auth_conn);
		auth_conn = NULL;
	}

	if (current_conn) {
		bt_conn_unref(current_conn);
		current_conn = NULL;
		dk_set_led_off(CON_STATUS_LED);
	}
}

#ifdef CONFIG_BT_NUS_SECURITY_ENABLED
static void security_changed(struct bt_conn *conn, bt_security_t level,
			     enum bt_security_err err)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	if (!err) {
		LOG_INF(&amp;quot;Security changed: %s level %u&amp;quot;, log_strdup(addr),
			level);
	} else {
		LOG_WRN(&amp;quot;Security failed: %s level %u err %d&amp;quot;, log_strdup(addr),
			level, err);
	}
}
#endif

static struct bt_conn_cb conn_callbacks = {
	.connected    = connected,
	.disconnected = disconnected,
#ifdef CONFIG_BT_NUS_SECURITY_ENABLED
	.security_changed = security_changed,
#endif
};

#if defined(CONFIG_BT_NUS_SECURITY_ENABLED)
static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	LOG_INF(&amp;quot;Passkey for %s: %06u&amp;quot;, log_strdup(addr), passkey);
}

static void auth_passkey_confirm(struct bt_conn *conn, unsigned int passkey)
{
	char addr[BT_ADDR_LE_STR_LEN];

	auth_conn = bt_conn_ref(conn);

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	LOG_INF(&amp;quot;Passkey for %s: %06u&amp;quot;, log_strdup(addr), passkey);
	LOG_INF(&amp;quot;Press Button 1 to confirm, Button 2 to reject.&amp;quot;);
}


static void auth_cancel(struct bt_conn *conn)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	LOG_INF(&amp;quot;Pairing cancelled: %s&amp;quot;, log_strdup(addr));
}


static void pairing_confirm(struct bt_conn *conn)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	bt_conn_auth_pairing_confirm(conn);

	LOG_INF(&amp;quot;Pairing confirmed: %s&amp;quot;, log_strdup(addr));
}


static void pairing_complete(struct bt_conn *conn, bool bonded)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	LOG_INF(&amp;quot;Pairing completed: %s, bonded: %d&amp;quot;, log_strdup(addr),
		bonded);
}


static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	LOG_INF(&amp;quot;Pairing failed conn: %s, reason %d&amp;quot;, log_strdup(addr),
		reason);
}


static struct bt_conn_auth_cb conn_auth_callbacks = {
	.passkey_display = auth_passkey_display,
	.passkey_confirm = auth_passkey_confirm,
	.cancel = auth_cancel,
	.pairing_confirm = pairing_confirm,
	.pairing_complete = pairing_complete,
	.pairing_failed = pairing_failed
};
#else
static struct bt_conn_auth_cb conn_auth_callbacks;
#endif

static void bt_receive_cb(struct bt_conn *conn, const uint8_t *const data,
			  uint16_t len)
{
	int err;
	char addr[BT_ADDR_LE_STR_LEN] = {0};

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, ARRAY_SIZE(addr));

	LOG_INF(&amp;quot;Received data from: %s&amp;quot;, log_strdup(addr));

	for (uint16_t pos = 0; pos != len;) {
		struct uart_data_t *tx = k_malloc(sizeof(*tx));

		if (!tx) {
			LOG_WRN(&amp;quot;Not able to allocate UART send data buffer&amp;quot;);
			return;
		}

		/* Keep the last byte of TX buffer for potential LF char. */
		size_t tx_data_size = sizeof(tx-&amp;gt;data) - 1;

		if ((len - pos) &amp;gt; tx_data_size) {
			tx-&amp;gt;len = tx_data_size;
		} else {
			tx-&amp;gt;len = (len - pos);
		}

		memcpy(tx-&amp;gt;data, &amp;amp;data[pos], tx-&amp;gt;len);

		pos += tx-&amp;gt;len;

		/* Append the LF character when the CR character triggered
		 * transmission from the peer.
		 */
		if ((pos == len) &amp;amp;&amp;amp; (data[len - 1] == &amp;#39;\r&amp;#39;)) {
			tx-&amp;gt;data[tx-&amp;gt;len] = &amp;#39;\n&amp;#39;;
			tx-&amp;gt;len++;
		}

		err = uart_tx(uart, tx-&amp;gt;data, tx-&amp;gt;len, SYS_FOREVER_MS);
		if (err) {
			k_fifo_put(&amp;amp;fifo_uart_tx_data, tx);
		}
	}
}

static struct bt_nus_cb nus_cb = {
	.received = bt_receive_cb,
};

void error(void)
{
	dk_set_leds_state(DK_ALL_LEDS_MSK, DK_NO_LEDS_MSK);

	while (true) {
		/* Spin for ever */
		k_sleep(K_MSEC(1000));
	}
}

static void num_comp_reply(bool accept)
{
	if (accept) {
		bt_conn_auth_passkey_confirm(auth_conn);
		LOG_INF(&amp;quot;Numeric Match, conn %p&amp;quot;, (void *)auth_conn);
	} else {
		bt_conn_auth_cancel(auth_conn);
		LOG_INF(&amp;quot;Numeric Reject, conn %p&amp;quot;, (void *)auth_conn);
	}

	bt_conn_unref(auth_conn);
	auth_conn = NULL;
}

void button_changed(uint32_t button_state, uint32_t has_changed)
{
	uint32_t buttons = button_state &amp;amp; has_changed;

	if (auth_conn) {
		if (buttons &amp;amp; KEY_PASSKEY_ACCEPT) {
			num_comp_reply(true);
		}

		if (buttons &amp;amp; KEY_PASSKEY_REJECT) {
			num_comp_reply(false);
		}
	}
}

static void configure_gpio(void)
{
	int err;

	err = dk_buttons_init(button_changed);
	if (err) {
		LOG_ERR(&amp;quot;Cannot init buttons (err: %d)&amp;quot;, err);
	}

	err = dk_leds_init();
	if (err) {
		LOG_ERR(&amp;quot;Cannot init LEDs (err: %d)&amp;quot;, err);
	}
}

void main(void)
{
	int blink_status = 0;
	int err = 0;

	configure_gpio();

	err = uart_init();
	if (err) {
		error();
	}

	bt_conn_cb_register(&amp;amp;conn_callbacks);

	if (IS_ENABLED(CONFIG_BT_NUS_SECURITY_ENABLED)) {
		bt_conn_auth_cb_register(&amp;amp;conn_auth_callbacks);
	}

	err = bt_enable(NULL);
	if (err) {
		error();
	}

	LOG_INF(&amp;quot;Bluetooth initialized&amp;quot;);

	k_sem_give(&amp;amp;ble_init_ok);

	if (IS_ENABLED(CONFIG_SETTINGS)) {
		settings_load();
	}

	err = bt_nus_init(&amp;amp;nus_cb);
	if (err) {
		LOG_ERR(&amp;quot;Failed to initialize UART service (err: %d)&amp;quot;, err);
		return;
	}

	err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), sd,
			      ARRAY_SIZE(sd));
	if (err) {
		LOG_ERR(&amp;quot;Advertising failed to start (err %d)&amp;quot;, err);
	}

	printk(&amp;quot;Starting Nordic UART service example\n&amp;quot;);

	for (;;) {
		dk_set_led(RUN_STATUS_LED, (++blink_status) % 2);
		k_sleep(K_MSEC(RUN_LED_BLINK_INTERVAL));
	}
}
                                                                     
                                                                     
                                                                     uint32_t radio_rssi_get(void);
                                                                    

                      #define SYS_CLOCK_HW_CYCLES_TO_NS(X) (uint32_t)(SYS_CLOCK_HW_CYCLES_TO_NS64(X))

                      /* SYS_CLOCK_HW_CYCLES_TO_NS64 converts CPU clock cycles to nanoseconds */
                      #define SYS_CLOCK_HW_CYCLES_TO_NS64(X) \
                              (((uint64_t)(X) * NSEC_PER_SEC) / sys_clock_hw_cycles_per_sec())       
                                                 





void ble_write_thread(void)
{
                      uint32_t start_time;
                      uint32_t stop_time;
                      uint32_t cycles_spent;
                      uint32_t nanoseconds_spent;
                      /* capture initial time stamp */
                      start_time = k_cycle_get_32();




/* Don&amp;#39;t go any further until BLE is initialized */
k_sem_take(&amp;amp;ble_init_ok, K_FOREVER);
                                                                
                                                                  
                                                                  uint32_t rssi;
                                                                  char buf2[30];
                                      
                                                                  while(1){
                                                                  rssi = radio_rssi_get();
                    
                      
                      
                      
                      /* capture final time stamp */
                      stop_time = k_cycle_get_32();

                      /* compute how long the work took (assumes no counter rollover) */
                      cycles_spent = stop_time - start_time;
                      nanoseconds_spent = SYS_CLOCK_HW_CYCLES_TO_NS(cycles_spent);


                      sprintf(buf2,&amp;quot;%012d\t%zu\r\n&amp;quot;,rssi,nanoseconds_spent);
                                                                   
                                                                    
                                                                    bt_nus_send(NULL,buf2,28);
                                                                    }
        

}

K_THREAD_DEFINE(ble_write_thread_id, STACKSIZE, ble_write_thread, NULL, NULL,
		NULL, PRIORITY, 0, 0);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I modified the code again, and implemented a function to record rssi and timestamp when polling is received from central.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;However, I don&amp;#39;t understand the clock settings, so I don&amp;#39;t understand the meaning of the time lapse values displayed.&lt;/p&gt;
&lt;p&gt;And why does the counter sometimes skip?&lt;/p&gt;
&lt;p&gt;Also, I would like to know the code to control the polling interval of central.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/_AB30A630F330C830_.JPG" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I want to use NCS to acquire RSSI with a total of two nRF51s, one central and one peripheral.</title><link>https://devzone.nordicsemi.com/thread/321761?ContentTypeID=1</link><pubDate>Mon, 26 Jul 2021 09:52:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8f61407d-e856-43a2-a39c-41902d8abc32</guid><dc:creator>tadanohito</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2018 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */

/** @file
 *  @brief Nordic UART Bridge Service (NUS) sample
 */
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;zephyr/types.h&amp;gt;
#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;drivers/uart.h&amp;gt;

#include &amp;lt;device.h&amp;gt;
#include &amp;lt;soc.h&amp;gt;

#include &amp;lt;bluetooth/bluetooth.h&amp;gt;
#include &amp;lt;bluetooth/uuid.h&amp;gt;
#include &amp;lt;bluetooth/gatt.h&amp;gt;
#include &amp;lt;bluetooth/hci.h&amp;gt;

#include &amp;lt;bluetooth/services/nus.h&amp;gt;

#include &amp;lt;dk_buttons_and_leds.h&amp;gt;

#include &amp;lt;settings/settings.h&amp;gt;

#include &amp;lt;stdio.h&amp;gt;

#include &amp;lt;logging/log.h&amp;gt;

#define LOG_MODULE_NAME peripheral_uart
LOG_MODULE_REGISTER(LOG_MODULE_NAME);

#define STACKSIZE CONFIG_BT_NUS_THREAD_STACK_SIZE
#define PRIORITY 7

#define DEVICE_NAME CONFIG_BT_DEVICE_NAME
#define DEVICE_NAME_LEN	(sizeof(DEVICE_NAME) - 1)

#define RUN_STATUS_LED DK_LED1
#define RUN_LED_BLINK_INTERVAL 1000

#define CON_STATUS_LED DK_LED2

#define KEY_PASSKEY_ACCEPT DK_BTN1_MSK
#define KEY_PASSKEY_REJECT DK_BTN2_MSK

#define UART_BUF_SIZE CONFIG_BT_NUS_UART_BUFFER_SIZE
#define UART_WAIT_FOR_BUF_DELAY K_MSEC(50)
#define UART_WAIT_FOR_RX CONFIG_BT_NUS_UART_RX_WAIT_TIME

static K_SEM_DEFINE(ble_init_ok, 0, 1);

static struct bt_conn *current_conn;
static struct bt_conn *auth_conn;

static const struct device *uart;
static struct k_delayed_work uart_work;

struct uart_data_t {
	void *fifo_reserved;
	uint8_t data[UART_BUF_SIZE];
	uint16_t len;
};

static K_FIFO_DEFINE(fifo_uart_tx_data);
static K_FIFO_DEFINE(fifo_uart_rx_data);

static const struct bt_data ad[] = {
	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
	BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
};

static const struct bt_data sd[] = {
	BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),
};
/*
device型はname,config設定のアドレス，API構造体のアドレス，コモンデバイスの状態のアドレス，デバイスインスタンスのプライベートデータのアドレス
デバイスに関連するハンドルへの任意のポインタを持つ

uart_evnetは現在のイベントに関する情報を含む構造体
*/
static void uart_cb(const struct device *dev, struct uart_event *evt, void *user_data)
{
	ARG_UNUSED(dev);

	static uint8_t *current_buf;
	static size_t aborted_len;
	static bool buf_release;
	struct uart_data_t *buf;
	static uint8_t *aborted_buf;

	switch (evt-&amp;gt;type) {
	case UART_TX_DONE:
		if ((evt-&amp;gt;data.tx.len == 0) ||
		    (!evt-&amp;gt;data.tx.buf)) {
			return;
		}

		if (aborted_buf) {
			buf = CONTAINER_OF(aborted_buf, struct uart_data_t,
					   data);
			aborted_buf = NULL;
			aborted_len = 0;
		} else {
			buf = CONTAINER_OF(evt-&amp;gt;data.tx.buf, struct uart_data_t,
					   data);
		}

		k_free(buf);

		buf = k_fifo_get(&amp;amp;fifo_uart_tx_data, K_NO_WAIT);
		if (!buf) {
			return;
		}

		if (uart_tx(uart, buf-&amp;gt;data, buf-&amp;gt;len, SYS_FOREVER_MS)) {
			LOG_WRN(&amp;quot;Failed to send data over UART&amp;quot;);
		}

		break;

	case UART_RX_RDY:
		buf = CONTAINER_OF(evt-&amp;gt;data.rx.buf, struct uart_data_t, data);
		buf-&amp;gt;len += evt-&amp;gt;data.rx.len;
		buf_release = false;

		if (buf-&amp;gt;len == UART_BUF_SIZE) {
			k_fifo_put(&amp;amp;fifo_uart_rx_data, buf);
		} else if ((evt-&amp;gt;data.rx.buf[buf-&amp;gt;len - 1] == &amp;#39;\n&amp;#39;) ||
			  (evt-&amp;gt;data.rx.buf[buf-&amp;gt;len - 1] == &amp;#39;\r&amp;#39;)) {
                        /* k_fifo_putは第二引数のbufを    
                          fifo先入れ先出しのアドレスに追加している
                        */   
			k_fifo_put(&amp;amp;fifo_uart_rx_data, buf);
			current_buf = evt-&amp;gt;data.rx.buf;
			buf_release = true;
			uart_rx_disable(uart);
		}

		break;

	case UART_RX_DISABLED:
		buf = k_malloc(sizeof(*buf));
		if (buf) {
			buf-&amp;gt;len = 0;
		} else {
			LOG_WRN(&amp;quot;Not able to allocate UART receive buffer&amp;quot;);
			k_delayed_work_submit(&amp;amp;uart_work,
					      UART_WAIT_FOR_BUF_DELAY);
			return;
		}

		uart_rx_enable(uart, buf-&amp;gt;data, sizeof(buf-&amp;gt;data),
			       UART_WAIT_FOR_RX);

		break;

	case UART_RX_BUF_REQUEST:
		buf = k_malloc(sizeof(*buf));
		if (buf) {
			buf-&amp;gt;len = 0;
			uart_rx_buf_rsp(uart, buf-&amp;gt;data, sizeof(buf-&amp;gt;data));
		} else {
			LOG_WRN(&amp;quot;Not able to allocate UART receive buffer&amp;quot;);
		}

		break;

	case UART_RX_BUF_RELEASED:
		buf = CONTAINER_OF(evt-&amp;gt;data.rx_buf.buf, struct uart_data_t,
				   data);
		if (buf_release &amp;amp;&amp;amp; (current_buf != evt-&amp;gt;data.rx_buf.buf)) {
			k_free(buf);
			buf_release = false;
			current_buf = NULL;
		}

		break;

	case UART_TX_ABORTED:
			if (!aborted_buf) {
				aborted_buf = (uint8_t *)evt-&amp;gt;data.tx.buf;
			}

			aborted_len += evt-&amp;gt;data.tx.len;
			buf = CONTAINER_OF(aborted_buf, struct uart_data_t,
					   data);

			uart_tx(uart, &amp;amp;buf-&amp;gt;data[aborted_len],
				buf-&amp;gt;len - aborted_len, SYS_FOREVER_MS);

		break;

	default:
		break;
	}
}

static void uart_work_handler(struct k_work *item)
{
	struct uart_data_t *buf;

	buf = k_malloc(sizeof(*buf));
	if (buf) {
		buf-&amp;gt;len = 0;
	} else {
		LOG_WRN(&amp;quot;Not able to allocate UART receive buffer&amp;quot;);
		k_delayed_work_submit(&amp;amp;uart_work, UART_WAIT_FOR_BUF_DELAY);
		return;
	}

	uart_rx_enable(uart, buf-&amp;gt;data, sizeof(buf-&amp;gt;data), UART_WAIT_FOR_RX);
}

static int uart_init(void)
{
	int err;
	struct uart_data_t *rx;

	uart = device_get_binding(DT_LABEL(DT_NODELABEL(uart0)));
	if (!uart) {
		return -ENXIO;
	}

	rx = k_malloc(sizeof(*rx));
	if (rx) {
		rx-&amp;gt;len = 0;
	} else {
		return -ENOMEM;
	}

	k_delayed_work_init(&amp;amp;uart_work, uart_work_handler);

	err = uart_callback_set(uart, uart_cb, NULL);
	if (err) {
		return err;
	}

	return uart_rx_enable(uart, rx-&amp;gt;data, sizeof(rx-&amp;gt;data), 50);
}

static void connected(struct bt_conn *conn, uint8_t err)
{
	char addr[BT_ADDR_LE_STR_LEN];

	if (err) {
		LOG_ERR(&amp;quot;Connection failed (err %u)&amp;quot;, err);
		return;
	}

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
	LOG_INF(&amp;quot;Connected %s&amp;quot;, log_strdup(addr));

	current_conn = bt_conn_ref(conn);

	dk_set_led_on(CON_STATUS_LED);
}

static void disconnected(struct bt_conn *conn, uint8_t reason)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	LOG_INF(&amp;quot;Disconnected: %s (reason %u)&amp;quot;, log_strdup(addr), reason);

	if (auth_conn) {
		bt_conn_unref(auth_conn);
		auth_conn = NULL;
	}

	if (current_conn) {
		bt_conn_unref(current_conn);
		current_conn = NULL;
		dk_set_led_off(CON_STATUS_LED);
	}
}

#ifdef CONFIG_BT_NUS_SECURITY_ENABLED
static void security_changed(struct bt_conn *conn, bt_security_t level,
			     enum bt_security_err err)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	if (!err) {
		LOG_INF(&amp;quot;Security changed: %s level %u&amp;quot;, log_strdup(addr),
			level);
	} else {
		LOG_WRN(&amp;quot;Security failed: %s level %u err %d&amp;quot;, log_strdup(addr),
			level, err);
	}
}
#endif

static struct bt_conn_cb conn_callbacks = {
	.connected    = connected,
	.disconnected = disconnected,
#ifdef CONFIG_BT_NUS_SECURITY_ENABLED
	.security_changed = security_changed,
#endif
};

#if defined(CONFIG_BT_NUS_SECURITY_ENABLED)
static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	LOG_INF(&amp;quot;Passkey for %s: %06u&amp;quot;, log_strdup(addr), passkey);
}

static void auth_passkey_confirm(struct bt_conn *conn, unsigned int passkey)
{
	char addr[BT_ADDR_LE_STR_LEN];

	auth_conn = bt_conn_ref(conn);

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	LOG_INF(&amp;quot;Passkey for %s: %06u&amp;quot;, log_strdup(addr), passkey);
	LOG_INF(&amp;quot;Press Button 1 to confirm, Button 2 to reject.&amp;quot;);
}


static void auth_cancel(struct bt_conn *conn)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	LOG_INF(&amp;quot;Pairing cancelled: %s&amp;quot;, log_strdup(addr));
}


static void pairing_confirm(struct bt_conn *conn)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	bt_conn_auth_pairing_confirm(conn);

	LOG_INF(&amp;quot;Pairing confirmed: %s&amp;quot;, log_strdup(addr));
}


static void pairing_complete(struct bt_conn *conn, bool bonded)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	LOG_INF(&amp;quot;Pairing completed: %s, bonded: %d&amp;quot;, log_strdup(addr),
		bonded);
}


static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	LOG_INF(&amp;quot;Pairing failed conn: %s, reason %d&amp;quot;, log_strdup(addr),
		reason);
}


static struct bt_conn_auth_cb conn_auth_callbacks = {
	.passkey_display = auth_passkey_display,
	.passkey_confirm = auth_passkey_confirm,
	.cancel = auth_cancel,
	.pairing_confirm = pairing_confirm,
	.pairing_complete = pairing_complete,
	.pairing_failed = pairing_failed
};
#else
static struct bt_conn_auth_cb conn_auth_callbacks;
#endif

static void bt_receive_cb(struct bt_conn *conn, const uint8_t *const data,
			  uint16_t len)
{
	int err;
	char addr[BT_ADDR_LE_STR_LEN] = {0};

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, ARRAY_SIZE(addr));

	LOG_INF(&amp;quot;Received data from: %s&amp;quot;, log_strdup(addr));

	for (uint16_t pos = 0; pos != len;) {
		struct uart_data_t *tx = k_malloc(sizeof(*tx));

		if (!tx) {
			LOG_WRN(&amp;quot;Not able to allocate UART send data buffer&amp;quot;);
			return;
		}

		/* Keep the last byte of TX buffer for potential LF char. */
		size_t tx_data_size = sizeof(tx-&amp;gt;data) - 1;

		if ((len - pos) &amp;gt; tx_data_size) {
			tx-&amp;gt;len = tx_data_size;
		} else {
			tx-&amp;gt;len = (len - pos);
		}

		memcpy(tx-&amp;gt;data, &amp;amp;data[pos], tx-&amp;gt;len);

		pos += tx-&amp;gt;len;

		/* Append the LF character when the CR character triggered
		 * transmission from the peer.
		 */
		if ((pos == len) &amp;amp;&amp;amp; (data[len - 1] == &amp;#39;\r&amp;#39;)) {
			tx-&amp;gt;data[tx-&amp;gt;len] = &amp;#39;\n&amp;#39;;
			tx-&amp;gt;len++;
		}

		err = uart_tx(uart, tx-&amp;gt;data, tx-&amp;gt;len, SYS_FOREVER_MS);
		if (err) {
			k_fifo_put(&amp;amp;fifo_uart_tx_data, tx);
		}
	}
}

static struct bt_nus_cb nus_cb = {
	.received = bt_receive_cb,
};

void error(void)
{
	dk_set_leds_state(DK_ALL_LEDS_MSK, DK_NO_LEDS_MSK);

	while (true) {
		/* Spin for ever */
		k_sleep(K_MSEC(1000));
	}
}

static void num_comp_reply(bool accept)
{
	if (accept) {
		bt_conn_auth_passkey_confirm(auth_conn);
		LOG_INF(&amp;quot;Numeric Match, conn %p&amp;quot;, (void *)auth_conn);
	} else {
		bt_conn_auth_cancel(auth_conn);
		LOG_INF(&amp;quot;Numeric Reject, conn %p&amp;quot;, (void *)auth_conn);
	}

	bt_conn_unref(auth_conn);
	auth_conn = NULL;
}

void button_changed(uint32_t button_state, uint32_t has_changed)
{
	uint32_t buttons = button_state &amp;amp; has_changed;

	if (auth_conn) {
		if (buttons &amp;amp; KEY_PASSKEY_ACCEPT) {
			num_comp_reply(true);
		}

		if (buttons &amp;amp; KEY_PASSKEY_REJECT) {
			num_comp_reply(false);
		}
	}
}

static void configure_gpio(void)
{
	int err;

	err = dk_buttons_init(button_changed);
	if (err) {
		LOG_ERR(&amp;quot;Cannot init buttons (err: %d)&amp;quot;, err);
	}

	err = dk_leds_init();
	if (err) {
		LOG_ERR(&amp;quot;Cannot init LEDs (err: %d)&amp;quot;, err);
	}
}

void main(void)
{
	int blink_status = 0;
	int err = 0;

	configure_gpio();

	err = uart_init();
	if (err) {
		error();
	}

	bt_conn_cb_register(&amp;amp;conn_callbacks);

	if (IS_ENABLED(CONFIG_BT_NUS_SECURITY_ENABLED)) {
		bt_conn_auth_cb_register(&amp;amp;conn_auth_callbacks);
	}

	err = bt_enable(NULL);
	if (err) {
		error();
	}

	LOG_INF(&amp;quot;Bluetooth initialized&amp;quot;);

	k_sem_give(&amp;amp;ble_init_ok);

	if (IS_ENABLED(CONFIG_SETTINGS)) {
		settings_load();
	}

	err = bt_nus_init(&amp;amp;nus_cb);
	if (err) {
		LOG_ERR(&amp;quot;Failed to initialize UART service (err: %d)&amp;quot;, err);
		return;
	}

	err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), sd,
			      ARRAY_SIZE(sd));
	if (err) {
		LOG_ERR(&amp;quot;Advertising failed to start (err %d)&amp;quot;, err);
	}

	printk(&amp;quot;Starting Nordic UART service example\n&amp;quot;);

	for (;;) {
		dk_set_led(RUN_STATUS_LED, (++blink_status) % 2);
		k_sleep(K_MSEC(RUN_LED_BLINK_INTERVAL));
	}
}
                                                                     uint32_t radio_rssi_get(void);
                                                                     int64_t k_uptime_get(void);
                          
void ble_write_thread(void)
{

                                                                      uint64_t time_stamp;
                                                                      uint64_t milliseconds_spent;

                                                                      /* capture initial time stamp */
                                                                      time_stamp = k_uptime_get();

	/* Don&amp;#39;t go any further until BLE is initialized */
	k_sem_take(&amp;amp;ble_init_ok, K_FOREVER);
                                      uint32_t rssi;
                                      char buf2[30];
                                      
                                                                  while(1){
                                                                  k_sleep(K_MSEC(10));
                                                                  rssi = radio_rssi_get();

                                                                      /* compute how long the work took (also updates the time stamp) */
                                                                  milliseconds_spent = k_uptime_delta(&amp;amp;time_stamp);
                                                                  sprintf(buf2,&amp;quot;%012d\t%llu\r\n&amp;quot;,rssi,milliseconds_spent);                                
                                                                    //sprintf(buf2,&amp;quot;%012d\r\n&amp;quot;,rssi);
           
                                                                    bt_nus_send(NULL,buf2,20);
                                                                    }
        
	
}

K_THREAD_DEFINE(ble_write_thread_id, STACKSIZE, ble_write_thread, NULL, NULL,
		NULL, PRIORITY, 0, 0);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The peripheral code looks like this, but I don&amp;#39;t think this code is able to get the rsi according to the &amp;quot;connection interval&amp;quot;.&lt;/p&gt;
&lt;p&gt;When this code is executed, the rssi is obtained, but the time repeats between &amp;quot;11&amp;quot; and &amp;quot;39&amp;quot;.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;I want to get the polling packets from central and record the rssi and timestamp, what library should I use?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I want to use NCS to acquire RSSI with a total of two nRF51s, one central and one peripheral.</title><link>https://devzone.nordicsemi.com/thread/321751?ContentTypeID=1</link><pubDate>Mon, 26 Jul 2021 09:27:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4c2ad141-82cd-4185-baa6-ff430cc2a12c</guid><dc:creator>tadanohito</dc:creator><description>&lt;p&gt;&lt;span&gt;I know it&amp;#39;s not supported and may not work properly, but I&amp;#39;m asking for the following.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I would like to know if there is a sample project or code that has the necessary connection intervals, functions for sending empty packets, or functions for this purpose.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I want to make it work under my responsibility.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The version of NCS is 1.6.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I want to use NCS to acquire RSSI with a total of two nRF51s, one central and one peripheral.</title><link>https://devzone.nordicsemi.com/thread/321710?ContentTypeID=1</link><pubDate>Mon, 26 Jul 2021 07:21:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:42a0a9bc-0fd3-40a5-867b-37f6bc0bb366</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Do you have any more questions then, or do you consider the case resolved?&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I want to use NCS to acquire RSSI with a total of two nRF51s, one central and one peripheral.</title><link>https://devzone.nordicsemi.com/thread/321632?ContentTypeID=1</link><pubDate>Sat, 24 Jul 2021 07:39:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3d0d01f5-821f-4c6e-8f61-91f53ed0162d</guid><dc:creator>tadanohito</dc:creator><description>&lt;p&gt;I understood about that.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I want to use NCS to acquire RSSI with a total of two nRF51s, one central and one peripheral.</title><link>https://devzone.nordicsemi.com/thread/321483?ContentTypeID=1</link><pubDate>Fri, 23 Jul 2021 07:14:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c52209d2-1362-4163-af18-774e58de46ce</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;If you look at the &lt;a href="https://www.nordicsemi.com/products/nrf51822"&gt;nRF51822 product page&lt;/a&gt; you will see that it points to the SoftDevices, and the nRF5 SDK.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/index.html"&gt;nRF Connect SDK&lt;/a&gt; (including Zephyr) is intended for use with the nRF52, nRF53 and nRF91 series.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Zephyr has board support for the nRF51 series as you have seen, but if you go to production with this solution you are essentially on your own if you encounter any problems. If there are some bugs or problems with any of the libraries, like the Bluetooth stack for instance, it is not something we will take responsibility for since we don&amp;#39;t support this combination.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It is the same if you use other non-Nordic libraries for a Nordic part, like Arduino libraries for instance. We don&amp;#39;t have the capacity to support and fix bugs in all third party software that runs on our chips, only the software that we&amp;nbsp;develop and test specifically for our devices.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I want to use NCS to acquire RSSI with a total of two nRF51s, one central and one peripheral.</title><link>https://devzone.nordicsemi.com/thread/321389?ContentTypeID=1</link><pubDate>Thu, 22 Jul 2021 13:54:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0cd857dd-4abc-4eb1-867b-ed3edf39a11b</guid><dc:creator>tadanohito</dc:creator><description>&lt;p&gt;Yes, but so far the peripheral_uart and central_uart sample projects are working with &amp;quot;Board name:nrf51dongle_nrf51422&amp;quot;, so I thought it would not be a problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I want to use NCS to acquire RSSI with a total of two nRF51s, one central and one peripheral.</title><link>https://devzone.nordicsemi.com/thread/321348?ContentTypeID=1</link><pubDate>Thu, 22 Jul 2021 12:20:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:874cee3b-5f7c-4f27-9b7b-4435ea8955d9</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It is important to mention that we don&amp;#39;t recommend starting new BLE designs with the nRF51 series today, since it only supports Bluetooth 4.1, which will be deprecated in early 2023:&lt;br /&gt;&lt;a href="https://www.bluetooth.com/archived-specifications/"&gt;https://www.bluetooth.com/archived-specifications/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This means that after this time you will not be allowed to qualify any new BLE designs based on this Bluetooth version.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Also, we don&amp;#39;t have official support for the nRF51 series in Zephyr/nRF Connect SDK,&amp;nbsp;which means are not able to prioritize support for this combination of hardware and software.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Have you considered migrating to the nRF52 series instead?&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>