I am developing an accelerometer, which will send the data via Bluetooth to a tablet. I am using the nrf52840 and to program it I am using de nrfConnect SDK. I am sending an 80 position buffer each position of the buffer has 3 int8 inside. The data (with my configurations) is being sent 10 times per second. If my calculations are right: 10 * 80 * 3 = 2400 bytes per second, that is only .0192 Mbps.
I am updating the connection parameters (PHY, data_length, and MTU) when a connection happens, and the parameteres are being updated successfully. I also tried increasing the buffer size, yet I can not increase the size of the buffer, because if I set it to 83, it starts sending more data than capable. Maybe the way i am sending the data is not optimal.
I would appreciate any help!
I will leave some parts of the code here:
void send_data_thread(void)
{
while(1){
/* Simulate data */
simulate_data();
pack_data(sensor_valueX,sensor_valueY,sensor_valueZ);
}
}
static void simulate_data(void){
simulate_dataX();
simulate_dataY();
simulate_dataZ();
}
static void pack_data(uint8_t x, uint8_t y, uint8_t z){
buffer[buffer_index].x = x;
buffer[buffer_index].y = y;
buffer[buffer_index].z = z;
buffer_index++;
if (buffer_index == BUFFER_SIZE){
int err = my_lbs_send_sensor_notify();
size_t size_of_struct = sizeof(buffer);
LOG_INF("Size of buffer: %u bytes", size_of_struct);
if (err) {
LOG_ERR("Notification failed: %d", err);
}
buffer_index = 0;
}
}
int my_lbs_send_sensor_notify(void)
{
if (!notify_sensor_enabled) {
return -EACCES;
}
return bt_gatt_notify(NULL, &accelerometer_svc.attrs[1],
&buffer,
sizeof(buffer));
}
/////////////////////////////////////////////////////////////////////
UPDATE: I modified the thread, and now I am able to get .9 Mbps. The modification looks like this:
void send_data_thread(void)
{
while(1){
if(notify_sensor_enabled){
simulate_data();
pack_data(sensor_valueX,sensor_valueY,sensor_valueZ);
}
}
}