Hello, I received my thingy52 and wanted just temperature ... I see that thingy is not using ESS - environmental sensing service so I tried to create my own. (I tried to use the BLE studio with no luck as persistant crashes on code generation avoid using that) I created device information service and battery service with related characteristics. I use SDK 13.1 based on the examples/ble_peripheral/ble_app_template on PCA10040 an Keil S132
My problem is now that the temperature characteristic in the environmental service is not showing up (in the NRF Connect App in my android)
What goes wrong? Is it related to the adopted profile that I use? How can I test myself the implementation? How can I generate code stubs from adopted profiles? - as BLE studio plugin crashes
Best Regards. Adib
here is my code / I also pushed the modified code to gitlab.com/.../environmento
#define BLE_UUID_ENVIRONMENTAL_SENSING_SERVICE 0x181A // environmental sensing service uuid
#define BLE_UUID_TEMPERATURE_CHAR 0x2A6E /**< temperature characteristic UUID. */
#define BLE_APPEARANCE_TEMPERATUR_SENSOR 1347 /**< Temperatur Sensor */
static uint32_t temperature_char_add(ble_ess_t * p_ess,
const ble_ess_init_t * p_ess_init)
{
NRF_LOG_INFO("temperature_char_add.\r\n");
ble_gatts_char_md_t char_md;
ble_gatts_attr_md_t cccd_md;
ble_gatts_attr_t attr_char_value;
ble_uuid_t ble_uuid;
ble_gatts_attr_md_t attr_md;
uint8_t encoded_initial_temperature[MAX_ESM_LEN];
memset(&cccd_md, 0, sizeof(cccd_md));
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
cccd_md.write_perm = p_ess_init->ess_temperature_attr_md.cccd_write_perm;
cccd_md.vloc = BLE_GATTS_VLOC_STACK;
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.read = 1;
char_md.char_props.write = 1;
char_md.char_props.notify = 1;
char_md.p_char_user_desc = NULL;
char_md.p_char_pf = NULL;
char_md.p_user_desc_md = NULL;
char_md.p_cccd_md = &cccd_md;
char_md.p_sccd_md = NULL;
BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_TEMPERATURE_CHAR);
memset(&attr_md, 0, sizeof(attr_md));
attr_md.read_perm = p_ess_init->ess_temperature_attr_md.read_perm;
attr_md.write_perm = p_ess_init->ess_temperature_attr_md.write_perm;
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth = 0;
attr_md.wr_auth = 0;
attr_md.vlen = 2;
memset(&attr_char_value, 0, sizeof(attr_char_value));
uint16_encode(123, encoded_initial_temperature);
attr_char_value.p_uuid = &ble_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = 2;
attr_char_value.init_offs = 0;
attr_char_value.max_len = 2;
attr_char_value.p_value = encoded_initial_temperature;
return sd_ble_gatts_characteristic_add(p_ess->service_handle,
&char_md,
&attr_char_value,
&p_ess->temperature_handles);
}
uint32_t ble_ess_init(ble_ess_t * p_ess, const ble_ess_init_t * p_ess_init)
{
uint32_t err_code;
ble_uuid_t ble_uuid;
// Initialize service structure
p_ess->evt_handler = p_ess_init->evt_handler;
p_ess->is_sensor_contact_supported = p_ess_init->is_sensor_contact_supported;
p_ess->conn_handle = BLE_CONN_HANDLE_INVALID;
p_ess->is_sensor_contact_detected = false;
p_ess->rr_interval_count = 0;
p_ess->max_hrm_len = MAX_ESM_LEN;
// Add service
BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_ENVIRONMENTAL_SENSING_SERVICE);
err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
&ble_uuid,
&p_ess->service_handle);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
// Add temperature measurement characteristic
err_code = temperature_char_add(p_ess, p_ess_init);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
return NRF_SUCCESS;
}
in main.c
static void services_init(void)
{
...
// environmental sense service
ble_ess_init_t ess_init;
memset(&ess_init, 0, sizeof(ess_init));
// Here the sec level for the Battery Service can be changed/increased.
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&ess_init.ess_temperature_attr_md.cccd_write_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&ess_init.ess_temperature_attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&ess_init.ess_temperature_attr_md.write_perm);
err_code = ble_ess_init(&m_ess, &ess_init);
}
in main.c
static void gap_params_init(void)
{
ret_code_t err_code;
ble_gap_conn_params_t gap_conn_params;
ble_gap_conn_sec_mode_t sec_mode;
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
err_code = sd_ble_gap_device_name_set(&sec_mode,
(const uint8_t *)DEVICE_NAME,
strlen(DEVICE_NAME));
APP_ERROR_CHECK(err_code);
/* YOUR_JOB: Use an appearance value matching the application's use case. */
err_code = sd_ble_gap_appearance_set(BLE_APPEARANCE_TEMPERATUR_SENSOR);
APP_ERROR_CHECK(err_code);
memset(&gap_conn_params, 0, sizeof(gap_conn_params));
gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL;
gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL;
gap_conn_params.slave_latency = SLAVE_LATENCY;
gap_conn_params.conn_sup_timeout = CONN_SUP_TIMEOUT;
err_code = sd_ble_gap_ppcp_set(&gap_conn_params);
APP_ERROR_CHECK(err_code);
}