Hello
So I have a bluetooth serial module connected to my Arduino Mega on the RX1, TX1 pins, and to my PC. It is working very good, I can send and receive to/from both sides. Serial settings are: 57600 8N1.
But sometimes, there are few data bytes that gets corrupted in the transmission.
Example of data corruption as seen in the Arduino IDE Serial Monitor, when the Arduino send data to PC:
hello blablabla blablabla blablabla blablabla blablabla blablabla blablabla
hello blablabla blablabla blablabla blablabla blablab±??±??±?blablabla
hello blablabla blablabla blablabla blablabla blablabla blablabla blablabla
Those errors are very rare, less than 1% of the messages sent by Arduino, contain some corrupted data.
I would like to know, what is the best (100% accurate, and if possible, fast) way to handle those errors?
I've though about few ideas:
-
When PC receive message, it send it back to the Arduino, which compare with the original message that was sent the first time. If no difference, then message is valid, do nothing, else re-send the message. Issue: if PC receive valid message but when sending back to Arduino, the message get corrupted, then the Arduino will still re-send the message.
-
Arduino adds some check bytes (a CRC for example) at the end of the message, PC recalculate the check bytes of the message and then compare with the check bytes that were received. If no difference, message is valid, do nothing, else ask Arduino to re-send the message. Issue: if PC send message "resend_message_please" to Arduino, and this message get corrupted, then the Arduino won't resend the message.
Some other ideas I had, are much more flawed so I don't bother writing them...
Do you have some better ways?
Thanks in advance