CYBLE-416045-02 Observer mode, scan Bluetooth devices

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Bartek
Level 3
Level 3
10 replies posted 10 sign-ins 5 replies posted

Dear all,

I try to run two Bluetooth devices on CYBLE-416045-02.

1. It is BLE  mouse  (it works)

2. Observer that scan air and should give list of peer devices and their RSSI.

a) I add observer to bluetooth component 

b) I add two events to 

            case CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT:

             case CY_BLE_EVT_GAPC_SCAN_START_STOP:

c) I run star scanning by function:

               Cy_BLE_GAPC_StartScan(CY_BLE_SCANNING_FAST,CY_BLE_OBSERVER_CONFIGURATION_0_INDEX);

When I try to get any scan results by checking appScanDevInfo.count in event CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT it gives 0.

I will be thankfull if someone give me information how I can scan nerby bluetooth devices and get their  adreses and RSSI.

 

Regards,

Bartek

 

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
Yugandhar
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 5 likes given

Hello,

You can use the Cy_BLE_GATTC_ReadCharacteristicValue() if you know the attribute handle value. Internally, Read Request is sent to the peer GATT Server. If the read operation is successful, GATT Server sends a Read Response. This response results in CY_BLE_EVT_GATTC_READ_RSP event at the GATT Client's end, and response is passed to the application as shown in below code.
Please refer to the attached project for this operation.

*************************************************************
cy_stc_ble_gattc_read_req_t readReq;

readReq.connHandle = conn_handle;
readReq.attrHandle = 0x0003;

apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReq);


case CY_BLE_EVT_GATTC_READ_RSP:

read = (cy_stc_ble_gattc_read_rsp_param_t*) eventParam;
printf("Device name is \r\n");
for(uint8 k=0;k<=read->value.len;k++)
printf("\r\n %x",read->value.val[k]);

break;
*************************************************************

Thanks,
P Yugandhar.

View solution in original post

0 Likes
17 Replies
VenkataD_41
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi Bartek,

The event parameter for the event CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT is of the form cy_stc_ble_gapc_adv_report_param_t. You can decode this event parameter to get the details like device address, RSSI, scan response data, device address type, etc. 

To find the event params corresponding to particular events, you can go and look at the definition of various events by right-clicking on the events and selecting "Go to Definition" tab.

Hope this helps! 

Thanks and regards

Ganesh

0 Likes
Bartek
Level 3
Level 3
10 replies posted 10 sign-ins 5 replies posted

Thank you ! 😉

I put code like that to check if it works:

case CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
{
cy_stc_ble_gapc_adv_report_param_t *advReport = (cy_stc_ble_gapc_adv_report_param_t *)eventParam;
if((advReport->eventType == CY_BLE_GAPC_NON_CONN_UNDIRECTED_ADV) &&
(cy_ble_scanIndex == CY_BLE_OBSERVER_CONFIGURATION_0_INDEX))
{

DBG_PRINTF("rssi - %d dBm\r\n", advReport->rssi);
DBG_PRINTF("addr: %x:%x:%x:%x:%x:%x\r\n", advReport->peerBdAddr[5],advReport->peerBdAddr[4],advReport->peerBdAddr[3],
advReport->peerBdAddr[2],advReport->peerBdAddr[1],advReport->peerBdAddr[0]);

}
}
break;

Looks that it works it gives correct rssi but addresses  are not correct. I don't know why 

example it should be 8 d2 3e 72 7b 20 but it gives me 26 8b 1d c9 6f 90.

Incorrect address is also not constant for given device.

 

0 Likes
lock attach
Attachments are accessible only for community members.
VenkataD_41
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi,

Can you please try this code snippet instead of the one you used. I changed the advReport from pointer to normal variable.

case CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
{
cy_stc_ble_gapc_adv_report_param_t advReport = *(cy_stc_ble_gapc_adv_report_param_t *)eventParam;
if((advReport.eventType == CY_BLE_GAPC_NON_CONN_UNDIRECTED_ADV) &&
(cy_ble_scanIndex == CY_BLE_OBSERVER_CONFIGURATION_0_INDEX))
{

DBG_PRINTF("rssi - %d dBm\r\n", advReport.rssi);
DBG_PRINTF("addr: %x:%x:%x:%x:%x:%x\r\n", advReport.peerBdAddr[5],advReport.peerBdAddr[4],advReport.peerBdAddr[3],
advReport.peerBdAddr[2],advReport.peerBdAddr[1],advReport.peerBdAddr[0]);

}
}
break;

Please find the attached project which I tested at my side and it is working fine.

Thanks and regards

Ganesh

0 Likes
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

Bartek,

A while back I provided a dual-project workspace.  One project was a Beacon (Advertiser), the other a Observer (Scanner).

Each project had a Terminal interface that allowed the user to modify the Beacon properties and the other to modify the Observer properties (such as displaying BLE addresses and RSSI).

It was meant to be a tool for me to learn about BLE.

I think you would find this code useful for instruction and a good place to start.

link: PSoC6-BLE-Beacon-and-Scanner-Creator-projects 

Len
"Engineering is an Art. The Art of Compromise."
Bartek
Level 3
Level 3
10 replies posted 10 sign-ins 5 replies posted

Thank you 🙂

I will check it. But still why I get wrong mac addresses?  I  have no idea  😞

 

0 Likes

Bartek,

Check out this WikiPedia reference to MAC addresses.  MAC addresses (WikiPedia) 

It defines MAC addresses as being manufacturing-assigned.  Therefore, if you were manufacturing a product, you as the manufacturer need to go to IEEE organization to acquire a group of MAC addresses (which encode a manufacturer ID assigned to you).

The Infineon BLE product has the ability to publish a static or random BDADDR.  If random, then the address will be different between connection sessions.  This is probably what you are seeing.

If the BDADDR is static, there are two types.  One is customer supplied and the other is a CPU-generated number based on the unique Silicon ID of the CPU.  It sounds like you want this type at least before you need to acquire your own MAC addresses.

Len
"Engineering is an Art. The Art of Compromise."
Bartek
Level 3
Level 3
10 replies posted 10 sign-ins 5 replies posted

I know. But the problem is not a address of my device but addresses of scanned devices (peer devices) example my laptop.

I use below simply code :

case CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT:
{
cy_stc_ble_gapc_adv_report_param_t *advReport = (cy_stc_ble_gapc_adv_report_param_t *)eventParam;
if(cy_ble_scanIndex == CY_BLE_OBSERVER_CONFIGURATION_0_INDEX)
{
DBG_PRINTF("rssi - %d dBm\r\n", advReport->rssi);
DBG_PRINTF("\r\n addr: %x:%x:%x:%x:%x:%x\r\n", advReport->peerBdAddr[5],advReport->peerBdAddr[4],advReport->peerBdAddr[3],
advReport->peerBdAddr[2],advReport->peerBdAddr[1],advReport->peerBdAddr[0]);

}
}
break;

After new program, sometimes my cypress device  reset or peer device reset I got different bluetooth address of  my laptop or other bluetooth devices that are nearby. I think there is an error in libary or I'm doing some errors in pointers and   I got no value but for example address. 

I don't have any idea how to fix it.

0 Likes
VenkataD_41
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi Bartek,

I know. But the problem is not the address of my device but addresses of scanned devices (peer devices) example my laptop.

As Len mentioned, the problem might not be with the Scanner device. It might be with those devices which are advertising. The devices can advertise through Static or Random addresses. In case the devices advertise with Random addresses, you will see different addresses from time to time. Please use the BLE Find me code example and change the address of it according to your wish and check if your scanner is scanning that address properly or not.

After new program, sometimes my cypress device  reset or peer device reset I got different bluetooth address of  my laptop or other bluetooth devices that are nearby. I think there is an error in libary or I'm doing some errors in pointers and   I got no value but for example address.

Please ensure that you are using the latest version of PDL which is 3.1.3? Also if possible, please attach the scanner project where you are seeing these problems.

Thanks 

Ganesh 

0 Likes
Bartek
Level 3
Level 3
10 replies posted 10 sign-ins 5 replies posted

Hi Ganesh,

You are right it could be that devices advertise with random address, I'm using PDL 3.1.4.

Do you know how to get scanned device name instead of address ?

Regards,

Bartek 

