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

app_timer code merged with ble_app_beacon from Nordic SDK

Hi, 

I have merged these two codes from SDK: 

\nRF5_SDK_17.0.2_d674dde\examples\peripheral\timer

\nRF5_SDK_17.0.2_d674dde\examples\ble_peripheral\ble_app_beacon

I want my app_timer to interrupt every 1second upon which it sends an advertisement beacon. 

In practice, my device just sends 1 advertisement beacon and then it stops sending the next ones, 

Can you advise what is done wrong here,

Thanks 

Parents
  • Hi,

    I have some questions about this. Why to you use a app_timer to advertise regularly? Advertising is by nature repeated, and you can configure the advertising interval to 1 second so that it automatically sends a packet every 1 minute. Why do you need an app timer for this?

    Also, the app_timer itself looks correct. You have a repeated app timer with a timeout of 1000 ms. So the timeout handler should run every time. However, I expect you will get an error the second time as you try to configure advertising again without stopping it (it is possible to update just the advertising data without stopping it, but tat has to be done differently).

    Wrapping up, there are several issues here, but I do not understand what you really want to do. Perhaps you can explain the end goal, and then I can try to suggest a sensible way to do wat you want do do?

Reply
  • Hi,

    I have some questions about this. Why to you use a app_timer to advertise regularly? Advertising is by nature repeated, and you can configure the advertising interval to 1 second so that it automatically sends a packet every 1 minute. Why do you need an app timer for this?

    Also, the app_timer itself looks correct. You have a repeated app timer with a timeout of 1000 ms. So the timeout handler should run every time. However, I expect you will get an error the second time as you try to configure advertising again without stopping it (it is possible to update just the advertising data without stopping it, but tat has to be done differently).

    Wrapping up, there are several issues here, but I do not understand what you really want to do. Perhaps you can explain the end goal, and then I can try to suggest a sensible way to do wat you want do do?

Children
  • Thanks Einar. So in my timer handler if I stop advertising, that will fix the issue? 

    The reason I used a timer for advertising is because I want my peripheral to advertise every 1 second as a non-connectable beacon, and then perform ble pairing with a central device using the other Nordic examples every 15 seconds to receive some data from central as a connectable beacon. So my configuration would change every 15 second based on a timer that synchronize these two tasks. 

  • Hi,

    Kaveh.M said:
    Thanks Einar. So in my timer handler if I stop advertising, that will fix the issue? 

    Yes, that would certainly fix one error. There may be more, though.

    Kaveh.M said:
    The reason I used a timer for advertising is because I want my peripheral to advertise every 1 second as a non-connectable beacon, and then perform ble pairing with a central device using the other Nordic examples every 15 seconds to receive some data from central as a connectable beacon.

    I see. And you want only a single advertising packet every second? If so, you should keep the configured advertising interval at 1 second. But I do not see a good reason for using a 1 second timeout for the app timer. If you want to change mode every 15 seconds, then that is probably what you should use. There is no need to restart advertising every 1 second when there is no change. Also, you need to consider how you indent this to work in practice with the connection, which could perhasp sometimes take some time to establish, and perhaps sometime does not happen. Should you have a timeout for that? Etc. I believe it makes sense to think a bit more about such details before jumping into implementation.

  • Great. I ll use 1second intervals for my advertisement, and stop advertisement every 15seconds using my timer, then I ll perform pairing to communicate some data between central and peripheral. 

    I assume using the following examples and merge it with my existing code for BLE pairing and data communication. 

    \examples\ble_central\ble_app_uart_c\pca10040\s132\   -> for Central

    \examples\ble_peripheral\ble_app_uart\pca10040\s132  -> for Peripheral

    Please let me know if there are better sample codes to use for this purpose. 

Related