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

What is the API call to send data from the nRF51822 device to the iOS/Android master?

Hi all,

When I receive data from the phone app, I do it via this service handler (and it works):

err_code = ble_services_init(&my_device_service, ble_receive_handler);
APP_ERROR_CHECK(err_code);

Now I would like to set something up to send data up to the master. How do I do it?

Thanks, Gil

Parents
  • I'd recommend you to have a look at nAN-36, which shows a basic application doing two-way communication. Code that works with SDK 5.1.0 and S110 version 6.0.0 is available on GitHub here.

    In short, the function call sd_ble_gatts_hvx() will send data from a GATT Server to a GATT Client, but you can do this only on a characteristic that has the notification or indicate property, and the GATT Client must have enabled notifications by writing to the CCCD for this to happen. You must therefore make sure to set up a characteristic with this property, and make sure that whatever Central device you're testing with enabled this before you try to send data. If the CCCD is not enabled when you try to send a notification/indication, you'll get NRF_ERROR_INVALID_STATE back, as noted in the header file comment in ble_gatts.h.

Reply
  • I'd recommend you to have a look at nAN-36, which shows a basic application doing two-way communication. Code that works with SDK 5.1.0 and S110 version 6.0.0 is available on GitHub here.

    In short, the function call sd_ble_gatts_hvx() will send data from a GATT Server to a GATT Client, but you can do this only on a characteristic that has the notification or indicate property, and the GATT Client must have enabled notifications by writing to the CCCD for this to happen. You must therefore make sure to set up a characteristic with this property, and make sure that whatever Central device you're testing with enabled this before you try to send data. If the CCCD is not enabled when you try to send a notification/indication, you'll get NRF_ERROR_INVALID_STATE back, as noted in the header file comment in ble_gatts.h.

Children
Related