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

Send struct of data

Hi all,

If I want to send a table that contains a structure in each of his cases using sd_ble_gatts_hvx(), can I get it ?
Knowing that the second parametre of sd_ble_gatts_hvx() contains a ble_gatts_hvx_params_t variable, which has the uint8* p_data attribute.

Regards,

mohBOSS.

Parents
  • The short answer is yes, you can transfer anything you want.

    The BLE transport only knows it is transporting bytes from peripheral to central or vice versa. It doesn't know or care what those bytes represent, they can be anything you want them to be. There are limitations such as the need to fragment things over 20 bytes in size, the speed at which you can do the transfer, and things like that, but there is nothing to prevent you from transferring anything you want to.

  • typedef struct

    { int8_t rssi; ble_gap_addr_t advertisor_addr; }rssi_mac;

    uint32_t ble_rssi_mac_send(ble_rssi_mac_t * p_lbs, rssi_mac data_to_send) {

    ble_gatts_hvx_params_t params;
    uint16_t len = sizeof(data_to_send);
    
    memset(&params, 0, sizeof(params));
    params.type = BLE_GATT_HVX_NOTIFICATION;
    params.handle = p_lbs->rssi_mac_char_handles.value_handle;
    params.p_data = &data_to_send;
    params.p_len = &len;
    
    return sd_ble_gatts_hvx(p_lbs->conn_handle, &params); 
    

    }

    I was wrong, it's not an error but a warning about non compatible types.

Reply
  • typedef struct

    { int8_t rssi; ble_gap_addr_t advertisor_addr; }rssi_mac;

    uint32_t ble_rssi_mac_send(ble_rssi_mac_t * p_lbs, rssi_mac data_to_send) {

    ble_gatts_hvx_params_t params;
    uint16_t len = sizeof(data_to_send);
    
    memset(&params, 0, sizeof(params));
    params.type = BLE_GATT_HVX_NOTIFICATION;
    params.handle = p_lbs->rssi_mac_char_handles.value_handle;
    params.p_data = &data_to_send;
    params.p_len = &len;
    
    return sd_ble_gatts_hvx(p_lbs->conn_handle, &params); 
    

    }

    I was wrong, it's not an error but a warning about non compatible types.

Children
No Data
Related