0 Likes
lock attach
Attachments are accessible only for community members.
VenkataD_41
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi Bartek,

The device name could be part of the advertisement packet. However, the developer who developed the peripheral device will have an option to choose whether to advertise the device name or not. Only when the device advertises the name in the advertisement packet, you can find the advertising name.

The event parameter that comes with event CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT will have the advertisement data also (please find the attached image). The device name generally starts with the 5th byte of the advertisement packet. Please note that the maximum advertisement packet will be 31 bytes.

Hope this helps!

Thanks and regards

Ganesh

0 Likes

Ganesh,

You are correct.  It is optional if the advertiser wants to send a device name.

Are you aware of a standard BLE packet to request a device name from an advertising device?

If there is one and the device supports it, it might be a way to detect your intended device.

There is also a way to advertise a Manufacture ID and sub-ID.  This is a way to compress manufacturing data to meet the 31 byte advertising packet limit.

My Scanner project has the ability of decoding an advertising packet (Verbose mode) to try to find this type of info. (If it is sent.)

Len
"Engineering is an Art. The Art of Compromise."
lock attach
Attachments are accessible only for community members.
VenkataD_41
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi Bartek,

The request to read the device name is possible only after connecting to that device. The default GATT database of the server has the Generic Access service which is a standard service. Inside that standard service, you can see the standard Device Name characteristic. So after connection using the API Cy_BLE_GATTC_ReadUsingCharacteristicUuid() you can read the peer device name. The Device name characteristic is Bluetooth SIG specified characteristic. The UUID is fixed i.e. 0x2A00 as shown in the image attached.

In your case since there is no connection established, reading the device name is possible only through the advertisement packet.

Thanks and regards

Ganesh

0 Likes
Bartek
Level 3
Level 3
10 replies posted 10 sign-ins 5 replies posted

Thank you 🙂 

You are really helpfull 🙂

0 Likes
Bartek
Level 3
Level 3
10 replies posted 10 sign-ins 5 replies posted

Ganesh,

Sorry for asking so many questions ( I'm totaly new in cypress uC), but could you give me code example how to use Cy_BLE_GATTC_ReadUsingCharacteristicUuid()  to get connected device name?

Regards,

Bartek

0 Likes
VenkataD_41
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi Bartek,

I will try to develop a code example for you. Meanwhile, we recommend you go through the example projects mentioned by Len in one of the previous posts and the code examples present in PSoC Creator.

The information about how to use the API is available from PDL documentation. You can access it from PSoC Creator--> Help--> Documentation--> Peripheral Driver Library. Once you open the page of PDL documentation, you need to click on Middleware and Software API reference--> BLE middleware library--> API refernce--> BLE Common API. Here you will see all the APIs related to BLE. 

You can read the documentation of those APIs you have already used and then read the API Cy_BLE_GATTC_ReadUsingCharacteristicUuid() for better understanding.

Hope this helps!

Thanks

Ganesh

0 Likes
Bartek
Level 3
Level 3
10 replies posted 10 sign-ins 5 replies posted

Hi Ganesh,

Thank you. I will be very thankfull if you could develop some  example. 

Regards,

Bartek 

0 Likes
lock attach
Attachments are accessible only for community members.
Yugandhar
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 5 likes given

Hello,

You can use the Cy_BLE_GATTC_ReadCharacteristicValue() if you know the attribute handle value. Internally, Read Request is sent to the peer GATT Server. If the read operation is successful, GATT Server sends a Read Response. This response results in CY_BLE_EVT_GATTC_READ_RSP event at the GATT Client's end, and response is passed to the application as shown in below code.
Please refer to the attached project for this operation.

*************************************************************
cy_stc_ble_gattc_read_req_t readReq;

readReq.connHandle = conn_handle;
readReq.attrHandle = 0x0003;

apiResult = Cy_BLE_GATTC_ReadCharacteristicValue(&readReq);


case CY_BLE_EVT_GATTC_READ_RSP:

read = (cy_stc_ble_gattc_read_rsp_param_t*) eventParam;
printf("Device name is \r\n");
for(uint8 k=0;k<=read->value.len;k++)
printf("\r\n %x",read->value.val[k]);

break;
*************************************************************

Thanks,
P Yugandhar.

0 Likes