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

Control a function by button and/or BLE (e.g. iOS App)

Hi,

i started writing a BLE application with the nRF51822 but i seam to have some trouble understanding BLE/S110. My application will consist of a button and an actor connected to the nRF51822 and a smartphone app. I would like to create a characteristic in my service (called ACS - actor control service) which I would like to contain all this in one variable. Both should be able to control different modes of the actor like ON/50%/OFF. And for example when I turn the actor ON using the button it should be notify the app of this event. I read AN-36 and as far as I understand the button and the led are either writeable or readable parameters. But what I don't want is using several different vairables/characteristics to do that one task (like in AN36 for the led (write from smartphone to led) and button(write button status from nRF51822 to app)).

My questions are: Is this possible like I discribed and how? Can you maybe recommend examples to look at and/or any docs to read?

Thanks in advance.

Regards Marius

Parents
  • I'm not quite sure I understand why you absolutely want to combine them, and it sounds as if what you want is more or less exactly what's covered by nAN-36 and the code here. There isn't really any problems with notifying the phone about a button press, but also using it to trigger something locally on your device. It should also be pretty easy to extens the LED state to instead write a number or something, and then using that number to control whatever action you want to happen on your device (i.e. with 0 being off, some other value being fully on, and whatever value in between being a percentage or similar).

    If it is so that the local button directly controls the value, and you want to know the value also on the phone, I'd recommend to instead just remove the button characteristic, and just notify the value when it changes.

    Also, for completeness, there isn't really anything stopping you from having a characteristic that's both readable, writeable and notifiable. You can do this by just setting all the needed properties in the ble_gatts_char_md_t struct when initializing the characteristic. You can then both do notifications with sd_ble_gatts_hvx(), set the value to be read with sd_ble_gatts_value_set() or receive writes over-the-air.

Reply
  • I'm not quite sure I understand why you absolutely want to combine them, and it sounds as if what you want is more or less exactly what's covered by nAN-36 and the code here. There isn't really any problems with notifying the phone about a button press, but also using it to trigger something locally on your device. It should also be pretty easy to extens the LED state to instead write a number or something, and then using that number to control whatever action you want to happen on your device (i.e. with 0 being off, some other value being fully on, and whatever value in between being a percentage or similar).

    If it is so that the local button directly controls the value, and you want to know the value also on the phone, I'd recommend to instead just remove the button characteristic, and just notify the value when it changes.

    Also, for completeness, there isn't really anything stopping you from having a characteristic that's both readable, writeable and notifiable. You can do this by just setting all the needed properties in the ble_gatts_char_md_t struct when initializing the characteristic. You can then both do notifications with sd_ble_gatts_hvx(), set the value to be read with sd_ble_gatts_value_set() or receive writes over-the-air.

Children
No Data
Related