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

How to poll data from sensor using an android app nrf52 nordic

I am developing on the nRF52 boards with a capacitive sensor. I followed the tutorial in this link and created a custom service with 3 read characteristics. I am able to use the nordic connect app to read the values in those 3 characteristics continuously. I am also able to modify the nrf uart app to read those values and print it out on the phone continuously when I connect to the nrf52.

However, what I want to do now is polling data from the nrf52 when I press a button on the android app. For example, my nrf52 will be in sleep mode, then when I connect it to the phone and pressed a button, then the nrf52 will wake up and send some data over to the phone for a few seconds then nrf52 goes back to sleep again.

I'm having trouble on how to set up my application so that it will only send data when I press a button. Any suggestion on how to implement this would be appreciated it.

Thank you

  • Could you be more precise in your middle paragraph? By "uC" you mean nRF52? If it sleeps how does it wake up? Then how exactly BLE connection happens? Once you have BLE connection then nRF52 cannot be OFF so you can "pull" by GATT methods whatever you need.

    I believe the problem you have is that you changed architecture to push/pull (GATT Write/Read) while basically all BLE GATT applications use push/async push by GATT Write/Notify methods. So if you now realize all advantages of that approach simply return from "Read" to "Notify" as it was in original Nordic BLE UART Service examples.

  • Cool. So how exactly do you envision that "my nrf52 will be in sleep mode, then when I connect it to the phone and pressed a button, then the nrf52 will wake up and send some data over to the phone"? nRF5x chips have only two power saving states/modes: first is SLEEP (POWER ON) which is basically used every time MCU doesn't need to do any processing. However during this state all HW peripherals can be active so e.g. RTC can run and wake MCU for all scheduled operations such as radio events. So in this state you can have BLE active - in pretty much any state including connected link. The second power saving mode is POWER OFF. In this only external event such as GPIO high/low change or NFC field sense can wake up MCU and it will treat it basically as reset (so you need to initiate all the things including BLE stack). Obviously this is not usable for your story.

  • Thanks a lot for your answer, I'm still trying to figure out how I am going to implement everything. So is there a way to send a signal from the phone to the nrf52 board to wake up the board?

    Also, On the nrf connect app, there is a download button on the side of the read characteristic and each time I hit the download button, it will update a new value from the capcitive sensor reading. Basically, I want to implement a button like that.

    On top of that button, I want the nrf52 board to read data from the capacitive sensor for a few seconds when I press the button. when the button is not pressed then the nrf52 board and the capacitive sensor should be in sleep mode.

    Does this clarify more on my questions?

  • What do you call "sleep" and what do you mean by wake-up? If you are fine with standard operation of nRF5x (= it runs some scheduled operation by RTC timer - either in BLE stack or in your app - and otherwise it sleeps) then simply keep it advertising, once you want to connect from phone you can do so, as soon as connection link is established you can directly start your procedure with capacitive sensor (or whatever else) and as soon as you have any data then nRF5x sends them immediately to the phone as GATT Notify or Indicate, no need to pulling it out of nRF5x by reads (basically no one is doing it because there is no reason). If you want to do it differently (= read instead of notify) then you certainly can. Maybe can you formulate shorter and technically clearer question(s) so someone will be able to answer them?:)

Related