Hi,
I am working on a project wherein the default state of the chip is extended sleep mode. On reception of a low signal gpio interrupt, the chip wakes up, advertises 5 packets. After this, the device switches to scan mode. Now, when the device receive an advertising report, it switches to advertisement mode advertises the received packet, and after advertisement, switches back to scan. This process continues until 5 BLE packets are sent from the device. Parallely, I have initiated a uart2_read() operation in the app_wakeupcb(). Now, after advertisement of 5th packet(ie, the device is in peripheral/advertisement mode), the uart data is checked, and if any data is received, that data is sent from the device. This flow works fine.
Now, on the other hand, if no advertisement reports are received(ie, role switching has not taken place), in the scanning_completed()[which is invoked after 10s scan timeout since general discovery mode scan is used], role switching to adv mode is initiated, the uart data is checked, and if any data is received, that data is sent from the device. While I am verifying the code flow using breakpoints, the flow works fine. But, the device is not sending any advertisement. After initiating each advertisement start command, I am invoking a 50ms timer to cancel advertisement. The flow even reaches this callback with error status GAP_ERR_CANCELED. Why is this happening ?
The code snippet is as follows :
void scanning_completed(uint8_t status)
{
if(status == GAP_ERR_TIMEOUT){
user_app_configuration_func(GAP_PERIPHERAL_SLV);
}
}
void user_app_configuration_func(uint8_t role)
{
struct gapm_set_dev_config_cmd* cmd = KE_MSG_ALLOC
(
GAPM_SET_DEV_CONFIG_CMD,
TASK_GAPM, TASK_APP,
gapm_set_dev_config_cmd
);
// Set device configuration
cmd->operation = GAPM_SET_DEV_CONFIG;
// Set role
cmd->role = role;
memset( cmd->irk.key, 0, sizeof(struct gap_sec_key));
cmd->appearance = 0;
cmd->appearance_write_perm = GAPM_WRITE_DISABLE;
cmd->name_write_perm = GAPM_WRITE_DISABLE;
ke_msg_send(cmd);
return;
}
void user_app_on_set_dev_config_complete( void )
{
send_uart_status();
}
void send_uart_status(void){
struct gapm_start_advertise_cmd* cmd;
cmd = app_easy_gap_non_connectable_advertise_get_active();
memset(cmd->info.host.adv_data,0,28);
memset(cmd->info.host.adv_data, 0, 28);
cmd->info.host.adv_data_len = 28;
memcpy(cmd->info.host.adv_data ,header_data,sizeof(header_data));
memcpy(&(cmd->info.host.adv_data[4]),sample_data,sizeof(sample_data));
app_easy_gap_non_connectable_advertise_start();
timer_50ms = app_easy_timer(5,handle_50ms_timer);
}
void handle_50ms_timer(void)
{
++no_of_uart_pkts_sent;
app_easy_gap_advertise_stop();
}
void user_app_adv_nonconn_complete(uint8_t status)
{
if(no_of_uart_pkts_sent < 5){
send_uart_status();
}
else{
no_of_uart_pkts_sent = 0;
go_to_sleep();
}
}
void go_to_sleep(void)
{
arch_set_sleep_mode(ARCH_EXT_SLEEP_ON);
arch_ble_ext_wakeup_on();
/ /配置唤醒的屁股on
app_button_enable();
}
The control is as per expectation.
ie, after 10 second timeout, the control reaches scanning_completed(), and on successful device configuration completion, reaches send_uart_status().
When the no_of_uart_packets_sent count becomes 5, the device enters the go_to_sleep() also.
But the advertisement do not seem to go out of the chip, when I am verifying using sniffer.
Please suggest the reasons and solutions for the same as early as possible, as this is blocking for our further development.
Thanks
Wisilica
Hi wisilica,
If i get your case properly, correct me if i am wrong, there is a case where upon switching role from central to peripheral (when there are no advertising packets received when the device is operating as central) you issue a start advertise command and you see no advertising packets from the device when operating as peripheral, instead you get a advertise complete callback that the current advertising procedure was cancelled. I dont see any obvious reason for this to occur unless you are invoking a cancel command for cancelling the advertising procedure prior to the 50 ms timer callback, you will have to experiment with your setup in order to find out why this happens, for example you could start with the following experiment if you dont setup the 50 ms timer to cancel the advertising or if you setup a larger timer, does this have the same effect ? Are you still not able to see the device advertising ? Are you still getting the completion callback ? With what status ?
Also i suppose that the the reason for starting and stopping the advertising procedure is because you would like to count the advertising events and based on the emmited packets act. As a suggestion there is a more efficient and straightforward way to do that instead of starting and stopping the advertising procedure, please check the beacon example in the user_on_ble_powered() callback, you can use that in order to count the advertising events (the functionallity checks that the last BLE event is a BLE_EVT_END and if it is acts, so you can just increase a counter measuring the advertising events). You can poll the state of your counter in the user_on_ble_powered() as well and attach a functionallity at that point.
Thanks MT_dialog