cancel
Showing results for 
Search instead for 
Did you mean: 

Could not add new services to the BlueNRG

MVinn.1
Associate

@I'm new to BlueNRG. I have choosen BLE_SerialPort_Master_Slave project for my project. I need to connected with my Master(Mobile app) and receive data from the app.

I would like to create a new service which is similar to the existng Add_SerialPort_Service(). Here I have created a new service function named Add_Travel_Service(). The code inside the travel_service is same as serialport_service function. Here I just want to see, how to create a new service. I compile and flash the hex file, I never see a new service added.

I have increased the macros in SerialPort_config.h, however no use.

/* Default number of link */
#define MIN_NUM_LINK                10
/* Default number of GAP and GATT services */
#define DEFAULT_NUM_GATT_SERVICES   10
/* Default number of GAP and GATT attributes */
#define DEFAULT_NUM_GATT_ATTRIBUTES 9
 
/* Number of services requests from the serial port demo */
#define NUM_APP_GATT_SERVICES 10
 
/* Number of attributes requests from the serial port demo */
#define NUM_APP_GATT_ATTRIBUTES 10
 
/* Number of links needed for the demo: 1
 * Only 1 the default
 */
#define NUM_LINKS               (MIN_NUM_LINK)
 
/* Number of GATT attributes needed for the serial port demo. */
#define NUM_GATT_ATTRIBUTES     (DEFAULT_NUM_GATT_ATTRIBUTES + NUM_APP_GATT_ATTRIBUTES)
 
/* Number of GATT services needed for the serial port demo. */
#define NUM_GATT_SERVICES       (DEFAULT_NUM_GATT_SERVICES + NUM_APP_GATT_SERVICES)
 
/* Array size for the attribute value */
#define ATT_VALUE_ARRAY_SIZE    (44 + 80) //(GATT + GAP) = 44 + Serial Port  (TX (41) + RX (39) characteristics)   Services
 
/* Flash security database size */
#define FLASH_SEC_DB_SIZE       (0x400)
 
/* Flash server database size */
#define FLASH_SERVER_DB_SIZE    (0x400)
 
/* Set supported max value for ATT_MTU enabled by the application. Allowed values in range: [23:158] [New parameter added on BLE stack v2.x] */
#define MAX_ATT_MTU             (DEFAULT_ATT_MTU) 
 
/* Set supported max value for attribute size: it is the biggest attribute size enabled by the application */
#define MAX_ATT_SIZE            (20)

My code for the new service in gatt_db.c file is

