<?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>Bluetooth connexion issue</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/91984/bluetooth-connexion-issue</link><description>Hello community, I&amp;#39;m trying to implement BT service on my project to be able to connect with my phone for information my project displays data from sensors(BME280, INA219, MPU6050) connected to my D-kit i&amp;#39;m using nrf connect V1.8.0 and NRF5340dk i got</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 12 Aug 2023 19:30:01 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/91984/bluetooth-connexion-issue" /><item><title>RE: Bluetooth connexion issue</title><link>https://devzone.nordicsemi.com/thread/441044?ContentTypeID=1</link><pubDate>Sat, 12 Aug 2023 19:30:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9b029114-fdea-4915-8095-56eb15b79160</guid><dc:creator>pauleffect</dc:creator><description>&lt;p&gt;as usual, as soon as I post on a support forum, i find the solution in the next 3 minutes.&lt;br /&gt;&lt;br /&gt;the code produced a log that stated &amp;quot;[00:00:01.450,439] &amp;lt;inf&amp;gt; bt_hci_core: bt_init: No ID address. App must call settings_load()&amp;quot;&lt;br /&gt;&lt;br /&gt;which is weird, because in my conf file i have.&lt;/p&gt;
&lt;div&gt;&lt;span&gt;CONFIG_SETTINGS&lt;/span&gt;&lt;span&gt;=n&lt;br /&gt;&lt;br /&gt;Furthermore, nrf samples all have something like&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;	if (IS_ENABLED(CONFIG_SETTINGS)) {
		settings_load();
	}&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;span&gt;So I didn&amp;#39;t put that in the code.&lt;br /&gt;&lt;br /&gt;Apparently calling&amp;nbsp;&lt;strong&gt;settings_load&lt;/strong&gt; is what the code was missing. probably the sample was written for an old version of zephyr.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The complete main is:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;


int main(void)
{
	int err;

	printk(&amp;quot;Starting Bluetooth Peripheral LBS example\n&amp;quot;);




	k_msleep(1000);
	err = bt_enable(NULL);
	if (err) {
		printk(&amp;quot;INIT: Bluetooth init failed (err %d)\n&amp;quot;, err);
		return 0;
	}
	else
	{
		printk(&amp;quot;INIT: Bluetooth initialized %d\n&amp;quot;, err);
	}

	//Configure connection callbacks
	bt_conn_cb_register(&amp;amp;conn_callbacks);

	//Initalize services
	err = my_service_init();

	if (err) 
	{
		printk(&amp;quot;Failed to init LBS (err:%d)\n&amp;quot;, err);
		return;
	}


	settings_load();

	//Start advertising
	err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad),
			      sd, ARRAY_SIZE(sd));
	if (err) 
	{
		printk(&amp;quot;Advertising failed to start (err %d)\n&amp;quot;, err);
		while(1);
	}

	

	if (!err) 
	{
		printk(&amp;quot;Bluetooth initialized\n&amp;quot;);
	} else 
	{
		printk(&amp;quot;BLE initialization did not complete in time\n&amp;quot;);
	}

	printk(&amp;quot;Bluetooth initialized\n&amp;quot;);

	my_service_init();

	uint32_t counter = 0;
	for (;;) {
		printk(&amp;quot;NET LOOP %u\n&amp;quot;, ++counter);
		k_sleep(K_MSEC(1000));
	}
}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Apologies for the sloppy as hell code, I just copy pasted everything in the main.c.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth connexion issue</title><link>https://devzone.nordicsemi.com/thread/441043?ContentTypeID=1</link><pubDate>Sat, 12 Aug 2023 19:18:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1f5d174e-c0e6-430c-b093-3d61587a262a</guid><dc:creator>pauleffect</dc:creator><description>&lt;p&gt;followed the same article. built the code. no warning. same output (err -11).&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*
 * Copyright (c) 2018 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */

#include &amp;lt;zephyr/types.h&amp;gt;
#include &amp;lt;stddef.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;errno.h&amp;gt;
#include &amp;lt;zephyr/sys/printk.h&amp;gt;
#include &amp;lt;zephyr/sys/byteorder.h&amp;gt;
#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;
#include &amp;lt;soc.h&amp;gt;

#include &amp;lt;zephyr/bluetooth/bluetooth.h&amp;gt;
#include &amp;lt;zephyr/bluetooth/hci.h&amp;gt;
#include &amp;lt;zephyr/bluetooth/conn.h&amp;gt;
#include &amp;lt;zephyr/bluetooth/uuid.h&amp;gt;
#include &amp;lt;zephyr/bluetooth/gatt.h&amp;gt;
#include &amp;lt;zephyr/settings/settings.h&amp;gt;


#define DEVICE_NAME             CONFIG_BT_DEVICE_NAME
#define DEVICE_NAME_LEN         (sizeof(DEVICE_NAME) - 1)

#define MAX_TRANSMIT_SIZE 240
uint8_t data_rx[MAX_TRANSMIT_SIZE];
uint8_t data_tx[MAX_TRANSMIT_SIZE];

#define MY_SERVICE_UUID 				0xd4, 0x86, 0x48, 0x24, 0x54, 0xB3, 0x43, 0xA1, 0xBC, 0x20, 0x97, 0x8F, 0xC3, 0x76, 0xC2, 0x75
#define RX_CHARACTERISTIC_UUID 			0xA6, 0xE8, 0xC4, 0x60, 0x7E, 0xAA, 0x41, 0x6B, 0x95, 0xD4, 0x9D, 0xCC, 0x08, 0x4F, 0xCF, 0x6A
#define TX_CHARACTERISTIC_UUID 			0xED, 0xAA, 0x20, 0x11, 0x92, 0xE7, 0x43, 0x5A, 0xAA, 0xE9, 0x94, 0x43, 0x35, 0x6A, 0xD4, 0xD3

