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

ESP32 Bluetooth Classic (BT) support #428

Merged
merged 13 commits into from Feb 1, 2019
Merged

ESP32 Bluetooth Classic (BT) support #428

merged 13 commits into from Feb 1, 2019

Conversation

FedericoBusero
Copy link
Contributor

Description

Add support for Bluetooth (classic, BT) on ESP32 (Android only).
This need an up-to-date ESP32 library, if not it will not compile.

I did not make use of BluetoothSerial, due to the lack of onConnect, onDisconnect and Txpower functionality. By handling connect/disconnect nicely, Blynk always keeps working perfectly without sync-problems when going out-of-range and coming back. Remark that this needs Android app 2.26.7, as in 2.26.6 there is a bug in the Bluetooth implementation (I checked with a development version, in which Bluetooth issues are solved).

Add possibility to define the device name of the ESP32 BLE device
When running Blynk in direct mode (using Bluetooth/BLE), the connection can stop working after "Packet too big" or "Invalid header type". 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.
However, it is not necessary to stop the 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 block, 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. Because conn.flush() doesn't exist, we make use of the fact that conn.connect() is basically executing a buffer flush.
flush in direct mode instead of reconnecting
Update with blynkkk master
Use of old values ESP_PWR_LVL_N2, ESP_PWR_LVL_P7 for backward compatibility, they are also available in new IDF code
@vshymanskyy vshymanskyy self-assigned this Oct 17, 2018
@vshymanskyy vshymanskyy merged commit 6181ea1 into blynkkk:master Feb 1, 2019
teejaydub pushed a commit to teejaydub/blynk-library that referenced this pull request Jan 26, 2023
* User defined ESP32 BLE Device name

Add possibility to define the device name of the ESP32 BLE device

* name BLE_DEVICE_NAME to be consistent with other BLE's

* Flushing buffer in direct mode

When running Blynk in direct mode (using Bluetooth/BLE), the connection can stop working after "Packet too big" or "Invalid header type". 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.
However, it is not necessary to stop the 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 block, 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. Because conn.flush() doesn't exist, we make use of the fact that conn.connect() is basically executing a buffer flush.

* Update BlynkProtocol.h

flush in direct mode instead of reconnecting

* update naar blynk lib

* Initial ESP32 BT classic support

* ESP32 BT classic example

* Update BlynkProtocol.h

* use old values ESP_PWR_LVL_N2, ESP_PWR_LVL_P7

Use of old values ESP_PWR_LVL_N2, ESP_PWR_LVL_P7 for backward compatibility, they are also available in new IDF code
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

2 participants