c# - Some data is being skipped when writing to Arduino esp32 from Unity per frame - Stack Overflow

I'm currently getting an issue when sending data per frame, the last thing sent sometimes doesn�

I'm currently getting an issue when sending data per frame, the last thing sent sometimes doesn't appear on the device. I have a feeling there might be something on the Arduino side of things that I can update to make sure the last thing sent is always received even if it interrupts the previous onWrite, but I'm not familiar enough with Arduino to be sure.

I'm sending data from Unity using Velorexe's Unity Android Bluetooth low Energy plugin.

For example, if I have this in Update:

void Update()
{
    dataPacket = Time.time.ToString();

    Debug.Log($"Sending data packet {dataPacket}.");

    _writeCharacteristic = new WriteToCharacteristic(uuid, serviceUUID, characteristicUUID, Encoding.ASCII.GetBytes(dataPacket), true);
    _writeCharacteristic.Start();
}

In the Logcat, I'll see the updates happening every frame. Logcat debugs per frame

I'm using NimBLE in Arduino, and printing out the value from the onWrite DataCallback. This is all I get in the Serial Monitor. Arduino Serial Monitor

A new WriteToCharacteristic is being created and started per frame, but not all of them are being received. It's not terribly important that every single one makes it through, but it is important that the last one is received as soon as it's created and overwrites the current one/anything before it.

What would be the best way to set it up so that the last _writeCharacteristic takes priority?

I've tried adding _writeCharacteristic.End(); before creating the next one, so that there shouldn't be any running write commands to prevent the last one from being picked up. I'm not too sure what else I could do aside from just making a for loop that checks to make sure the current data on the device matches what's in Unity, but that feels really hacky/unoptimized.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745062092a4609025.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信