#define BT_UUID_MY_SERIVCE      BT_UUID_DECLARE_128(MY_SERVICE_UUID)
#define BT_UUID_MY_SERIVCE_RX   BT_UUID_DECLARE_128(RX_CHARACTERISTIC_UUID)
#define BT_UUID_MY_SERIVCE_TX   BT_UUID_DECLARE_128(TX_CHARACTERISTIC_UUID)

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, MY_SERVICE_UUID),
};



struct bt_conn *my_connection;

static void connected(struct bt_conn *conn, uint8_t err)
{
	struct bt_conn_info info; 
	char addr[BT_ADDR_LE_STR_LEN];

	my_connection = conn;

	if (err) 
	{
		printk(&amp;quot;Connection failed (err %u)\n&amp;quot;, err);
		return;
	}
	else if(bt_conn_get_info(conn, &amp;amp;info))
	{
		printk(&amp;quot;Could not parse connection info\n&amp;quot;);
	}
	else
	{
		bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
		
		printk(&amp;quot;Connection established!		\n\
		Connected to: %s					\n\
		Role: %u							\n\
		Connection interval: %u				\n\
		Slave latency: %u					\n\
		Connection supervisory timeout: %u	\n&amp;quot;
		, addr, info.role, info.le.interval, info.le.latency, info.le.timeout);
	}
}

static void disconnected(struct bt_conn *conn, uint8_t reason)
{
	printk(&amp;quot;Disconnected (reason %u)\n&amp;quot;, reason);

	my_connection = NULL;
}

static bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param)
{
	//If acceptable params, return true, otherwise return false.
	return true; 
}

static void le_param_updated(struct bt_conn *conn, uint16_t interval, uint16_t latency, uint16_t timeout)
{
	struct bt_conn_info info; 
	char addr[BT_ADDR_LE_STR_LEN];
	
	if(bt_conn_get_info(conn, &amp;amp;info))
	{
		printk(&amp;quot;Could not parse connection info\n&amp;quot;);
	}
	else
	{
		bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
		
		printk(&amp;quot;Connection parameters updated!	\n\
		Connected to: %s						\n\
		New Connection Interval: %u				\n\
		New Slave Latency: %u					\n\
		New Connection Supervisory Timeout: %u	\n&amp;quot;
		, addr, info.le.interval, info.le.latency, info.le.timeout);
	}
}


static struct bt_conn_cb conn_callbacks = {
	.connected		    = connected,
	.disconnected   	= disconnected,
	.le_param_req		= le_param_req,
	.le_param_updated	= le_param_updated
};






int my_service_init(void)
{
    int err = 0;
   
    memset(&amp;amp;data_rx, 0, MAX_TRANSMIT_SIZE);
    memset(&amp;amp;data_tx, 0, MAX_TRANSMIT_SIZE);
    
    return err;
}

static ssize_t on_receive(struct bt_conn *conn,
			  const struct bt_gatt_attr *attr,
			  const void *buf,
			  uint16_t len,
			  uint16_t offset,
			  uint8_t flags)
{
    const uint8_t * buffer = buf;
    
	printk(&amp;quot;Received data, handle %d, conn %p, data: 0x&amp;quot;, attr-&amp;gt;handle, conn);
    for(uint8_t i = 0; i &amp;lt; len; i++){
        printk(&amp;quot;%02X&amp;quot;, buffer[i]);
    }
    printk(&amp;quot;\n&amp;quot;);

	return len;
}

static void on_sent(struct bt_conn *conn, void *user_data)
{
	ARG_UNUSED(user_data);

    const bt_addr_le_t * addr = bt_conn_get_dst(conn);
        
	printk(&amp;quot;Data sent to Address 0x %02X %02X %02X %02X %02X %02X \n&amp;quot;, addr-&amp;gt;a.val[0]
                                                                    , addr-&amp;gt;a.val[1]
                                                                    , addr-&amp;gt;a.val[2]
                                                                    , addr-&amp;gt;a.val[3]
                                                                    , addr-&amp;gt;a.val[4]
                                                                    , addr-&amp;gt;a.val[5]);
}

/* This function is called whenever the CCCD register has been changed by the client*/
void on_cccd_changed(const struct bt_gatt_attr *attr, uint16_t value)
{
    ARG_UNUSED(attr);
    switch(value)
    {
        case BT_GATT_CCC_NOTIFY: 
            // Start sending stuff!
            break;

        case BT_GATT_CCC_INDICATE: 
            // Start sending stuff via indications
            break;

        case 0: 
            // Stop sending stuff
            break;
        
        default: 
            printk(&amp;quot;Error, CCCD has been set to an invalid value&amp;quot;);     
    }
}
                        

