Hi, I am trying to create a custom_service for my application.
I am using nRF52832 SDK_16
SES
I want to create the BLE_SERVICES
which has send characteristics and read characteristics , like multiple characteristics in single SERVICES
1. First characteristics - need to send INT value
2. Second characteristics - need to send STRING value / TEXT
3. Third characteristics - need to receive INT value
4. Fourth characteristics - need to receive STRING value / TEXT
this is my case
I have refereed nRF THINGY52 .
there some custom services like TES, TMS, TCS
While checking nRF THINGY 52 with the nRF CONNECT and nRF THINGY mobile app
I came with few queries
1. WRITE NOT PERMIT
I have look custom services in thingy52 . in that every service has configuration characteristics. that can be changed via nRF thingy mobile app
and while using nRF CONNECT app not able to write . is there any format i need to work on this configuration
what is work of this functions
on_write
static void on_write(ble_tes_t * p_tes, ble_evt_t * p_ble_evt)
{
ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
if ( (p_evt_write->handle == p_tes->temperature_handles.cccd_handle) &&
(p_evt_write->len == 2) )
{
bool notif_enabled;
notif_enabled = ble_srv_is_notification_enabled(p_evt_write->data);
if (p_tes->is_temperature_notif_enabled != notif_enabled)
{
p_tes->is_temperature_notif_enabled = notif_enabled;
if (p_tes->evt_handler != NULL)
{
p_tes->evt_handler(p_tes, BLE_TES_EVT_NOTIF_TEMPERATURE, p_evt_write->data, p_evt_write->len);
}
}
}
else if ( (p_evt_write->handle == p_tes->pressure_handles.cccd_handle) &&
(p_evt_write->len == 2) )
{
bool notif_enabled;
notif_enabled = ble_srv_is_notification_enabled(p_evt_write->data);
if (p_tes->is_pressure_notif_enabled != notif_enabled)
{
p_tes->is_pressure_notif_enabled = notif_enabled;
if (p_tes->evt_handler != NULL)
{
p_tes->evt_handler(p_tes, BLE_TES_EVT_NOTIF_PRESSURE, p_evt_write->data, p_evt_write->len);
}
}
}
else if ( (p_evt_write->handle == p_tes->humidity_handles.cccd_handle) &&
(p_evt_write->len == 2) )
{
bool notif_enabled;
notif_enabled = ble_srv_is_notification_enabled(p_evt_write->data);
if (notif_enabled != p_tes->is_humidity_notif_enabled)
{
p_tes->is_humidity_notif_enabled = notif_enabled;
if (p_tes->evt_handler != NULL)
{
p_tes->evt_handler(p_tes, BLE_TES_EVT_NOTIF_HUMIDITY, p_evt_write->data, p_evt_write->len);
}
}
}
else if ( (p_evt_write->handle == p_tes->gas_handles.cccd_handle) &&
(p_evt_write->len == 2) )
{
bool notif_enabled;
notif_enabled = ble_srv_is_notification_enabled(p_evt_write->data);
if (notif_enabled != p_tes->is_gas_notif_enabled)
{
p_tes->is_gas_notif_enabled = notif_enabled;
if (p_tes->evt_handler != NULL)
{
p_tes->evt_handler(p_tes, BLE_TES_EVT_NOTIF_GAS, p_evt_write->data, p_evt_write->len);
}
}
}
else if ( (p_evt_write->handle == p_tes->color_handles.cccd_handle) &&
(p_evt_write->len == 2) )
{
bool notif_enabled;
notif_enabled = ble_srv_is_notification_enabled(p_evt_write->data);
if (notif_enabled != p_tes->is_color_notif_enabled)
{
p_tes->is_color_notif_enabled = notif_enabled;
if (p_tes->evt_handler != NULL)
{
p_tes->evt_handler(p_tes, BLE_TES_EVT_NOTIF_COLOR, p_evt_write->data, p_evt_write->len);
}
}
}
else
{
// Do Nothing. This event is not relevant for this service.
}
}
on_authorize_req
static void on_authorize_req(ble_tes_t * p_tes, ble_evt_t * p_ble_evt)
{
ble_gatts_evt_rw_authorize_request_t * p_evt_rw_authorize_request = &p_ble_evt->evt.gatts_evt.params.authorize_request;
uint32_t err_code;
if (p_evt_rw_authorize_request->type == BLE_GATTS_AUTHORIZE_TYPE_WRITE)
{
if (p_evt_rw_authorize_request->request.write.handle == p_tes->config_handles.value_handle)
{
ble_gatts_rw_authorize_reply_params_t rw_authorize_reply;
bool valid_data = true;
// Check for valid data
if(p_evt_rw_authorize_request->request.write.len != sizeof(ble_tes_config_t))
{
valid_data = false;
}
else
{
ble_tes_config_t * p_config = (ble_tes_config_t *)p_evt_rw_authorize_request->request.write.data;
if ( (p_config->temperature_interval_ms < BLE_TES_CONFIG_TEMPERATURE_INT_MIN) ||
(p_config->temperature_interval_ms > BLE_TES_CONFIG_TEMPERATURE_INT_MAX) ||
(p_config->pressure_interval_ms < BLE_TES_CONFIG_PRESSURE_INT_MIN) ||
(p_config->pressure_interval_ms > BLE_TES_CONFIG_PRESSURE_INT_MAX) ||
(p_config->humidity_interval_ms < BLE_TES_CONFIG_HUMIDITY_INT_MIN) ||
(p_config->humidity_interval_ms > BLE_TES_CONFIG_HUMIDITY_INT_MAX) ||
(p_config->color_interval_ms < BLE_TES_CONFIG_COLOR_INT_MIN) ||
(p_config->color_interval_ms > BLE_TES_CONFIG_COLOR_INT_MAX) ||
(p_config->gas_interval_mode < BLE_TES_CONFIG_GAS_MODE_MIN) ||
((int)p_config->gas_interval_mode > (int)BLE_TES_CONFIG_GAS_MODE_MAX))
{
valid_data = false;
}
}
rw_authorize_reply.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE;
if (valid_data)
{
rw_authorize_reply.params.write.update = 1;
rw_authorize_reply.params.write.gatt_status = BLE_GATT_STATUS_SUCCESS;
rw_authorize_reply.params.write.p_data = p_evt_rw_authorize_request->request.write.data;
rw_authorize_reply.params.write.len = p_evt_rw_authorize_request->request.write.len;
rw_authorize_reply.params.write.offset = p_evt_rw_authorize_request->request.write.offset;
}
else
{
rw_authorize_reply.params.write.update = 0;
rw_authorize_reply.params.write.gatt_status = BLE_GATT_STATUS_ATTERR_WRITE_NOT_PERMITTED;
}
err_code = sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.gatts_evt.conn_handle,
&rw_authorize_reply);
APP_ERROR_CHECK(err_code);
if ( valid_data && (p_tes->evt_handler != NULL))
{
p_tes->evt_handler(p_tes,
BLE_TES_EVT_CONFIG_RECEIVED,
p_evt_rw_authorize_request->request.write.data,
p_evt_rw_authorize_request->request.write.len);
}
}
}
}
and on_connect , on_disconnect :
means is that particular service will work after the ble is connected to the host . and stops after it disconnect ?
static void on_connect(ble_tes_t * p_tes, ble_evt_t * p_ble_evt) { p_tes->conn_handle = p_ble_evt->evt.gap_evt.conn_handle; } static void on_disconnect(ble_tes_t * p_tes, ble_evt_t * p_ble_evt) { UNUSED_PARAMETER(p_ble_evt); p_tes->conn_handle = BLE_CONN_HANDLE_INVALID; }
2. Is THINGY has memory
while i tried to changed the value of the temperature interval update to 1000ms in thingy app . and it updated and works even after power off .
IS THINGY use external memory like EEPROM
3. HOW TO NAME CUSTOM SERVICES AND CHARACTERISTICS
while creating any custom service it shows unknown services
but in THINGY device in nRF CONNECT app is shows the name . how to name to custom services