Howdy,
I am using an nRF52840 to perform BLE communication. For this communication I am using extended advertising to perform most of my data transmission. Thing is though, sometimes I need to connect to the device to perform updates and send commands. I set up all the connection callbacks and have the system reestablish advertising after disconnecting. To test all of this, I decided to use the nRF Connect app to test the connection. The problem I am facing is that when I try to connect, it seems to get stuck in a loop of connecting and disconnecting. My phone simply says that it is trying to connect, while my code shows that it is connecting and disconnecting rapidly. I have attached the setup functions and my callbacks for the connection in the code below. Any help would be much appreciated.
static struct bt_conn *default_conn;
struct bt_le_ext_adv *adv;
static struct bt_le_adv_param adv_param = {
.options = BT_LE_ADV_OPT_USE_IDENTITY | BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_EXT_ADV,
// .interval_min = BT_GAP_ADV_FAST_INT_MIN_1, // Every 1 to 3 seconds
// .interval_max = BT_GAP_ADV_FAST_INT_MAX_1,
.interval_min = BT_GAP_ADV_SLOW_INT_MIN,
.interval_max = BT_GAP_ADV_SLOW_INT_MAX,
.peer = NULL
};
struct bt_data adv_data[] = {
BT_DATA(BT_DATA_MANUFACTURER_DATA, "Random Junk", 12),
};
static void app_led_cb(void)
{
byte_status = byte_status | 0b00000001; // Set LED status bit to 1
nrf_gpio_pin_set(LED_R);
k_timer_start(&led_timeout, LED_TIMEOUT_SECONDS, LED_TIMEOUT_SECONDS);
}
static struct my_lbs_cb app_callbacks = {
.led_cb = app_led_cb,
};
static void connected(struct bt_conn *conn, uint8_t err)
{
if (err) {
#if INCLUDE_PRINT_STATEMENTS
printk("Connection failed (error 0x%02x)\n", err);
#endif
}
else
{
#if INCLUDE_PRINT_STATEMENTS
printk("Connected\n");
#endif
}
default_conn = bt_conn_ref(conn);
}
static void disconnected(struct bt_conn *conn, uint8_t reason)
{
printk("Disconnection started\n");
bt_conn_unref(default_conn);
default_conn = NULL;
}
static void recycled_cb(void){
int ret = bt_le_ext_adv_start(adv, NULL);
if (ret)
{
#if INCLUDE_PRINT_STATEMENTS
printk("Advertising failed to start (err %d)\n", ret);
#endif
}
printk("Successfully Disconnected\n");
}
static struct bt_conn_cb conn_callbacks = {
.connected = connected,
.disconnected = disconnected,
.recycled = recycled_cb,
};