You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm new to BLE development, and we're using Linux (ubuntu) with the latest version of GattLib (0.7.2).
When we call the gattlib_connect function, the callback (on_device_connect) is only invoked when the function does not succeed, meaning the return value is non-zero.
Why does this happen? How can I interact with the "connection" object if the callback isn't triggered on a successful connection? Any guidance would be appreciated! (start scan and stop scan working fine)
if (IsConnected())
{
printf("already connected\n");
}
else
{
printf("connecting to device...\n");
int ret = gattlib_connect(adapter, (char*)address, GATTLIB_CONNECTION_OPTIONS_NONE, on_device_connect, NULL);
if (ret)
{
printf("Failed to connect. Error code: %d\n", ret);
current_connection = NULL;
}
else
{
printf("connected\n");
isConnected = true;
// in this state the on_device_connect callback is not invoke!!!
}
}
}
void BLEInterface::Disconnect()
{
if (!IsConnected())
{
printf("not connected\n");
}
else
{
printf("disconnecting from device...\n");
int ret = gattlib_disconnect(current_connection, true);
if (ret)
{
printf("Failed to disconnect Error code: %d\n", ret);
}
else
{
printf("disconnected\n");
isConnected = false;
}
}
I'm new to BLE development, and we're using Linux (ubuntu) with the latest version of GattLib (0.7.2).
When we call the gattlib_connect function, the callback (on_device_connect) is only invoked when the function does not succeed, meaning the return value is non-zero.
Why does this happen? How can I interact with the "connection" object if the callback isn't triggered on a successful connection? Any guidance would be appreciated! (start scan and stop scan working fine)
#include
#include <pthread.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/queue.h>
#include "gattlib.h"
#include
#include
#include
#include
typedef void (*ble_discovered_device_t)(const char *addr, const char *name);
gattlib_adapter_t *adapter;
gattlib_connection_t *current_connection;
bool isConnected;
// represent a Bluetooth device
struct Device
{
std::string name;
std::string macID;
};
// list of devices
std::vector deviceList;
void on_device_connect(gattlib_adapter_t *adapter, const char *dst, gattlib_connection_t *connection, int error, void *user_data)
{
current_connection = connection;
}
void ble_discovered_device(gattlib_adapter_t *adapter, const char *addr, const char *name, void *user_data)
{
int ret;
}
void BLEInterface::Init()
{
isConnected = false;
deviceList.clear();
}
void BLEInterface::StartScaning(BoardSide side, PairType pairingType, uint8_t roomId)
{
}
void BLEInterface::StopScaning()
{
printf("Stop scanning...\n");
}
void BLEInterface::Connect(uint8_t *address, uint8_t len)
{
}
void BLEInterface::Disconnect()
{
if (!IsConnected())
{
printf("not connected\n");
}
else
{
printf("disconnecting from device...\n");
}
bool BLEInterface::IsConnected()
{
return isConnected;
}
The text was updated successfully, but these errors were encountered: