Hello,
I am sending a float in my BLE payload, using nRF Connect I can sniff and see that the value is being sending, it changes every time.
However, in my central when collecting the data, this value seems always to be zero, so I am doing something wrong with the encoding but I cannot point out what. I see on the logs that the connection, discovery, binding goes fine.
Any hint on what I am doing wrong?
The called function to parse the hvx incoming data (central)
static void on_hvx(ble_c_t * p_ble_c, const ble_evt_t * p_ble_evt)
{
// Check if the event is on the link for this instance
if (p_ble_c->conn_handle != p_ble_evt->evt.gattc_evt.conn_handle)
{
NRF_LOG_DEBUG("received HVX on link 0x%x, not associated to this instance, ignore\r\n",
p_ble_evt->evt.gattc_evt.conn_handle);
return;
}
NRF_LOG_DEBUG("received HVX on handle 0x%x, m_handle 0x%x\r\n",
p_ble_evt->evt.gattc_evt.paras.hvx.handle,
p_ble_c->peer_db.m_handle);
// Check if this is a notification.
if (p_ble_evt->evt.gattc_evt.paras.hvx.handle == p_ble_c->peer_db.m_handle)
{
ble_c_evt_t ble_c_evt;
uint32_t index = 0;
ble_c_evt.evt_type = BLE_C_EVT_m_NOTIFICATION;
ble_c_evt.conn_handle = p_ble_c->conn_handle;
printf("received length %d \r\n",(p_ble_evt->evt.gattc_evt.paras.hvx.len));
printf("p_ble_evt->evt.gattc_evt.paras.hvx.data 0 %f \r\n",p_ble_evt->evt.gattc_evt.paras.hvx.data[0]);
printf("p_ble_evt->evt.gattc_evt.paras.hvx.data 1 %f \r\n",p_ble_evt->evt.gattc_evt.paras.hvx.data[1]);
printf("p_ble_evt->evt.gattc_evt.paras.hvx.data 2 %f \r\n",p_ble_evt->evt.gattc_evt.paras.hvx.data[2]);
printf("p_ble_evt->evt.gattc_evt.paras.hvx.data 3 %f \r\n",p_ble_evt->evt.gattc_evt.paras.hvx.data[3]);
printf("p_ble_evt->evt.gattc_evt.paras.hvx.data 4 %f \r\n",p_ble_evt->evt.gattc_evt.paras.hvx.data[4]);
ble_c_evt.paras.hr.m_value = p_ble_evt->evt.gattc_evt.paras.hvx.data[1];
printf("m_value %f \r\n",ble_c_evt.paras.hr.m_value);
NRF_LOG_RAW_HEXDUP_INFO("the Hvx.data",*p_ble_evt->evt.gattc_evt.paras.hvx.data)
p_ble_c->evt_handler(p_ble_c, &ble_c_evt);
}
}
The function that sends dat from the pheripherial
uint32_t ble_msr_send(ble_msr_t * p_ms, float measurement)
{
uint32_t err_code;
// Send value if connected and notifying
if (p_ms->conn_handle != BLE_CONN_HANDLE_INVALID)
{
uint16_t len;
uint16_t hvx_len;
ble_gatts_hvx_params_t hvx_params;
len = sizeof(measurement);
hvx_len = len;
memset(&hvx_params, 0, sizeof(hvx_params));
hvx_params.handle = p_ms->hrm_handles.value_handle;
hvx_params.type = BLE_GATT_HVX_NOTIFICATION;
hvx_params.offset = 0;
hvx_params.p_len = &hvx_len;
hvx_params.p_data = (uint8_t *)& measurement;
err_code = sd_ble_gatts_hvx(p_ms->conn_handle, &hvx_params);
if ((err_code == NRF_SUCCESS) && (hvx_len != len))
{
err_code = NRF_ERROR_DATA_SIZE;
}
}
else
{
err_code = NRF_ERROR_INVALID_STATE;
}
return err_code;
}