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

Sample code to add a Custom BLE Service on nRF82540DK using nRF Connect SDK

Hi nRF support team,

I am trying to add a new Custom Service and Characteristic an application on nRF82540 development kit using the nRF Connect SDK.

Can you please let me know the instructions on how to add a custom service and characteristic? It would be great if you can share the sample code to create a new custom BLE service.

Regards,

Kalyan

Parents
  • Hello,

    I assume you refer to the nRF52840, just to clear any misunderstandings Slight smile
    We don't have much other than the examples in the folder NCS\nrf\samples\bluetooth

    I suggest you check out the example peripheral_uart. This is an example that uses a custom BLE service (custom meaning that this service is not a standardized BLE service).



    In main.c you can see that the nus.h file is included:

    #include <bluetooth/services/nus.h>
    This file is located in NCS\nrf\include\bluetooth\services\nus.h
    The complimentary .c file is nus.c in NCS\nrf\subsys\bluetooth\services\nus.c

    The "main thread" in this example is the "led_blink_thread". There you can see the
    err = bt_enable(NULL);
    which enables the BLE stack, and:
    err = bt_gatt_nus_init(&nus_cb);
    which initializes the nus (Nordic UART Service), which is the custom BLE service in this example.

    Actually, it is not entirely true that this function intializes this service, but you can look at the nuc.c/h to see how to set up a service. It is the macros in nuc.c:
    /* UART Service Declaration */
    BT_GATT_SERVICE_DEFINE(nus_svc,
    BT_GATT_PRIMARY_SERVICE(BT_UUID_NUS_SERVICE),
    	BT_GATT_CHARACTERISTIC(BT_UUID_NUS_TX,
    			       BT_GATT_CHRC_NOTIFY,
    			       BT_GATT_PERM_READ,
    			       NULL, NULL, NULL),
    	BT_GATT_CCC(NULL, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
    	BT_GATT_CHARACTERISTIC(BT_UUID_NUS_RX,
    			       BT_GATT_CHRC_WRITE |
    			       BT_GATT_CHRC_WRITE_WITHOUT_RESP,
    			       BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
    			       NULL, on_receive, NULL),
    );
    Use this as a starting point, and let me know if you get stuck.
    Best regards,
    Edvin
Reply
  • Hello,

    I assume you refer to the nRF52840, just to clear any misunderstandings Slight smile
    We don't have much other than the examples in the folder NCS\nrf\samples\bluetooth

    I suggest you check out the example peripheral_uart. This is an example that uses a custom BLE service (custom meaning that this service is not a standardized BLE service).



    In main.c you can see that the nus.h file is included:

    #include <bluetooth/services/nus.h>
    This file is located in NCS\nrf\include\bluetooth\services\nus.h
    The complimentary .c file is nus.c in NCS\nrf\subsys\bluetooth\services\nus.c

    The "main thread" in this example is the "led_blink_thread". There you can see the
    err = bt_enable(NULL);
    which enables the BLE stack, and:
    err = bt_gatt_nus_init(&nus_cb);
    which initializes the nus (Nordic UART Service), which is the custom BLE service in this example.

    Actually, it is not entirely true that this function intializes this service, but you can look at the nuc.c/h to see how to set up a service. It is the macros in nuc.c:
    /* UART Service Declaration */
    BT_GATT_SERVICE_DEFINE(nus_svc,
    BT_GATT_PRIMARY_SERVICE(BT_UUID_NUS_SERVICE),
    	BT_GATT_CHARACTERISTIC(BT_UUID_NUS_TX,
    			       BT_GATT_CHRC_NOTIFY,
    			       BT_GATT_PERM_READ,
    			       NULL, NULL, NULL),
    	BT_GATT_CCC(NULL, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
    	BT_GATT_CHARACTERISTIC(BT_UUID_NUS_RX,
    			       BT_GATT_CHRC_WRITE |
    			       BT_GATT_CHRC_WRITE_WITHOUT_RESP,
    			       BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
    			       NULL, on_receive, NULL),
    );
    Use this as a starting point, and let me know if you get stuck.
    Best regards,
    Edvin
Children
Related