Skip to content

Correct value of BLE.connected() #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions libraries/CurieBLE/src/BLEPeripheral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ BLECentral BLEPeripheral::central(void)

bool BLEPeripheral::connected(void)
{
BLEDevice centralBle = BLE.central();
return centralBle.connected();
return BLE.connected();
}

void BLEPeripheral::init()
Expand Down
37 changes: 31 additions & 6 deletions libraries/CurieBLE/src/internal/BLEDeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,43 @@ void BLEDeviceManager::end()

bool BLEDeviceManager::connected(const BLEDevice *device) const
{
bt_conn_t* conn = bt_conn_lookup_addr_le(device->bt_le_address());
bool retval = false;
//pr_debug(LOG_MODULE_BLE, "%s-%d: add-%s", __FUNCTION__, __LINE__, device->address().c_str());
if (NULL != conn)

if (BLEUtils::isLocalBLE(*device))
{
//pr_debug(LOG_MODULE_BLE, "%s-%d: state-%d", __FUNCTION__, __LINE__,conn->state);
if (conn->state == BT_CONN_CONNECTED)
// first check if in peripheral mode and a central is connected
if (BLEUtils::macAddressValid(_peer_central))
{
retval = true;
}
bt_conn_unref(conn);
else // next check if in central mode and connected to any peripherals
{
for (int i = 0; i < BLE_MAX_CONN_CFG; i++)
{
if (BLEUtils::macAddressValid(_peer_peripheral[i]))
{
retval = true;
break;
}
}
}
}
else
{
bt_conn_t* conn = bt_conn_lookup_addr_le(device->bt_le_address());

//pr_debug(LOG_MODULE_BLE, "%s-%d: add-%s", __FUNCTION__, __LINE__, device->address().c_str());
if (NULL != conn)
{
//pr_debug(LOG_MODULE_BLE, "%s-%d: state-%d", __FUNCTION__, __LINE__,conn->state);
if (conn->state == BT_CONN_CONNECTED)
{
retval = true;
}
bt_conn_unref(conn);
}
}

return retval;
}

Expand Down