/* LED Button Service Declaration and Registration */
BT_GATT_SERVICE_DEFINE(my_service,
BT_GATT_PRIMARY_SERVICE(BT_UUID_MY_SERIVCE),    
BT_GATT_CHARACTERISTIC(BT_UUID_MY_SERIVCE_RX,
			       BT_GATT_CHRC_WRITE | BT_GATT_CHRC_WRITE_WITHOUT_RESP,
			       BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, 
                   NULL, on_receive, NULL),
BT_GATT_CHARACTERISTIC(BT_UUID_MY_SERIVCE_TX,
			       BT_GATT_CHRC_NOTIFY,
			       BT_GATT_PERM_READ,
                   NULL, NULL, NULL),
BT_GATT_CCC(on_cccd_changed,
        BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
);

/* This function sends a notification to a Client with the provided data,
given that the Client Characteristic Control Descripter has been set to Notify (0x1).
It also calls the on_sent() callback if successful*/
void my_service_send(struct bt_conn *conn, const uint8_t *data, uint16_t len)
{
    /* 
    The attribute for the TX characteristic is used with bt_gatt_is_subscribed 
    to check whether notification has been enabled by the peer or not.
    Attribute table: 0 = Service, 1 = Primary service, 2 = RX, 3 = TX, 4 = CCC.
    */
    const struct bt_gatt_attr *attr = &amp;amp;my_service.attrs[3]; 

    struct bt_gatt_notify_params params = 
    {
        .uuid   = BT_UUID_MY_SERIVCE_TX,
        .attr   = attr,
        .data   = data,
        .len    = len,
        .func   = on_sent
    };

    // Check whether notifications are enabled or not
    if(bt_gatt_is_subscribed(conn, attr, BT_GATT_CCC_NOTIFY)) 
    {
        // Send the notification
	    if(bt_gatt_notify_cb(conn, &amp;amp;params))
        {
            printk(&amp;quot;Error, unable to send notification\n&amp;quot;);
        }
    }
    else
    {
        printk(&amp;quot;Warning, notification not enabled on the selected attribute\n&amp;quot;);
    }
}









int main(void)
{
	int err;

	printk(&amp;quot;Starting Bluetooth Peripheral LBS example\n&amp;quot;);




	k_msleep(1000);
	err = bt_enable(NULL);
	if (err) {
		printk(&amp;quot;INIT: Bluetooth init failed (err %d)\n&amp;quot;, err);
		return 0;
	}
	else
	{
		printk(&amp;quot;INIT: Bluetooth initialized %d\n&amp;quot;, err);
	}

	//Configure connection callbacks
	bt_conn_cb_register(&amp;amp;conn_callbacks);

	//Initalize services
	err = my_service_init();

	if (err) 
	{
		printk(&amp;quot;Failed to init LBS (err:%d)\n&amp;quot;, err);
		return;
	}

	//Start advertising
	err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad),
			      sd, ARRAY_SIZE(sd));
	if (err) 
	{
		printk(&amp;quot;Advertising failed to start (err %d)\n&amp;quot;, err);
		return;
	}

	printk(&amp;quot;Advertising successfully started\n&amp;quot;);





	if (!err) 
	{
		printk(&amp;quot;Bluetooth initialized\n&amp;quot;);
	} else 
	{
		printk(&amp;quot;BLE initialization did not complete in time\n&amp;quot;);
	}

	printk(&amp;quot;Bluetooth initialized\n&amp;quot;);

	my_service_init();





	uint32_t counter = 0;
	for (;;) {
		printk(&amp;quot;NET LOOP %u\n&amp;quot;, ++counter);
		k_sleep(K_MSEC(1000));
	}
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth connexion issue</title><link>https://devzone.nordicsemi.com/thread/386598?ContentTypeID=1</link><pubDate>Fri, 16 Sep 2022 11:00:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:864b6e1b-70b4-4763-ba5e-ed5cdb8c98c1</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;I do not see&amp;nbsp;anything obviously very wrong in the Bluetooth related code now (though there are a few other things worth noting for a&amp;nbsp;different time). Does it build without warnings now? What happens runtime and what do you see when debugging?&lt;/p&gt;
&lt;p&gt;Note the code I posted before, which was basically your code just with the non-BLE part stripped out, and a few issues fixed. And that works fine. I recommend you to test it and compare with your won code. Or perhaps start with that, observe that it is working, and put back things from your original code gradually while checking that nothing breaks. That way I expect you will get this working quickly.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth connexion issue</title><link>https://devzone.nordicsemi.com/thread/386593?ContentTypeID=1</link><pubDate>Fri, 16 Sep 2022 10:50:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:201082bb-7414-4a5a-9167-dd8cf04bd689</guid><dc:creator>Rihab</dc:creator><description>&lt;p&gt;here&amp;#39;s my updated code&amp;nbsp;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;device.h&amp;gt;
#include &amp;lt;drivers/sensor.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;sys/util.h&amp;gt;
#include &amp;lt;sys/printk.h&amp;gt;
#include &amp;lt;inttypes.h&amp;gt;
#include &amp;lt;drivers/gpio.h&amp;gt;

#include &amp;lt;zephyr/types.h&amp;gt;
#include &amp;lt;stddef.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;errno.h&amp;gt;
#include &amp;lt;sys/byteorder.h&amp;gt;
#include &amp;lt;soc.h&amp;gt;
#include &amp;lt;bluetooth/bluetooth.h&amp;gt;
#include &amp;lt;bluetooth/hci.h&amp;gt;
#include &amp;lt;bluetooth/conn.h&amp;gt;
#include &amp;lt;bluetooth/uuid.h&amp;gt;
#include &amp;lt;bluetooth/gatt.h&amp;gt;

#include &amp;quot;C:/sdk/v1.9.0/zephyr/samples/sensor/inaa219/services/my_service.h&amp;quot;

#define DEVICE_NAME 		CONFIG_BT_DEVICE_NAME
#define DEVICE_NAME_LEN 		(sizeof(DEVICE_NAME) - 1)

#define SLEEP_TIME_MS	1

/*
 * Get button configuration from the devicetree sw0 alias. This is mandatory.
 Replace DT_ALIAS(sw0) by sw27 to get output through SCT click
 */
#define MY_SERVICE_UUID 0x0001
#define SW0_NODE	DT_ALIAS(sw0)
#if !DT_NODE_HAS_STATUS(SW0_NODE, okay)
#error &amp;quot;Unsupported board: sw0 devicetree alias is not defined&amp;quot;
#endif
static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios,
							      {0});
static struct gpio_callback button_cb_data;
static struct gpio_dt_spec led = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led0), gpios,
						     {0});
static int on_click = 1;

#define APP_WORK_QUEUE_SIZE 4096	
#define APP_WORK_QUEUE_PRI -1

K_THREAD_STACK_DEFINE(application_stack_area, APP_WORK_QUEUE_SIZE);	
			 
static struct k_work_q application_work_q;
static struct k_work bt_ready_data_data_data_data_work;
static struct k_work get_ina219_data_data_data_work;
//static struct k_work get_bme280_data_data_work;
static struct k_work get_mpu6050_data_work;	

static K_SEM_DEFINE(ble_init_ok, 0, 1);

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, MY_SERVICE_UUID),
};
struct bt_conn *my_connection;

static void connected(struct bt_conn *conn, uint8_t err)
{
	struct bt_conn_info info; 
	char addr[BT_ADDR_LE_STR_LEN];

	my_connection = conn;

	if (err) 
	{
		printk(&amp;quot;Connection failed (err %u)\n&amp;quot;, err);
		return;
	}
	else if(bt_conn_get_info(conn, &amp;amp;info))
	{
		printk(&amp;quot;Could not parse connection info\n&amp;quot;);
	}
	else
	{
		bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
		
		printk(&amp;quot;Connection established!		\n\
		Connected to: %s			\n\
		Role: %u				\n\
		Connection interval: %u			\n\
		Slave latency: %u                       \n\
		Connection supervisory timeout: %u	\n&amp;quot;
		, addr, info.role, info.le.interval, info.le.latency, info.le.timeout);
	}
}

static void disconnected(struct bt_conn *conn, uint8_t reason)
{
	printk(&amp;quot;Disconnected (reason %u)\n&amp;quot;, reason);
}

static bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param)
{
	//If acceptable params, return true, otherwise return false.
	return true; 
}

static void le_param_updated(struct bt_conn *conn, uint16_t interval, uint16_t latency, uint16_t timeout)
{
	struct bt_conn_info info; 
	char addr[BT_ADDR_LE_STR_LEN];
	
	if(bt_conn_get_info(conn, &amp;amp;info))
	{
		printk(&amp;quot;Could not parse connection info\n&amp;quot;);
	}
	else
	{
		bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
		
		printk(&amp;quot;Connection parameters updated!	\n\
		Connected to: %s			\n\
		New Connection Interval: %u		\n\
		New Slave Latency: %u			\n\
		New Connection Supervisory Timeout: %u	\n&amp;quot;
		, addr, info.le.interval, info.le.latency, info.le.timeout);
	}
}

static struct bt_conn_cb conn_callbacks = 
{
	.connected			= connected,
	.disconnected   		= disconnected,
	.le_param_req			= le_param_req,
	.le_param_updated		= le_param_updated
};

static const char *now_str(void)
{
	static char buf[16]; /* ...HH:MM:SS.MMM */
	uint32_t now = k_uptime_get_32();
	unsigned int ms = now % MSEC_PER_SEC;
	unsigned int s;
	unsigned int min;
	unsigned int h;

	now /= MSEC_PER_SEC;
	s = now % 60U;
	now /= 60U;
	min = now % 60U;
	now /= 60U;
	h = now;

	snprintf(buf, sizeof(buf), &amp;quot;%u:%02u:%02u.%03u&amp;quot;,
		 h, min, s, ms);
	return buf;
}

static int process_mpu6050(const struct device *dev)
{
	struct sensor_value temperature;
	struct sensor_value accel[3];
	struct sensor_value gyro[3];
	int rc = sensor_sample_fetch(dev);

	if (rc == 0) {
		rc = sensor_channel_get(dev, SENSOR_CHAN_ACCEL_XYZ,
					accel);
	}
	if (rc == 0) {
		rc = sensor_channel_get(dev, SENSOR_CHAN_GYRO_XYZ,
					gyro);
	}
	if (rc == 0) {
		rc = sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP,
					&amp;amp;temperature);
	}
	if (rc == 0) {
		printf(&amp;quot;[%s]:%g Cel\n&amp;quot;
		       &amp;quot;  accel %f %f %f m/s/s\n&amp;quot;
		       &amp;quot;  gyro  %f %f %f rad/s\n&amp;quot;,
		       now_str(),
		       sensor_value_to_double(&amp;amp;temperature),
		       sensor_value_to_double(&amp;amp;accel[0]),
		       sensor_value_to_double(&amp;amp;accel[1]),
		       sensor_value_to_double(&amp;amp;accel[2]),
		       sensor_value_to_double(&amp;amp;gyro[0]),
		       sensor_value_to_double(&amp;amp;gyro[1]),
		       sensor_value_to_double(&amp;amp;gyro[2]));
	} else {
		printf(&amp;quot;sample fetch/get failed: %d\n&amp;quot;, rc);
	}

	return rc;
}

#ifdef CONFIG_MPU6050_TRIGGER
static struct sensor_trigger trigger;

static void handle_mpu6050_drdy(const struct device *dev,
				struct sensor_trigger *trig)
{
	int rc = process_mpu6050(dev);

	if (rc != 0) {
		printf(&amp;quot;cancelling trigger due to failure: %d\n&amp;quot;, rc);
		(void)sensor_trigger_set(dev, trig, NULL);
		return;
	}
}
#endif /* CONFIG_MPU6050_TRIGGER */

static const struct device *get_ina219_device(void)
{
  const struct device *dev = DEVICE_DT_GET_ANY(ti_ina219);
        if(dev == NULL){
                  printk(&amp;quot;\nEror: no device found. \n&amp;quot;);
                  return NULL;
         }
         if (!device_is_ready(dev)) {
		printk(&amp;quot;\nError: Device \&amp;quot;%s\&amp;quot; is not ready; &amp;quot;
		       &amp;quot;check the driver initialization logs for errors.\n&amp;quot;,
		       dev-&amp;gt;name);
		return NULL;
	}

	//printk(&amp;quot;Found device \&amp;quot;%s\&amp;quot;, getting sensor data\n&amp;quot;, dev-&amp;gt;name);
	return dev;
}

