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

Beacon wake up , Advertise, sleep on Switch Press

Hello,

We do not want our beacon on at all times. I suppose our need below has been asked before.

Is there a sample snippit of code, or a document on ble_app_beacon to help us execute this small main.c change?

ble_stack_init();
advertising_init();
nrf_gpio_cfg_input(BSP_BUTTON_0, NRF_GPIO_PIN_PULLUP);
nrf _gpio_cfg_input(BSP_BUTTON_1, NRF_GPIO_PIN_PULLUP);

// Some code to setup wake up event

     While (1)
    {
     System Off // not sure on detail for this for just detecting the switch event2
     GPIO Event //wait for switch press event on Beacon onboard switches
     System ON
     run advertising_start(); 
     wait 1000 ms
    }

We are compiling with nRF51822 SmartBeacon pca10028_nrf51422_xxac_s130

Thanks, we are just very new to this code, and would like to streamline the time to get this one change made. Any help would be appreciated.

Thanks to all

  • You can set the device to advertise for 1 second. When you get the BLE_GAP_EVT_TIMEOUT event from the SoftDevice (after 1 second of advertising) you can enter SYSTEM OFF sleep mode with GPIO wakeup. When the system wakes up from SYSTEM OFF sleep mode it will do a reset and hence start advertising for one second again. See this main file used for the ble_app_beacon example in SDK: main.c

    If you don’t want to reset when you wake up you can enter SYSTEM ON sleep mode (draws a couple of uA more than SYSTEM OFF sleep mode) with sd_app_evt_wait(). Configure gpio to give you interrupt on change (see pin_change_int example in SDK for this) and start advertise again for 1 second.

  • Your answer was perfect. Thank you. I took the main.c code and started to use it as an example... then realized it was already fully working. Thanks for not just suggesting idea, but executing a working solution.

    We have updated this now to do our Major/Minor updates on button press and other changes needed and its all good :)

    I have 1 question to follow up.

    We are getting some compile time warnings and I suspect I have an ARM linker issue. Can you look at the attached screen shot and suggest the right way to remove these warning?

    www.dropbox.com/.../SNAG-0003.jpg

    Thanks J

    ......\main.c(146): warning: #223-D: function "nrf_delay_ms" declared implicitly nrf_delay_ms(100); ......\main.c(149): warning: #188-D: enumerated type mixed with another type nrf_gpio_cfg_sense_input(BSP_BUTTON_0, GPIO_PIN_CNF_PULL_Pullup, GPIO_PIN_CNF_SENSE_Low); ......\main.c(149): warning: #188-D: enumerated type mixed with another type nrf_gpio_cfg_sense_input(BSP_BUTTON_0, GPIO_PIN_CNF_PULL_Pullup, GPIO_PIN_CNF_SENSE_Low); ......\main.c(151): warning: #188-D: enumerated type mixed with another type nrf_gpio_cfg_sense_input(BSP_BUTTON_1, GPIO_PIN_CNF_PULL_Pullup, GPIO_PIN_CNF_SENSE_Low); ......\main.c(151): warning: #188-D: enumerated type mixed with another type nrf_gpio_cfg_sense_input(BSP_BUTTON_1, GPIO_PIN_CNF_PULL_Pullup, GPIO_PIN_CNF_SENSE_Low);

    ......\main.c: 5 warnings, 0 errors

  • "nrf_delay_ms" declared implicity: you need to include nrf_delay.h in the file:

    #include "nrf_delay.h`
    

    The enumerated type mixed with another type warning was my fault, use this code instead:

    nrf_gpio_cfg_sense_input(BSP_BUTTON_0, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
    

    It is exactly the same (see the definitions for NRF_GPIO_PIN_PULLUP and NRF_GPIO_PIN_SENSE_LOW).

Related