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

I can not add a new pass char to my services using with sd_ble_gatts_characteristic_add()

I used This char tutorial for this project. Basicly I added beacon advertising mod with a connection mode to  this project and I tried to changed minor and major of the device from the nRF Connect app. I also want to add a pass char to made a authorized system. But i am having a fatal error when i trying to add a pass char to my servis. Error is emerging at the our_service.c at line 209. I will be gratefull. Thank you!

My main.c:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* Copyright (c) 2014 - 2018, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

My our_service.c

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdint.h>
#include <string.h>
#include "nrf_gpio.h"
#include "our_service.h"
#include "ble_srv_common.h"
#include "app_error.h"
#include "lutfu_beacon.h"
#include "nrf_log.h"
#define MAJ_VAL_OFFSET_IN_BEACON_INFO 18
uint8_t index = 18;
uint8_t value[4] = {0,0,0,0};
uint32_t err_code; // Variable to hold return codes from library and softdevice functions
ble_uuid_t service_uuid;
//ble_gattc_handle_range_t ble_gattc_handle_range;
const ble_gattc_handle_range_t ble_gattc_handle_range ={ 0x0001 , 0xFFFF };
ble_uuid_t char_uuid; ///ble_uuid
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

My our_service.h

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef OUR_SERVICE_H__
#define OUR_SERVICE_H__
#include <stdint.h>
#include "ble.h"
#include "ble_srv_common.h"
#include "nrf_ble_gatt.h"
#include <nrf_sdh_ble.h>
// FROM_SERVICE_TUTORIAL: Defining 16-bit service and 128-bit base UUIDs
#define BLE_UUID_OUR_BASE_UUID {{0x23, 0xD1, 0x13, 0xEF, 0x5F, 0x78, 0x23, 0x15, 0xDE, 0xEF, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00}} // 128-bit base UUID
#define BLE_UUID_OUR_SERVICE_UUID 0xF00D // Just a random, but recognizable value
// ALREADY_DONE_FOR_YOU: Defining 16-bit characteristic UUID
#define BLE_UUID_OUR_CHARACTERISTC_UUID 0xBEEF // Just a random, but recognizable value
#define PASSWORD_CHAR 0x1001
// This structure contains various status information for our service.
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

My second header file lutfu_beacon.h:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef LUTFU_BEACON_H__
#define LUTFU_BEACON_H__
#define APP_BEACON_INFO_LENGTH 0x17 /**< Total length of information advertised by the Beacon. */
#define APP_ADV_DATA_LENGTH 0x15 /**< Length of manufacturer specific data in the advertisement. */
#define APP_DEVICE_TYPE 0x02 /**< 0x02 refers to Beacon. */
#define APP_MEASURED_RSSI 0xC3 /**< The Beacon's measured RSSI at 1 meter distance in dBm. */
#define APP_COMPANY_IDENTIFIER 0x0059 /**< Company identifier for Nordic Semiconductor ASA. as per www.bluetooth.org. */
#define APP_MAJOR_VALUE 0x01, 0x02 /**< Major value used to identify Beacons. */
#define APP_MINOR_VALUE 0x03, 0x04 /**< Minor value used to identify Beacons. */
#define APP_BEACON_UUID 0x01, 0x12, 0x23, 0x34, \
0x45, 0x56, 0x67, 0x78, \
0x89, 0x9a, 0xab, 0xbc, \
0xcd, 0xde, 0xef, 0xf0 /**< Proprietary UUID for Beacon. */
//uint8_t APP_MAJOR_VALUE[2] = {0x01, 0x02 };
//uint8_t APP_MINOR_VALUE[2] = {0x03, 0x04 };
static uint8_t m_beacon_info[APP_BEACON_INFO_LENGTH] = //< Information advertised by the Beacon.
{
APP_DEVICE_TYPE, // Manufacturer specific information. Specifies the device type in this
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Sorry for late answer srac, no response from the community, I would start configuring a project today to see what kind of error is generated and a possible fix/workaround for it.

  • when debug the code i saw the error code 7 but I Couldnt figure it out why.

  • You are adding characteristic to a service that does not exist.

    First add the service using sd_ble_gatts_service_add  and use the handle from it in sd_ble_gatts_characteristic_add

  • Actually i believe i am using sd_ble_gatts_service_add in line 332 at our_service.c 

  • missed to see that. I do not see anything wrong in the way you are adding your password characteristic. Even looking at it line by line many times seems to be ok. I need to try it out on my desk to see if i missed any obvious param initialization mistake.

1 2