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

MCP doesnt recieve Sensor data

I have a project which measures temperature and humidity. After measurement the data should be send trough BLE.

I have one service for the sensor and two characteristics for humidity and temperature. On the MCP I see the service and the two characteristics.

The problem is, when I try to read the values of the sensor over MCP, I will always get 0 as value.

Here the set up for temperature:

Sensor.h:

uint32_t ble_fridge_send_temp(ble_fridge_t * p_fridge, uint8_t temp_value);

Sensor.c:

static uint32_t temp_char_add(ble_fridge_t * p_fridge, const ble_fridge_init_t * p_fridge_init)
{
   ble_gatts_char_md_t char_md;
   ble_gatts_attr_t    attr_char_value;
   ble_uuid_t          ble_uuid;
   ble_gatts_attr_md_t attr_md;

   memset(&char_md, 0, sizeof(char_md));

   char_md.char_props.read   = 1;
   char_md.char_props.write  = 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         = NULL;
   char_md.p_sccd_md         = NULL;

   ble_uuid.type = p_fridge->uuid_type;
   ble_uuid.uuid = FRIDGE_UUID_TEMP;

   memset(&attr_md, 0, sizeof(attr_md));

   BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
   BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
   attr_md.vloc       = BLE_GATTS_VLOC_STACK;
   attr_md.rd_auth    = 0;
   attr_md.wr_auth    = 0;
   attr_md.vlen       = 0;

   memset(&attr_char_value, 0, sizeof(attr_char_value));

   attr_char_value.p_uuid       = &ble_uuid;
   attr_char_value.p_attr_md    = &attr_md;
   attr_char_value.init_len     = sizeof(uint8_t);
   attr_char_value.init_offs    = 0;
   attr_char_value.max_len      = sizeof(uint8_t);
   attr_char_value.p_value      = NULL;

   return sd_ble_gatts_characteristic_add(p_fridge->service_handle, &char_md,
                                           &attr_char_value,
                                           &p_fridge->temp_char_handles);
}




uint32_t ble_fridge_send_temp(ble_fridge_t * p_fridge, uint8_t temp_value)
{
    ble_gatts_hvx_params_t hvx_params;

if (p_fridge == NULL)
{
    return NRF_ERROR_NULL;
}

if ((p_fridge->conn_handle == BLE_CONN_HANDLE_INVALID) || (!p_fridge->is_notification_enabled))
{
    return NRF_ERROR_INVALID_STATE;
}

memset(&hvx_params, 0, sizeof(hvx_params));

hvx_params.handle = p_fridge->temp_char_handles.value_handle;
hvx_params.p_data = &temp_value;
hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;

return sd_ble_gatts_hvx(p_fridge->conn_handle, &hvx_params);
} 

main.c:

float temperature;

static void temp_write_handler(ble_fridge_t *p_fridge, uint8_t temperature_value)
{
uint32_t err_code;

err_code = ble_fridge_send_temp(&m_fridge,temperature);

APP_ERROR_CHECK(err_code);
}

I tried it also with sd_ble_gatts_value_set:

Sensor.c

uint32_t ble_fridge_send_temp(ble_fridge_t * p_fridge, uint8_t temp_value)
{
  ble_gatts_value_t gatts_value;

  memset(&gatts_value, 0, sizeof(gatts_value));


  gatts_value.len		= sizeof(uint8_t);
  gatts_value.offset	= 0;
  gatts_value.p_value	= &temp_value;

  return sd_ble_gatts_value_set(p_fridge->conn_handle, p_fridge->temp_char_handles.value_handle, &gatts_value);
}

Why ble_fridge_send_temp(); will not send the value of the temperature?

From the MCP:

-ReadAttributeValue(13)

-Recieved Read Response, handle: 0x000B, value (0x): 01

What is missing/wrong ?

Parents Reply Children
No Data
Related