Reputation: 1035
I have Windows Forms App referencing UWP APIs for Bluetooth LE. My ESP32 creates GATT server. Windows App connects to it but I am able to make 7-9 calls per second. I need at least 40 calls per second. I am using Windows App to analyse audio via FFT, compute color and then I send it via Bluetooth like:
AT+SPECTRUM="240,200,122";\r\n
This command I have to send 40 times per sec. Wiki says that Bluetooth LE is able speed 0.27Mbps which is okay. Distance between chips is 50cm+-. Why Bluetooth? I would like to command it from notebook and iPhone aswell.
I am sending data in own Task:
public class BluetoothTask
{
Task task;
CancellationTokenSource tokenSource = new CancellationTokenSource();
GattCharacteristic gattCharacteristic;
public AutoResetEvent Signal { get; } = new AutoResetEvent(true);
public Point3D Color { get; set; } = new Point3D(0, 0, 0);
public BluetoothThread()
{
}
public void Start(GattCharacteristic characteristic)
{
gattCharacteristic = characteristic;
tokenSource = new CancellationTokenSource();
task = Task.Factory.StartNew(() => ProcessAsync());
}
public void Stop()
{
tokenSource.Cancel();
}
async Task ProcessAsync()
{
DataWriter writer = new DataWriter();
Stopwatch stopwatch = new Stopwatch();
int i = 0;
stopwatch.Start();
while (true)
{
if (tokenSource.Token.IsCancellationRequested)
break;
writer.WriteString($"AT+SPECTRUM=\"{(int)Math.Min(Color.X, 255)},{(int)Math.Min(Color.Y, 255)},{(int)Math.Min(Color.Z, 255)}\";\r\n");
try
{
await gattCharacteristic.WriteValueAsync(writer.DetachBuffer());
i++;
if(stopwatch.ElapsedMilliseconds >= 1000)
{
Debug.WriteLine($"Bluetooth calls: {i}");
i = 0;
stopwatch.Restart();
}
}
catch (Exception ex)
{
}
}
}
}
I would be glad if you could give me advice how to speedup communication between devices. Oh and btw I'm using that color ofc for Led strip control.
Upvotes: 1
Views: 1452
Reputation: 111
Increase the connection parameters of the peripheral (ESP32) to be more frequent to improve the speed. In other words, shorten the connection interval. This is not on Windows side and needs to be configured on the peripheral side.
Upvotes: 2