Sensor data loss while sending data via Wifi request - MPU6050 and MKR Wifi1010

Hi everybody,

I am new to programming and need some advice.
In my project I am using an Arduino MKR Wifi 1010 and a MPU 6050 sensor to send accelerometer data at about 80 Hz via Wifi to a server.
The data is temporarily stored in an array on the arduino memory and sent about every 3 seconds via HTTP request.

But here is the problem: during request time, the accelerometer data gets lost, which means i got gaps of about 150ms every 3 seconds. I want to detect steps and other biomedical parameters, so this makes my measurement inaccurate.

How can I adapt my code, so nothing gets lost?
Can I use the Fifo buffer on the MPU 6050 to store the missing data temporarily?
Are there other possible solutions?

Please helf me out, I am happy for any advice I can get.

#include <MPU6050_tockn.h>
#include <WiFiNINA.h>

MPU6050 mpu6050(Wire);
long timer = 0;
long interval = 11;
int counter = 0;
String d; 
String dSend;

char server[] = "192.168.43.166";
char script[] = "/addarray.php";
char ssid[] = "EMAT";
char pass[] = "87654321";
int status = WL_IDLE_STATUS;
WiFiClient client;

void setup() {
    if (WiFi.status() == WL_NO_MODULE) {
            while (true);
    }
    while (status != WL_CONNECTED) {
        status = WiFi.begin(ssid, pass);
        delay(2000);
    }
    Wire.begin();
    mpu6050.begin();
    mpu6050.calcGyroOffsets(true);
}

void loop() {  
    mpu6050.update();
    if(millis() - timer > interval){
        int t = timer;
        int z = mpu6050.getAccX();
        timer = millis();
        if (counter < 1) {
            d.concat("data=[[");
            d.concat(t);
            d.concat(",");
            d.concat(z);
            d.concat("],[");
            counter++;
        } else if (counter <= 288) {
            d.concat(t);
            d.concat(",");
            d.concat(z);
            d.concat("],[");
            counter++;    
        } else {
            d.concat(t);
            d.concat(",");
            d.concat(z);
            d.concat("]]");
            dSend = d;
            d.remove(0);
            counter = 0;
        }        
    }
    if (dSend.length() > 10) {
        if (client.connect(server,80)) {
            client.print("POST ");
            client.print(script);
            client.println(" HTTP/1.1");
            client.print("Host:");
            client.println(server);
            client.println("Content-Type: application/x-www-form-urlencoded");
            client.print("Content-Length:");
            client.println(dSend.length());
            client.println();
            client.print(dSend);
            client.stop();
            dSend.remove(0);
        }
    }
}

The following is an example of streaming orientation data from an MPU6050 over ESP8266 WiFi to a computer using UDP/OSC. It might be possible to modify it for the WiFi 1010 and/or send raw sensor data.

gbafamily:
The following is an example of streaming orientation data from an MPU6050 over ESP8266 WiFi to a computer using UDP/OSC. It might be possible to modify it for the WiFi 1010 and/or send raw sensor data.

i2cdevlib/Arduino/MPU6050/examples/MPU6050_DMP6_ESPWiFi at master · jrowberg/i2cdevlib · GitHub

unfortunately the library seems not to be compatible with this arduino board

emat:
unfortunately the library seems not to be compatible with this arduino board