我有Windows窗体应用程序引用蓝牙LE的UWP App。我的ESP32创建关贸总协定服务器。Windows应用程序连接到它,但我每秒可以进行7-9次呼叫。我需要至少每秒40个电话。我正在使用Windows App通过FFT分析音频,计算颜色,然后通过蓝牙发送,如下所示:
AT+SPECTRUM="240,200,122";\r\n这个命令我每秒要发送40次。Wiki说蓝牙LE的速度是0.27 says,这是可以的。芯片之间的距离为50 is +-。为什么选择蓝牙?我也想在notebook和iPhone上使用它。
我正在自己的任务中发送数据:
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)
{
}
}
}
}如果你能给我一些建议,如何加速设备之间的通信,我会很高兴的。哦,顺便说一句,我正在用那颜色的ofc来控制Led条带。
发布于 2018-07-26 07:25:39
增加外设(ESP32)的连接参数,使其频率更高,以提高速度。换句话说,缩短连接间隔。这不是在Windows端,需要在外设端配置。
https://stackoverflow.com/questions/51485129
复制相似问题