Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flushing buffer in direct mode (BLE / Bluetooth classic) #565

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

FedericoBusero
Copy link
Contributor

@FedericoBusero FedericoBusero commented May 15, 2022

Description

When running Blynk in direct mode (using Bluetooth/BLE), the connection can stop working after "Packet too big", "Invalid header type" or "Bad hdr len". The cause is the loss of one or more bytes, which makes the Blynk protocol get out of sync, resulting in a connection being closed.

A typical case is an Arduino Uno/Nano connected with a HM-10 module using SoftSerial (to keep Serial for debugging). Sometimes a byte is lost due to a bad softserial connection, and then the communication gets out of sync.

However, it is not necessary to close the open connection, it just needs to resync. Because the Blynk protocol misses sync bytes, it should be done in another way. In this solution, it makes use of the fact that Blynk on BT/BLE is sending its bytes in blocks, starting with the header. So, in case the systen is no longer synced, we just need to flush the buffer to get it in sync again. Using this fix, the stability of BLE in Blynk increases a lot when using SoftSerial.

Issues Resolved

  • Solve issue where the Blynk connection gets out of sync or stops after the loss of one or more bytes in direct mode (BLE/BT Classic) after showing the message "Packet too big", "Invalid header type" or "Bad hdr len".

@FedericoBusero FedericoBusero changed the title Federico busero direct mode sync Flushing buffer in direct mode (BLE / Bluetooth classic) May 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant