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.