# A question about speed with saving files and bluetooth

Hey everyone!
I’m building an app for my college project.
I need to send data via Bluetooth every 2 milliseconds (500 [Hz]) or so, and save that data.
So far I have everything running and performing well, the ESP32 (the microcontroller I use to send the data with) sends everything in 2 milliseconds ±.

There is a problem with one thing: The data isn’t being saved at 500 [Hz] speed.
When I completely remove the Bluetooth from the blocks, I can get 500 [Hz] rate of data saving.
But when I use Bluetooth, the speed is reduced to 100 [Hz], 5 times slower!

I checked the time difference between the beginning of the timer, and the end and I see only 3~4 milliseconds of delay (which is not optimal, but tolerable, I can live with 250 [Hz]).

Can someone help me to understand, why I got much lower saving rate then I’m supposed to get?

We would need to see your Blocks Aviel but you certainly can’t get an App to receive and save streamed data so fast on an Android device like a smartphone.

Question: Why do you need to save data every 2 milliseconds? Let’s say that is achieved - you have then got 150000 rows/items of data in five minutes!

Hahahaha, I guess it really is difficult to help without seeing the blocks, here is a picture:
[image below]

I want to save some data at a rate of 500 Hz, I know that saving all the data for a long time would be crazy hahaha.

Edit: the main code is below, getting the data via Bluetooth, and saving it.

In an ideal world, all the file appending would be done via a single append block. There is so much going on in the Clock1 Timer Block and that is where the delay is.

1. You haven’t explained why the data needs to be processed so fast. There does not appear to be any data processed that would warrant it. Closer to 0.5 seconds would be more realistic if the plotting is live.

1)Set the data send time interval on the bluetooth device to 1 second (1000 milliseconds) and set the App Clock 1 Timer to 800 milliseconds. When everything is working, those values can be tweaked-down (trial and error) but the App time interval must be about 20% faster than the bluetooth device.

We do not know what device you are using so can’t give advice on it’s script other than to say you must ensure the End Of Data flag used by the script is known by the App.

…don’t set the Clock1 Timer interval in the timer block - set it before the block is called.