cancel
Showing results for 
Search instead for 
Did you mean: 

BLUENRG - Beacon mode.

Posted on October 01, 2015 at 14:45

First I configure the module.

void BLUENRG_Setup(void) 
{ 
HCI_Init(); 
BlueNRG_RST(); 
Osal_MemCpy(bdaddr, SERVER_BDADDR, sizeof(SERVER_BDADDR)); 
/* Configure BlueNRG address as public (its public address is used) - MAC address of the device */ 
ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, CONFIG_DATA_PUBADDR_LEN, bdaddr); 
if(ret){ /*PRINTF(''Setting BD_ADDR failed.\n''); */ } 
/* Init BlueNRG GATT layer */ 
ret = aci_gatt_init(); 
if(ret){ } 
/* Init BlueNRG GAP layer as peripheral */ 
ret = aci_gap_init(GAP_PERIPHERAL_ROLE, &service_handle, &dev_name_char_handle, &appearance_char_handle); 
if(ret != BLE_STATUS_SUCCESS){ } 
ret = aci_gatt_update_char_value(service_handle, dev_name_char_handle, 0, 
strlen(name), (uint8_t *)name); 
if(ret){ } 
ret = aci_gap_set_auth_requirement(MITM_PROTECTION_REQUIRED, 
OOB_AUTH_DATA_ABSENT, 
NULL, 
7, 
16, 
USE_FIXED_PIN_FOR_PAIRING, 
123456, 
BONDING); 
if (ret == BLE_STATUS_SUCCESS) { } 
// Set output power level 
ret = aci_hal_set_tx_power_level(1,4); 
} 

Then I set itconnectable.

tBleStatus ret; 
const char local_name[] = {AD_TYPE_COMPLETE_LOCAL_NAME,'B','l','u','e','N','R','G'}; 
/* disable scan response */ 
hci_le_set_scan_resp_data(0,NULL); 
ret = aci_gap_set_discoverable(ADV_NONCONN_IND, 160, 160, PUBLIC_ADDR, NO_WHITE_LIST_USE, sizeof(local_name), local_name, 0, NULL, 0, 0); 
if (ret != BLE_STATUS_SUCCESS) { } 
//Remove this AD type otherwise beaconPayload exceed the maximum size 
ret = aci_gap_delete_ad_type(AD_TYPE_TX_POWER_LEVEL); 
} 

And periodically change the data.

uint32_t BLUENRG_DataUpdate(void) 
{ 
tBleStatus ret=0; 
adv_data[0] = 0xAA; //start packet 
adv_data[1] = idx++; //global variable – for debug 
adv_data[2] = 0xBB; //end packet 
ret = aci_gap_update_adv_data(sizeof(data), data); 
if (ret != BLE_STATUS_SUCCESS) 
{ 
return BLE_STATUS_ERROR ; 
} 
return BLE_STATUS_SUCCESS; 
} 

The problem that the Packet Sniffer sees always the same data AA 00 BB.

Why the beacon data is not updated?

8 REPLIES 8
Posted on October 01, 2015 at 15:57

Hi,

when you use the command aci_gap_update_adv_data you have to format the packet correctly.

 Please for futher details you can see in the Beacon script or IAR project.

The data has be formatted in according to the spec:

 

data = [lenData , AD_TYPE ] + data.

Anyway, in your code you are defined the variable

adv_data

while after you use data.

Regards,

GM

Posted on October 01, 2015 at 16:26

I did asin the demo

uint32_t BLUENRG_DataUpdate(void) 
{ 
tBleStatus ret=0; 
uint8_t manuf_data[] = {6, AD_TYPE_MANUFACTURER_SPECIFIC_DATA, 
0xAA, 
0x00, 
0x00, 
0x00, 
0xBB 
}; 
//for debug 
manuf_data[4] = idx++; 
ret = aci_gap_update_adv_data(7, manuf_data); 
if (ret != BLE_STATUS_SUCCESS) 
{ 
return BLE_STATUS_ERROR ; 
} 
return BLE_STATUS_SUCCESS; 
} 

I see the same data - no update 06 FF AA 00 01 00 BB
Posted on October 01, 2015 at 16:47

have you defined the variable idx ?

Posted on October 01, 2015 at 16:52

yes, of course. it's a global variable. I see it with a debugger J-Link. it's updated every 4 seconds - the period I set.

This is the data I see in the sniffer.

________________

Attachments :

adv4.png : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Ht2D&d=%2Fa%2F0X0000000aJ7%2FWyLgFXJ7zT7_.rgi_zBPW_Tr4nD1YpgVlfWm7LeOH_A&asPdf=false
Posted on October 02, 2015 at 11:52

Hi,

in attach you can find a script that should simulate your scenario. To run it, you should:

- Launch an instance of GUI DK 1.8.0

- open the COM PORT related to the device

- Goto Scripts tab

- select the script file and run it

Wtih sniffer , you should see that each 4 second the ADV packet is updated.

Regards,

GM

Posted on October 04, 2015 at 08:29

Thank you for the script. I'm trying to implement the beacon on the embedded side so I write in C. The sniffer should get the beacon.

If I want to port the script to my device how should I write it in C?

I found the problem (I guess). Pin interrupt request has

HCI_Isr()

routine in it. But somehow it doesn’t processed right. So I added in the main routine.

if (BlueNRG_DataPresent())

{

    

HCI_Isr()

;

}
Posted on October 05, 2015 at 10:07

You could see the IAR project under folder:

C:\Program Files (x86)\STMicroelectronics\BlueNRG DK 1.8.0\Projects\Projects_STD_Library\BLE_Beacon

and modify it in according to the script.

Regards,

GM

Posted on October 05, 2015 at 11:17

Thank you.