/*static const struct device *get_bme280_device(void)
{
	const struct device *dev = DEVICE_DT_GET_ANY(bosch_bme280);

	if (dev == NULL) {
		// No such node, or the node does not have status &amp;quot;okay&amp;quot;. 
		printk(&amp;quot;\nError: no device found.\n&amp;quot;);
		return NULL;
	}

	if (!device_is_ready(dev)) {
		printk(&amp;quot;\nError: Device \&amp;quot;%s\&amp;quot; is not ready; &amp;quot;
		       &amp;quot;check the driver initialization logs for errors.\n&amp;quot;,
		       dev-&amp;gt;name);
		return NULL;
	}

	//printk(&amp;quot;Found device \&amp;quot;%s\&amp;quot;, getting sensor data\n&amp;quot;, dev-&amp;gt;name);
	return dev;
}*/

static void get_mpu6050_data_work_fn(struct k_work *work)
{
        
	printk(&amp;quot;-----------------Get MPU6050 data\n&amp;quot; );

        struct sensor_value temperature;
        struct sensor_value accel[3];
        struct sensor_value gyro[3];

        printf(&amp;quot;[%s]:%g Cel\n&amp;quot;
	&amp;quot;  accel %f %f %f m/s/s\n&amp;quot;
	&amp;quot;  gyro  %f %f %f rad/s\n&amp;quot;,
	now_str(),
	sensor_value_to_double(&amp;amp;temperature),
	sensor_value_to_double(&amp;amp;accel[0]),
	sensor_value_to_double(&amp;amp;accel[1]),
	sensor_value_to_double(&amp;amp;accel[2]),
	sensor_value_to_double(&amp;amp;gyro[0]),
	sensor_value_to_double(&amp;amp;gyro[1]),
	sensor_value_to_double(&amp;amp;gyro[2]));
	
}

/*static void get_bme280_data_data_work_work_fn(struct k_work *work)
{
                printk(&amp;quot;+++++++++++++++++Get BME280 data\n&amp;quot;);
                
		struct sensor_value temp, press, humidity;
		sensor_sample_fetch(get_bme280_device());
		sensor_channel_get(get_bme280_device(), SENSOR_CHAN_AMBIENT_TEMP, &amp;amp;temp);
		sensor_channel_get(get_bme280_device(), SENSOR_CHAN_PRESS, &amp;amp;press);
		sensor_channel_get(get_bme280_device(), SENSOR_CHAN_HUMIDITY, &amp;amp;humidity);

		printk(&amp;quot;temp: %d.%06d; press: %d.%06d; humidity: %d.%06d\n&amp;quot;,
		      temp.val1, temp.val2, press.val1, press.val2,
		      humidity.val1, humidity.val2);
	
}*/

static void get_ina219_data_data_data_work_work_work_fn(struct k_work *work)
{
      printk(&amp;quot;################Get INA219 data\n&amp;quot;);

      struct sensor_value v_bus, power, current;
      sensor_sample_fetch(get_ina219_device());
                sensor_channel_get(get_ina219_device(), SENSOR_CHAN_VOLTAGE, &amp;amp;v_bus);
		sensor_channel_get(get_ina219_device(), SENSOR_CHAN_POWER, &amp;amp;power);
		sensor_channel_get(get_ina219_device(), SENSOR_CHAN_CURRENT, &amp;amp;current);
      
		printf(&amp;quot;Bus: %f [V] -- &amp;quot;
			&amp;quot;Power: %f [W] -- &amp;quot;
			&amp;quot;Current: %f [A]\n&amp;quot;,
		       sensor_value_to_double(&amp;amp;v_bus),
		       sensor_value_to_double(&amp;amp;power),
		       sensor_value_to_double(&amp;amp;current));
}

static void error(void)
{
	while (true) {
		printk(&amp;quot;Error!\n&amp;quot;);
		/* Spin for ever */
		k_sleep(K_MSEC(1000)); //1000ms
	}
}

void button_pressed(const struct device *dev, struct gpio_callback *cb,
		    uint32_t pins)
{
        printk(&amp;quot;***************Button pressed at &amp;quot;);
        int val = gpio_pin_get_dt(&amp;amp;button);
        if(val == 1){
        gpio_pin_set_dt(&amp;amp;button, val);
        printk(&amp;quot;Number of cycle : %d\n&amp;quot;, on_click++);
        }
        else if (val == 0){
        printk(&amp;quot;Number of cycle : %d\n&amp;quot;, on_click);
        }
	k_work_submit_to_queue(&amp;amp;application_work_q, &amp;amp;get_mpu6050_data_work);
        //k_work_submit_to_queue(&amp;amp;application_work_q, &amp;amp;get_bme280_data_data_work);
        k_work_submit_to_queue(&amp;amp;application_work_q, &amp;amp;get_ina219_data_data_data_work);
        k_work_submit_to_queue(&amp;amp;application_work_q, &amp;amp;bt_ready_data_data_data_data_work);
        
}
static void bt_ready_data_data_data_data_work_work_work_work_fn(int err)
{
	if (err) 
	{
		printk(&amp;quot;BLE init failed with error code %d\n&amp;quot;, err);
		return;
	}
	//Configure connection callbacks
        printk(&amp;quot;callbacks&amp;quot;);
	bt_conn_cb_register(&amp;amp;conn_callbacks);
	//Initalize services
        printk(&amp;quot;initialisation&amp;quot;);
	err = my_service_init();
        printk(&amp;quot;LBS \n&amp;quot;);
       
	//Start advertising
	err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad),
			      sd, ARRAY_SIZE(sd));
        printk(&amp;quot;BT Starting \n&amp;quot;);  
	if (err) 
	{
		printk(&amp;quot;Advertising failed to start (err %d)\n&amp;quot;, err);
		return;
	}
        else{
	printk(&amp;quot;Advertising successfully started\n&amp;quot;);
        }
	k_sem_give(&amp;amp;ble_init_ok);
}