uint8_t Add_SerialPort_Service(void)
{
  uint8_t ret;
 
  /*
  UUIDs:
  D973F2E0-B19E-11E2-9E96-0800200C9A66
  D973F2E1-B19E-11E2-9E96-0800200C9A66
  D973F2E2-B19E-11E2-9E96-0800200C9A66
  */
 
  const uint8_t uuid[16] = {0x66,0x9a,0x0c,0x20,0x00,0x08,0x96,0x9e,0xe2,0x11,0x9e,0xb1,0xe0,0xf2,0x73,0xd9};
  const uint8_t charUuidTX[16] = {0x66,0x9a,0x0c,0x20,0x00,0x08,0x96,0x9e,0xe2,0x11,0x9e,0xb1,0xe1,0xf2,0x73,0xd9};
  const uint8_t charUuidRX[16] = {0x66,0x9a,0x0c,0x20,0x00,0x08,0x96,0x9e,0xe2,0x11,0x9e,0xb1,0xe2,0xf2,0x73,0xd9};
  
  const uint8_t uuid3[16] = {0x88,0x20,0xc4,0x80, 0xe4,0x8b, 0x11,0xe2, 0x84,0x0b, 0x00,0x02,0xa5,0xd5,0xc5,0x1b};
 
  Osal_MemCpy(&service_uuid.Service_UUID_128, uuid, 16);
  
  ret = aci_gatt_add_service(UUID_TYPE_128, &service_uuid, PRIMARY_SERVICE, 6, &SerialPortServHandle);
  if (ret != BLE_STATUS_SUCCESS) goto fail;    
 
  Osal_MemCpy(&char_uuid.Char_UUID_128, charUuidTX, 16);
  ret =  aci_gatt_add_char(SerialPortServHandle, UUID_TYPE_128, &char_uuid, 20, CHAR_PROP_NOTIFY, ATTR_PERMISSION_NONE, 0,
                16, 1, &TXCharHandle);
  if (ret != BLE_STATUS_SUCCESS) goto fail;
 
  Osal_MemCpy(&char_uuid.Char_UUID_128, charUuidRX, 16);
  ret =  aci_gatt_add_char(SerialPortServHandle, UUID_TYPE_128, &char_uuid, 20, CHAR_PROP_WRITE|CHAR_PROP_WRITE_WITHOUT_RESP, ATTR_PERMISSION_NONE, GATT_NOTIFY_ATTRIBUTE_WRITE,
                16, 1, &RXCharHandle);
  if (ret != BLE_STATUS_SUCCESS) goto fail;
  printf("Serial Port Service added.\nTX Char Handle %04X, RX Char Handle %04X\n", TXCharHandle, RXCharHandle);
  return BLE_STATUS_SUCCESS; 
 
fail:
  printf("Error while adding Serial Port service.\n");
  return BLE_STATUS_ERROR ;
}
 
 
tBleStatus Add_Travel_Service(void)
{
  tBleStatus ret;
   const uint8_t uuid1[16] = {0x66,0x82,0x1a,0x40, 0xe4,0x77, 0x11,0xe2, 0x82,0xd0, 0x00,0x02,0xa5,0xd5,0xc5,0x1b};
  const uint8_t uuid2[16] = {0x77,0x2e,0x55,0x20, 0xe4,0x77, 0x11,0xe2, 0xa9,0xe3, 0x00,0x02,0xa5,0xd5,0xc5,0x1b};
  const uint8_t uuid3[16] = {0x88,0x20,0xc4,0x80, 0xe4,0x8b, 0x11,0xe2, 0x84,0x0b, 0x00,0x02,0xa5,0xd5,0xc5,0x1b};
  
    
  Osal_MemCpy(&service_uuid.Service_UUID_128, uuid1, 16);
  
  ret = aci_gatt_add_service(UUID_TYPE_128, &service_uuid, PRIMARY_SERVICE, 6, &SerialPortServHandle);
  if (ret != BLE_STATUS_SUCCESS) goto fail;    
 
  Osal_MemCpy(&char_uuid.Char_UUID_128, uuid2, 16);
  ret =  aci_gatt_add_char(SerialPortServHandle, UUID_TYPE_128, &char_uuid, 20, CHAR_PROP_NOTIFY, ATTR_PERMISSION_NONE, 0,
                16, 1, &TXCharHandle);
  if (ret != BLE_STATUS_SUCCESS) goto fail;
 
  Osal_MemCpy(&char_uuid.Char_UUID_128, uuid3, 16);
  ret =  aci_gatt_add_char(SerialPortServHandle, UUID_TYPE_128, &char_uuid, 20, CHAR_PROP_WRITE|CHAR_PROP_WRITE_WITHOUT_RESP, ATTR_PERMISSION_NONE, GATT_NOTIFY_ATTRIBUTE_WRITE,
                16, 1, &RXCharHandle);
  if (ret != BLE_STATUS_SUCCESS) goto fail;
 
  return BLE_STATUS_SUCCESS; 
 
fail:
  printf("Error while adding new service.\n");
  return BLE_STATUS_ERROR ;

whenever, I change the macros, I dont even find my device (undiscoverable). Can some one help me out how to add new service. Also I have edited the SerialPort_DeviceInit function in the seial_port.c file like below

uint8_t SerialPort_DeviceInit(void)
{
  uint8_t ret;
  uint16_t service_handle, dev_name_char_handle, appearance_char_handle;
  
  /* Setup the device address */
  Setup_DeviceAddress();
 
  /* Set the TX power to -2 dBm */
  aci_hal_set_tx_power_level(1, 4);
 
  /* GATT Init */
  ret = aci_gatt_init();    
  if(ret != BLE_STATUS_SUCCESS) {
      PRINTF("GATT_Init failed: 0x%02x\n", ret);
      return ret;
  }
 
  /* GAP Init */
  ret = aci_gap_init(GAP_CENTRAL_ROLE|GAP_PERIPHERAL_ROLE, 0,0x07, &service_handle, 
                     &dev_name_char_handle, &appearance_char_handle);
  if(ret != BLE_STATUS_SUCCESS) {
    PRINTF("GAP_Init failed: 0x%02x\n", ret);
    return ret;
  }
 
  // Add Device Service & Characteristics 
  ret = Add_SerialPort_Service();
  if(ret != BLE_STATUS_SUCCESS) {
    PRINTF("Error while adding service: 0x%02x\n", ret);
    return ret;
  }
  
  /*ret = Add_Travel_Service();
  if(ret != BLE_STATUS_SUCCESS) {
    PRINTF("Error while adding service: 0x%02x\n", ret);
    return ret;
  }*/
  
 
  /* Reset the discovery context */
  Reset_DiscoveryContext();
 
  return BLE_STATUS_SUCCESS;
}

Thank you.

0 REPLIES 0