<?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>LTE BLE Gateway example. Connect to same device twice.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/68573/lte-ble-gateway-example-connect-to-same-device-twice</link><description>I have a call to bt_scan_start after a device disconnects. 
 When the device connects again, I get this error: 
 ASSERTION FAIL [params-&amp;gt;value] @ WEST_TOPDIR/zephyr/subsys/bluetooth/host/gatt.c:4060 
 
 
 
 invalid parameters</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 24 Nov 2020 13:03:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/68573/lte-ble-gateway-example-connect-to-same-device-twice" /><item><title>RE: LTE BLE Gateway example. Connect to same device twice.</title><link>https://devzone.nordicsemi.com/thread/281560?ContentTypeID=1</link><pubDate>Tue, 24 Nov 2020 13:03:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32a05b05-d62d-45e9-a306-c6cf991c1cd0</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I&amp;#39;m not exactly sure what&amp;#39;s causing this error, but I would recommend you to look at the central_uart example and to see how it&amp;#39;s done there:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.4.0/samples/bluetooth/central_uart/src/main.c#L371-L393"&gt;https://github.com/nrfconnect/sdk-nrf/blob/v1.4.0/samples/bluetooth/central_uart/src/main.c#L371-L393&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I tested the central_uart example with the peripheral_uart sample and triggered the disconnect--&amp;gt;scan start from the central by resetting the peripheral. Everything worked fine, the scanning started again, the device connected and I was able to send commands forth and back.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LTE BLE Gateway example. Connect to same device twice.</title><link>https://devzone.nordicsemi.com/thread/281185?ContentTypeID=1</link><pubDate>Fri, 20 Nov 2020 19:01:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bed8e199-b17b-4ac9-8552-88cab5f06691</guid><dc:creator>kartikye</dc:creator><description>&lt;p&gt;params -&amp;gt; value does seem to be set in the code. Does this look right?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*
 * Copyright (c) 2018 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
 */

#include &amp;lt;zephyr.h&amp;gt;

#include &amp;lt;bluetooth/bluetooth.h&amp;gt;
#include &amp;lt;bluetooth/gatt.h&amp;gt;
#include &amp;lt;bluetooth/uuid.h&amp;gt;
#include &amp;lt;bluetooth/gatt_dm.h&amp;gt;
#include &amp;lt;bluetooth/scan.h&amp;gt;

#include &amp;lt;dk_buttons_and_leds.h&amp;gt;
#include &amp;lt;sys/byteorder.h&amp;gt;

#include &amp;lt;net/nrf_cloud.h&amp;gt;
#include &amp;quot;aggregator.h&amp;quot;

/* Thinghy advertisement UUID */
#define BT_UUID_THINGY                                                         \
	BT_UUID_DECLARE_128(0x00, 0x00, 0xFF, 0xF0, 0x00, 0x00, 0x10, 0x00,    \
			    0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB)

/* Thingy service UUID */
#define BT_UUID_TMS                                                            \
        BT_UUID_DECLARE_128(0xFB, 0x34, 0x9B, 0X5F, 0x80, 0x00, 0x00, 0x80,    \
			    0x00, 0x10, 0x00, 0x00, 0xF0, 0xFF, 0x00, 0x00)

//	BT_UUID_DECLARE_128(0x00, 0x00, 0xFF, 0xF0, 0x00, 0x00, 0x10, 0x00,    \
//			    0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB)

/* Thingy characteristic UUID */
#define BT_UUID_TOC                                                            \
	BT_UUID_DECLARE_128(0xFB, 0x34, 0x9B, 0X5F, 0x80, 0x00, 0x00, 0x80,    \
			    0x00, 0x10, 0x00, 0x00, 0xF1, 0xFF, 0x00, 0x00)
        
//      BT_UUID_DECLARE_128(0x00, 0x00, 0xFF, 0xF1, 0x00, 0x00, 0x10, 0x00,    \
//			    0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB)

