This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Scan for other devices using nrf51422 PCA10028

Hello, I would appreciate if you could help me solve what i am trying to do. I have nrf51DK board with nrf51422 on it, PCA10028, S130 and i want to use to scan for another devices, but i don't need to scan for all devices, what i want is to make it scanning only for one devices with known address. Does nrf51422 support this possibility? Scan only for a device with known address? After i found this device, i want to change the role and start advertising some data for a certain time(thats why i loaded chip with S130, because if i understand correct, it is possible to use same device for scanning and advertising).If so, could you provide some notes or example hot to do this? Right now i am playing with experimental_ble_app_multiactivity_beacon_hrs_ scanner example and i haven't totally figured out how example works, but i can see that i can monitor found device address in adv_packet structure ( adv_packet->addr.addr). However, don't know where to move from this point. Thank you very much in advance, Regards.

  • Woops, my mistake. Actually the code is working. But could you check if it is okay if i stop advertisements like this? I mean is it allowed, won't i cause hard fault or something if i'll try to stop advertise while it is going? because i don't know if device is advertising at the time i am calling sd_ble_gap_adv_stop(); function. Still keep an eye of this post if still possible :) Thanks.

  • If sd_ble_gap_adv_stop() returns an error and you then call APP_ERROR_CHECK you will end up in app_error_handler in a while(true) loop. This will happen if you call it when you are not advertising, because you will get NRF_ERROR_INVALID_STATE. So you can either handle(ignore) the error, so something like:

    err_code = sd_ble_gap_adv_stop();
    if(err_code == NRF_ERROR_INVALID_STATE)
    {
         err_code = NRF_SUCCESS;
    }
    APP_ERROR_CHECK(err_code);
    

    Another option is to set the advertising timeout (APP_ADV_TIMEOUT_IN_SECONDS). But the minimum timeout is 1 second. Then you don't need to call sd_ble_gap_adv_stop() at all.

  • Hello, i wanted to give a feedback and ask few last questions :) So i did what i need in my application: I'm scanning for devices and give a report when a device with specific address, which i know, is found. Then i start advertising for some time, actually for 1s, using APP_ADV_TIMEOUT_IN_SECONDS which you have mentioned. after i receive this event in a handler, i start to scan again and so on. Everything is tested and works fine. So thank you very much for your support, i'm accepting your answer now :) And the last question for this topic: stopping advertise after 1s is okay for now. But later i might be forced to lower the advertising time, so in case i need to stop advertising lets say after 250ms, how would you recommend to do it? just start advertising, and after advertising start function put a delay of 250ms, then stop? Would power consumption go up in this case? Thanks in advance. :)

  • Thank you for the feedback. Appreciate it. Could you add this question as a new question? This is getting a bit cluttered.

  • Sure. Do you want me to create new question and post everything i did to make this work, or just add the question and you will fix things up? I can make a short review how i did this and add it as an answer below newly created question. :)

Related