static void work_init(void)
{
	k_work_init(&amp;amp;get_mpu6050_data_work, get_mpu6050_data_work_fn);
	//k_work_init(&amp;amp;get_bme280_data_data_work, get_bme280_data_data_work_work_fn);
        k_work_init(&amp;amp;get_ina219_data_data_data_work, get_ina219_data_data_data_work_work_work_fn);
        k_work_init(&amp;amp;bt_ready_data_data_data_data_work, bt_ready_data_data_data_data_work_work_work_work_fn);
}

void main(void)
{
	int ret;       
        int err = 0;
	uint32_t number = 0;

	k_work_queue_start(&amp;amp;application_work_q, application_stack_area,
			K_THREAD_STACK_SIZEOF(application_stack_area),
			APP_WORK_QUEUE_PRI, NULL);
	work_init();

	if (!device_is_ready(button.port)) {
		printk(&amp;quot;Error: button device %s is not ready\n&amp;quot;,
		       button.port-&amp;gt;name);
		return;
	}

	ret = gpio_pin_configure_dt(&amp;amp;button, GPIO_INPUT);
	if (ret != 0) {
		printk(&amp;quot;Error %d: failed to configure %s pin %d\n&amp;quot;,
		       ret, button.port-&amp;gt;name, button.pin);
		return;
	}

	ret = gpio_pin_interrupt_configure_dt(&amp;amp;button,
					      GPIO_INT_EDGE_TO_ACTIVE);
	if (ret != 0) {
		printk(&amp;quot;Error %d: failed to configure interrupt on %s pin %d\n&amp;quot;,
			ret, button.port-&amp;gt;name, button.pin);
		return;
	}

	gpio_init_callback(&amp;amp;button_cb_data, button_pressed, BIT(button.pin));
	gpio_add_callback(button.port, &amp;amp;button_cb_data);
	printk(&amp;quot;Set up button at %s pin %d\n&amp;quot;, button.port-&amp;gt;name, button.pin);

	if (led.port &amp;amp;&amp;amp; !device_is_ready(led.port)) {
		printk(&amp;quot;Error %d: LED device %s is not ready; ignoring it\n&amp;quot;,
		       ret, led.port-&amp;gt;name);
		led.port = NULL;
	}
	if (led.port) {
		ret = gpio_pin_configure_dt(&amp;amp;led, GPIO_OUTPUT);
		if (ret != 0) {
			printk(&amp;quot;Error %d: failed to configure LED device %s pin %d\n&amp;quot;,
			       ret, led.port-&amp;gt;name, led.pin);
			led.port = NULL;
		} else {
			printk(&amp;quot;Set up LED at %s pin %d\n&amp;quot;, led.port-&amp;gt;name, led.pin);
		}
	}

	printk(&amp;quot;Press the button\n&amp;quot;);
	/*if (led.port) {
		while (1) {
			// If we have an LED, match its state to the button&amp;#39;s. 
			int val = gpio_pin_get_dt(&amp;amp;button);
                        
			if (val &amp;gt;= 0) {
				gpio_pin_set_dt(&amp;amp;led, val);
			}
			k_msleep(SLEEP_TIME_MS);
		}
	}*/
        printk(&amp;quot;Starting BLE Service\n&amp;quot;);
        err = bt_enable(bt_ready_data_data_data_data_work_work_work_work_fn);

	if (err) 
	{
		printk(&amp;quot;BLE initialization failed (err %d)\n&amp;quot;, err);
		error(); //Catch error
	}
	/* 	Bluetooth stack should be ready in less than 100 msec. 					\
																							\
		We use this semaphore to wait for bt_enable to call bt_ready before we proceed 		\
		to the main loop. By using the semaphore to block execution we allow the RTOS to 	\
		execute other tasks while we wait. */	
	err = k_sem_take(&amp;amp;ble_init_ok, K_MSEC(500));
                
	if (!err) 
	{
		printk(&amp;quot;Bluetooth initialized\n&amp;quot;);
	} else 
	{
		printk(&amp;quot;BLE initialization did not complete in time\n&amp;quot;);
		error(); //Catch error
	}



	for (;;) 
	{
		// Main loop
		//my_service_send(my_connection, (uint8_t *)&amp;amp;number, sizeof(number));
		number++;
		k_sleep(K_MSEC(1000)); // 1000ms
	}

	const char *const label = DT_LABEL(DT_INST(0, invensense_mpu6050));
	const struct device *mpu6050 = device_get_binding(label);

	if (!mpu6050) {
                printf(&amp;quot;All sensors configured %s\n&amp;quot;, label);
		//printf(&amp;quot;Failed to find sensor %s\n&amp;quot;, label);
		return;
	}

#ifdef CONFIG_MPU6050_TRIGGER
	trigger = (struct sensor_trigger) {
		.type = SENSOR_TRIG_DATA_READY,
		.chan = SENSOR_CHAN_ALL,
	};
	if (sensor_trigger_set(mpu6050, &amp;amp;trigger,
			       handle_mpu6050_drdy) &amp;lt; 0) {
		printf(&amp;quot;Cannot configure trigger\n&amp;quot;);
		return;
	}
	printk(&amp;quot;Configured for triggered sampling.\n&amp;quot;);
#endif

	while (!IS_ENABLED(CONFIG_MPU6050_TRIGGER)) {
		int rc = process_mpu6050(mpu6050);

		if (rc != 0) {
			break;
		}
		k_sleep(K_SECONDS(2));
	}

}&lt;/pre&gt;&lt;br /&gt;is there something we can do to make it clean and therefore to get the BT to work ?&lt;br /&gt;thank you in advance&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth connexion issue</title><link>https://devzone.nordicsemi.com/thread/386584?ContentTypeID=1</link><pubDate>Fri, 16 Sep 2022 10:20:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eccdae59-5539-44ce-bef9-c4adfe7c2007</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;I have not seen your updated code, but based on what you described I assume the problem is related to what I&amp;nbsp;described in my previous post: Your error variable is invalid and contains random/rubbish data, and you print that. So it does not mean anything.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth connexion issue</title><link>https://devzone.nordicsemi.com/thread/386574?ContentTypeID=1</link><pubDate>Fri, 16 Sep 2022 09:54:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7773cc0e-6341-48a7-bf9c-dc2c404844c4</guid><dc:creator>Rihab</dc:creator><description>&lt;p&gt;Thank you so much for the explanation. Now i entirely understand.&lt;br /&gt;But in your opinion what is causing the BT initialization to fail ?&lt;br /&gt;do you know what the code error below refers to please&amp;nbsp; ?&amp;nbsp;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;BLE init failed with error code 536875240&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth connexion issue</title><link>https://devzone.nordicsemi.com/thread/386557?ContentTypeID=1</link><pubDate>Fri, 16 Sep 2022 09:10:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4d0ab900-0610-4468-b526-8f481fda310b</guid><dc:creator>Einar Thorsrud</dc:creator><description>[quote user="Rihab"]i tried to search for the function bt_le_is_ready but i can&amp;#39;t find it no where&amp;nbsp;[/quote]
&lt;p&gt;There is no need for it here, it was just an idea based on the error you described before I saw all your code.&lt;/p&gt;
[quote user="Rihab"]and since u told me that i should pay attention to warnings&amp;nbsp;[/quote]
&lt;p&gt;Yes, that is good.&lt;/p&gt;
[quote user="Rihab"]the warning message is &amp;quot; passing argument 2 of &amp;#39;k_work_init&amp;#39; from incompatible pointer type [-Wincompatible-pointer-types] &amp;quot;&lt;br /&gt;Do you know what the code error means please&lt;br /&gt;is it caused by the warning ? how can i repare this warning please ?[/quote]
&lt;p&gt;Why are there 2 arguments?&amp;nbsp; The first argument you had there was invalid,&amp;nbsp; bt_ready_data_data_data_data_work_work_work_work_fn must have the prototype defined by the BT application, so it can only take an integer as argument, and this will be the error code.&amp;nbsp;You cannot have&amp;nbsp;struct&amp;nbsp;k_work in there, as this is populated by the Bluetooth stack and it would not know where to put there. So, your&amp;nbsp;bt_ready_data_data_data_data_work_work_work_work_fn &lt;em&gt;must&lt;/em&gt; look like this (though you can of course change the name of the function and the name of the variable holding the error code if you like):&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void bt_ready_data_data_data_data_work_work_work_work_fn(int err)&lt;/pre&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth connexion issue</title><link>https://devzone.nordicsemi.com/thread/386548?ContentTypeID=1</link><pubDate>Fri, 16 Sep 2022 08:51:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:959d6b9b-7ada-43fa-b3ba-f408150902a1</guid><dc:creator>Rihab</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;br /&gt;infinite thanks for taking a look into my warnings&amp;nbsp;&lt;br /&gt;but i want to tell you that:&amp;nbsp;&lt;br /&gt;now that i replaced &amp;quot;static void bt_ready_data_data_data_data_work_work_work_work_fn(struct k_work *work)&amp;quot; with &amp;quot;static void bt_ready_data_data_data_data_work_work_work_work_fn(int err)&amp;quot;&lt;br /&gt;i&amp;#39;m getting a new code error&amp;nbsp;&lt;br /&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1663317912716v1.png" alt=" " /&gt;&lt;br /&gt;and since u told me that i should pay attention to warnings&amp;nbsp;&lt;br /&gt;after my build i&amp;#39;m getting a warning when i&amp;#39;m calling the &amp;quot;k_work_init(&amp;amp;bt_ready_data_data_data_data_work, bt_ready_data_data_data_data_work_work_work_work_fn);&amp;quot; in my static void work init&amp;nbsp;&lt;/p&gt;
&lt;p&gt;the warning message is &amp;quot; passing argument 2 of &amp;#39;k_work_init&amp;#39; from incompatible pointer type [-Wincompatible-pointer-types] &amp;quot;&lt;br /&gt;Do you know what the code error means please&lt;br /&gt;is it caused by the warning ? how can i repare this warning please ?&lt;br /&gt;grateful for your help in advance&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth connexion issue</title><link>https://devzone.nordicsemi.com/thread/386529?ContentTypeID=1</link><pubDate>Fri, 16 Sep 2022 07:48:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1913e721-7e45-42f2-a221-2fb620c7d7cb</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;There are a few things missing here, most can be ignored, but for instance&amp;nbsp;my_service_send() and&amp;nbsp;my_service_init() are used by not defined anywhere in this code. So I ignore that.&lt;/p&gt;
&lt;p&gt;There are quite a few other things to note though, and that makes me want to stress that you should ensure that your code builds without warnings. The warnings are there to help you. For instance, in&amp;nbsp;bt_ready_data_data_data_data_work_work_work_work_fn() you have an err variable that is not initialized (so the content is meaningless), and you use that to figure out if BT initialization was successful or not. Which is clearly pointless. For this err to be meaningful, change the function to use int err as parameter, and remove the err variable you declare within (refer to for instance the beacon example in the SDK to see how it is done).&lt;/p&gt;
&lt;p&gt;When I remove most of your code which is not related to BT and do a quick clean-up, advertising starts without an error.&lt;/p&gt;
&lt;p&gt;Here is your stripped main.c file that works fine BT vise (advertising works and I am able to connect):&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/8540.main.c"&gt;devzone.nordicsemi.com/.../8540.main.c&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth connexion issue</title><link>https://devzone.nordicsemi.com/thread/386528?ContentTypeID=1</link><pubDate>Fri, 16 Sep 2022 07:40:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c245b2e-3f1b-4822-8f73-760d658ab8ba</guid><dc:creator>Rihab</dc:creator><description>&lt;p&gt;Hello,&lt;br /&gt;i tried to search for the function bt_le_is_ready but i can&amp;#39;t find it no where&amp;nbsp;&lt;br /&gt;can you provide me with an example code where it&amp;#39;s been used&amp;nbsp;&lt;br /&gt;thank you in advance&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth connexion issue</title><link>https://devzone.nordicsemi.com/thread/386401?ContentTypeID=1</link><pubDate>Thu, 15 Sep 2022 12:47:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2be13677-c12d-4f8d-a290-760b4ee2987c</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;I see. However, there seems to only be one condition where -EAGAIN (-11) would be returned in the case of legacy/normal advertising, and that is when Bluetooth is not ready. I do not see from these snippets why this would be a&amp;nbsp;problem, but could you check with&amp;nbsp;bt_is_ready() before calling&amp;nbsp;bt_le_adv_start()? If it is not, wait a bit before you try. Or just try first and if it returns -EAGAIN try again at a later point.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth connexion issue</title><link>https://devzone.nordicsemi.com/thread/386396?ContentTypeID=1</link><pubDate>Thu, 15 Sep 2022 12:34:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ee9a4260-47be-48c1-8923-97d31e259ed0</guid><dc:creator>Rihab</dc:creator><description>&lt;p&gt;hi,&amp;nbsp;&lt;br /&gt;thank you for your reply&amp;nbsp;&lt;br /&gt;infact i checked my code and i&amp;#39;m calling the function in the right place&amp;nbsp;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;    int err = 0;
	uint32_t number = 0;

	printk(&amp;quot;Starting BLE Service\n&amp;quot;);
	
	err = bt_enable(bt_ready_data_data_data_data_work_work_work_work_fn);

	if (err) 
	{
		printk(&amp;quot;BLE initialization failed (err %d)\n&amp;quot;, err);
		error(); //Catch error
	}
	
	/* 	Bluetooth stack should be ready in less than 100 msec. 								\
																							\
		We use this semaphore to wait for bt_enable to call bt_ready before we proceed 		\
		to the main loop. By using the semaphore to block execution we allow the RTOS to 	\
		execute other tasks while we wait. */	
	err = k_sem_take(&amp;amp;ble_init_ok, K_MSEC(500));
        
	if (!err) 
	{
		printk(&amp;quot;Bluetooth initialized\n&amp;quot;);
	} else 
	{
		printk(&amp;quot;BLE initialization did not complete in time\n&amp;quot;);
		error(); //Catch error
	}

	err = my_service_init();

	for (;;) 
	{
		// Main loop
		my_service_send(my_connection, (uint8_t *)&amp;amp;number, sizeof(number));
		number++;
		k_sleep(K_MSEC(1000)); // 1000ms
	}