#define DEVICE_NAME &amp;quot;Bluetooth BP&amp;quot;
#define DEVICE_NAME_LEN	(sizeof(DEVICE_NAME) - 1)


extern void alarm(void);
static void scan_start(void);

static uint8_t on_received(struct bt_conn *conn,
			struct bt_gatt_subscribe_params *params,
			const void *data, uint16_t length)
{
	if (length == 7) {
		printk(&amp;quot;Orientation: %x %x %x %x %x %x %x\n&amp;quot;, ((uint8_t *)data)[0], ((uint8_t *)data)[1], ((uint8_t *)data)[2], ((uint8_t *)data)[3], ((uint8_t *)data)[4], ((uint8_t *)data)[5], ((uint8_t *)data)[6]);
		struct sensor_data in_data;

		/*in_data.type = THINGY_ORIENTATION;
		in_data.length = 1;
		in_data.data[0] = ((uint8_t *)data)[0];

		if (aggregator_put(in_data) != 0) {
			printk(&amp;quot;Was not able to insert Thingy orientation data into aggregator.\n&amp;quot;);
		}
		// If the thingy is upside down, trigger an alarm.
		if (((uint8_t *)data)[0] == 3) {
			alarm();
		}
                */

	} else if (length == 8) {
		printk(&amp;quot;Diastolic: %x\n&amp;quot;,  ((uint8_t *)data)[4]);
                printk(&amp;quot;Systolic: %x\n&amp;quot;,  ((uint8_t *)data)[5]);
                printk(&amp;quot;Heart Rate: %x\n&amp;quot;,  ((uint8_t *)data)[6]);
        }
	return BT_GATT_ITER_CONTINUE;
}

static void discovery_completed(struct bt_gatt_dm *disc, void *ctx)
{
	int err;

	/* Must be statically allocated */
	static struct bt_gatt_subscribe_params param = {
		.notify = on_received,
		.value = BT_GATT_CCC_NOTIFY,
	};

	const struct bt_gatt_dm_attr *chrc;
	const struct bt_gatt_dm_attr *desc;

	chrc = bt_gatt_dm_char_by_uuid(disc, BT_UUID_TOC);
	if (!chrc) {
		printk(&amp;quot;Missing Thingy orientation characteristic\n&amp;quot;);
		goto release;
	}

	desc = bt_gatt_dm_desc_by_uuid(disc, chrc, BT_UUID_TOC);
	if (!desc) {
		printk(&amp;quot;Missing Thingy orientation char value descriptor\n&amp;quot;);
		goto release;
	}

	param.value_handle = desc-&amp;gt;handle,

	desc = bt_gatt_dm_desc_by_uuid(disc, chrc, BT_UUID_GATT_CCC);
	if (!desc) {
		printk(&amp;quot;Missing Thingy orientation char CCC descriptor\n&amp;quot;);
		goto release;
	}

	param.ccc_handle = desc-&amp;gt;handle;

	err = bt_gatt_subscribe(bt_gatt_dm_conn_get(disc), &amp;amp;param);
	if (err) {
		printk(&amp;quot;Subscribe failed (err %d)\n&amp;quot;, err);
	}

release:
	err = bt_gatt_dm_data_release(disc);
	if (err) {
		printk(&amp;quot;Could not release discovery data, err: %d\n&amp;quot;, err);
	}
}

static void discovery_service_not_found(struct bt_conn *conn, void *ctx)
{
	printk(&amp;quot;Thingy orientation service not found!\n&amp;quot;);
}

static void discovery_error_found(struct bt_conn *conn, int err, void *ctx)
{
	printk(&amp;quot;The discovery procedure failed, err %d\n&amp;quot;, err);
}

static struct bt_gatt_dm_cb discovery_cb = {
	.completed = discovery_completed,
	.service_not_found = discovery_service_not_found,
	.error_found = discovery_error_found,
};

