Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 9 months ago.
Problem connection heart rate monitor
Hi,
i have a problem connection my heart rate monitor to IDB05A1.
My source code : http://pastebin.com/gdQik7Km
I have two devices.
First is a Pan1026 usb stick that emulates a hear rate monitor. Second is a Mio Link device (http://www.mioglobal.com/de-de/Mio-LINK-Pulssportarmband/Product.aspx).
First I want to scan devices and connect them to discover services/characteristics. When i try to do this with the simulator it works. But if i do the same with the real device it stops while connecting. I dont get the connection callback.
I have enabled debug messages but there is no error message. After "DISCOVERY_COMPLETE" i get debug message "Connection started".
While using simulator i get a connection complete event from the module. And after that the callback is called.
Any ideas what is wrong with my code?
If i connect with smartphone to mio device i dont have any problems and i'm able to discover services/characteristics.
regards
Frank
Question relating to:
1 Answer
9 years, 9 months ago.
Are you trying to establish two connections in parallel?
Try to skip scan responses, and change the code as follows:
void connectToDevice(const Gap::Address_t peerAddr)
{
if(!params->isScanResponse) {
ble_error_t ret = ble.gap().connect(peerAddr, Gap::ADDR_TYPE_PUBLIC, NULL, NULL);
}
...
I think skip scan responses is in advertising callback?
I change code
oid scanResultReceived(const Gap::AdvertisementCallbackParams_t *params)
{
PRINTF("\r\nscanResultReceived\r\n");
//print advertsing values
PrintScanResult(params);
if(!params->isScanResponse) {
PRINTF("scan result ... try connect\r\n");
connectToDevice(params->peerAddr);
}
}
void connectToDevice(const Gap::Address_t peerAddr)
{
ble_error_t ret = ble.gap().connect(peerAddr, Gap::ADDR_TYPE_PUBLIC, NULL, NULL);
if(ret == BLE_ERROR_NONE) {
PRINTF("SUCCESS: connect\r\n");
} else {
PRINTF("ERROR : connect\r\n");
}
}
But result is the same...
EDIT:
I found problem connection mio link device.
If i change address type in connection function to RANDOM_ADDR it works. But now it doesn't connect to simulator device.
ble_error_t BlueNRGGap::createConnection ()
{
tBleStatus ret;
/*
Scan_Interval, Scan_Window, Peer_Address_Type, Peer_Address, Own_Address_Type, Conn_Interval_Min,
Conn_Interval_Max, Conn_Latency, Supervision_Timeout, Conn_Len_Min, Conn_Len_Max
*/
ret = aci_gap_create_connection(SCAN_P,
SCAN_L,
RANDOM_ADDR,
(unsigned char*)_peerAddr,
PUBLIC_ADDR,
CONN_P1, CONN_P2, 0,
SUPERV_TIMEOUT, CONN_L1 , CONN_L2);
_connecting = false;
if (ret != BLE_STATUS_SUCCESS) {
printf("Error while starting connection (ret=0x%02X).\n\r", ret);
return BLE_ERROR_UNSPECIFIED;
} else {
PRINTF("Connection started.\n");
for(int i=0; i<BDADDR_SIZE; i++) {
PRINTF("0x%02X ",_peerAddr[i]);
}
return BLE_ERROR_NONE;
}
}