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

BLE - Disconnect after a timeout #842

Merged
merged 1 commit into from
Jan 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions main/ZgatewayBT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,8 @@ void BLEconnect() {
if (pRemoteCharacteristic->canNotify()) {
Log.trace(F("Registering notification" CR));
pRemoteCharacteristic->subscribe(true, notifyCB);
delay(BLE_CNCT_TIMEOUT);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a delay here we could use a task notification wait with BLE_CNCT_TIMEOUT as the max wait time. The notification callback could release the task before the timeout and this would save time and battery power for both devices if applicable. Thoughts?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes good point!

pClient->disconnect();
} else {
Log.notice(F("Failed registering notification" CR));
pClient->disconnect();
Expand Down
1 change: 1 addition & 0 deletions main/config_BT.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ extern void MQTTtoBT(char* topicOri, JsonObject& RFdata);
#define BLEdelimiterLength 16
#define CRLR "0d0a"
#define CRLR_Length 4
#define BLE_CNCT_TIMEOUT 3000

#define ServicedataMinLength 29

Expand Down