static void connected(struct bt_conn *conn, uint8_t conn_err)
{
	int err;
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	if (conn_err) {
		printk(&amp;quot;Failed to connect to %s (%u)\n&amp;quot;, addr, conn_err);
		return;
	}

	printk(&amp;quot;Connected: %s\n&amp;quot;, addr);

	err = bt_gatt_dm_start(conn, BT_UUID_TMS, &amp;amp;discovery_cb, NULL);
	if (err) {
		printk(&amp;quot;Could not start service discovery, err %d\n&amp;quot;, err);
	}
}

static void disconnected(struct bt_conn *conn, uint8_t conn_err)
{
	printk(&amp;quot;Disconnected\n&amp;quot;);
        bt_scan_start(BT_SCAN_TYPE_SCAN_ACTIVE);
}

static struct bt_conn_cb conn_callbacks = {
	.connected = connected,
        .disconnected = disconnected
};

void scan_filter_match(struct bt_scan_device_info *device_info,
		       struct bt_scan_filter_match *filter_match,
		       bool connectable)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(device_info-&amp;gt;recv_info-&amp;gt;addr, addr, sizeof(addr));

	printk(&amp;quot;Device found: %s\n&amp;quot;, addr);
}

void scan_connecting_error(struct bt_scan_device_info *device_info)
{
	printk(&amp;quot;Connection to peer failed!\n&amp;quot;);
}

BT_SCAN_CB_INIT(scan_cb, scan_filter_match, NULL, scan_connecting_error, NULL);

static void scan_start(void)
{
	int err;

	struct bt_le_scan_param scan_param = {
		.type = BT_LE_SCAN_TYPE_ACTIVE,
		.options = BT_LE_SCAN_OPT_NONE, //BT_LE_SCAN_OPT_FILTER_DUPLICATE,
		.interval = 0x0010,
		.window = 0x0010,
	};

	struct bt_scan_init_param scan_init = {
		.connect_if_match = 1,
		.scan_param = &amp;amp;scan_param,
		.conn_param = BT_LE_CONN_PARAM_DEFAULT,
	};

	bt_scan_init(&amp;amp;scan_init);
	bt_scan_cb_register(&amp;amp;scan_cb);

        err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_NAME, &amp;amp;DEVICE_NAME);

        if (err) {
		printk(&amp;quot;Name filter cannot be added (err %d)&amp;quot;, err);
                printk(&amp;quot;%d\n&amp;quot;, CONFIG_BT_SCAN_NAME_CNT);
	}

	err = bt_scan_filter_enable(BT_SCAN_NAME_FILTER, false);

	if (err) {
		printk(&amp;quot;Filters cannot be turned on (err %d)&amp;quot;, err);
	}

	err = bt_scan_start(BT_SCAN_TYPE_SCAN_ACTIVE);
	if (err) {
		printk(&amp;quot;Scanning failed to start, err %d\n&amp;quot;, err);
	}

	printk(&amp;quot;Scanning...\n&amp;quot;);
}

static void ble_ready(int err)
{
	printk(&amp;quot;Bluetooth ready\n&amp;quot;);

	bt_conn_cb_register(&amp;amp;conn_callbacks);
	scan_start();
}

void ble_init(void)
{
	int err;

	printk(&amp;quot;Initializing Bluetooth..\n&amp;quot;);
	err = bt_enable(ble_ready);
	if (err) {
		printk(&amp;quot;Bluetooth init failed (err %d)\n&amp;quot;, err);
		return;
	}
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LTE BLE Gateway example. Connect to same device twice.</title><link>https://devzone.nordicsemi.com/thread/281172?ContentTypeID=1</link><pubDate>Fri, 20 Nov 2020 17:36:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dd665de6-5c88-48ee-a48f-921ec5f5c849</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;You should set the field params-&amp;gt;value to either&amp;nbsp;BT_GATT_CCC_NOTIFY or&amp;nbsp;BT_GATT_CCC_INDICATE. Right now you are providing a field value that is equal to 0.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>