&lt;/pre&gt;&lt;br /&gt;if you&amp;#39;re wondering what hae put in my function bt_ready_data_data_data_data_work_work_work_work_fn&lt;br /&gt;i&amp;#39;m linking it below&amp;nbsp;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void bt_ready_data_data_data_data_work_work_work_work_fn(struct k_work *work)
{
        int err;
	if (err) 
	{
		printk(&amp;quot;BLE init failed with error code %d\n&amp;quot;, err);
		return;
	}

	//Configure connection callbacks
	bt_conn_cb_register(&amp;amp;conn_callbacks);

	//Initalize services
	err = my_service_init();
        //printk(&amp;quot;Bluetooth initialized \n&amp;quot;);

	if (err) 
	{
		printk(&amp;quot;Failed to init LBS (err:%d)\n&amp;quot;, err);
		return;
	}


	//Start advertising
	err = bt_le_adv_start(BT_LE_ADV_NCONN_IDENTITY, ad, ARRAY_SIZE(ad),
			      sd, ARRAY_SIZE(sd));
	if (err) 
	{
		printk(&amp;quot;Advertising failed to start (err %d)\n&amp;quot;, err);
		return;
	}

	printk(&amp;quot;Advertising successfully started\n&amp;quot;);

	k_sem_give(&amp;amp;ble_init_ok);
}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;if functions are being called in the right place, then what is making the BT service failing to advertise ?&lt;br /&gt;can you help me find out please&amp;nbsp;&lt;br /&gt;Kindly,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bluetooth connexion issue</title><link>https://devzone.nordicsemi.com/thread/386366?ContentTypeID=1</link><pubDate>Thu, 15 Sep 2022 11:27:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c1030fe4-e439-4d45-aa54-3593dc7de573</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I do not see your code, but I assume you print&amp;nbsp;&amp;quot;Advertising failed to start&amp;quot; if&amp;nbsp;bt_le_adv_start() returns an error (and in that case it is only natural that you are not able to see the device from your phone when scanning, as it does not advertise). bt_le_adv_start() returns -EAGAIN if Bluetooth is not ready, so without seeing your code my guess is that you call this function too early. If need to wait until Bluetooth is enabled (for instance by using a callback that you provide to the call to&amp;nbsp;bt_enable(), as you can see form the &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/main/samples/bluetooth/beacon/src/main.c"&gt;beacon sample&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>