Skip to content

Commit

Permalink
Adjust bluetooth scan time
Browse files Browse the repository at this point in the history
  • Loading branch information
redakker committed Nov 16, 2023
1 parent 59bf0ad commit a9ce8dc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
9 changes: 4 additions & 5 deletions src/bluetooth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class BlueTooth: public BLEAdvertisedDeviceCallbacks {
String command;
long lastRun = 0;
long lastClear = 0;
long lastSendDeviceData = 0;
int scanAfter = BT_DEFAULT_SCAN_INTERVAL;
long lastSendDeviceData = 0;

boolean sendAutoDiscovery = false;
long lastSendAutoDiscovery = 0;
Expand Down Expand Up @@ -81,7 +80,7 @@ class BlueTooth: public BLEAdvertisedDeviceCallbacks {
// Parse the sting, split by ;

// Auto discovery for Home Assistant is available.
// Set it tru if the user enabled it
// Set it tre if the user enabled it
sendAutoDiscovery = (database.getValueAsInt(DB_HA_AUTODISCOVERY) > 0) ? true : false;
if (sendAutoDiscovery) {
autoDiscoveryPrefix = database.getValueAsString(DB_HA_AUTODISCOVERY_PREFIX);
Expand All @@ -97,10 +96,10 @@ class BlueTooth: public BLEAdvertisedDeviceCallbacks {

void loop() {

if (millis() - lastRun > scanAfter) {
if (millis() - lastRun > BT_DEFAULT_SCAN_INTERVAL) {
// Otherwise makes no sens to scan and sent it over
if (networkConnected) {
BLEScanResults foundDevices = pBLEScan->start(5, false);
BLEScanResults foundDevices = pBLEScan->start(10, false);
pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory
lastRun = millis();
}
Expand Down
2 changes: 1 addition & 1 deletion src/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#define BT_DEVICE_DATA_INTERVAL 1000*60 // Send the BLE device data time to time
#define DEVICE_DROP_OUT_COUNT 2 // We won't drop out in the first "not found" state, just decrease this value. Drop out when this is 0
#define PARSE_CHAR ";"
#define BT_DEFAULT_SCAN_INTERVAL 2000 // Scan is running after this timeout time to time
#define BT_DEFAULT_SCAN_INTERVAL 3000 // Scan is running after this timeout time to time

// Webhook
#define PRESENCE_WILDCARD "{presence}"
Expand Down
2 changes: 1 addition & 1 deletion src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class Mqtt {
}

void sendStatus () {
sendMqttMessage(baseTopic, "{\"status\": \"" + statusOn + "\", \"ip\":\"" + this -> deviceIPAddress + "\"}");
sendMqttMessage(baseTopic, "{\"status\": \"" + statusOn + "\", \"ip\":\"" + this -> deviceIPAddress + "\"}", true);
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/webcontent.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ BLEcker
<a class="button w100" href="/">home</a>
<a class="button w100" href="/update">update</a>
<!--<a class="button w100 button-danger" id="reset" href="#">reset</a>-->
<div class="version" id="version">v1.11 - 134</div>
<div class="version" id="version">v1.11 - 144</div>
<div id="footer">
<div><a href="https://github.com/redakker/blecker" target="_blank">blecker</a></div>
</div>
Expand Down Expand Up @@ -1550,7 +1550,7 @@ BLEcker
<a class="button w100" href="/">home</a>
<a class="button w100" href="/update">update</a>
<!--<a class="button w100 button-danger" id="reset" href="#">reset</a>-->
<div class="version" id="version">v1.11 - 134</div>
<div class="version" id="version">v1.11 - 144</div>
<div id="footer">
<div><a href="https://github.com/redakker/blecker" target="_blank">blecker</a></div>
</div>
Expand Down
10 changes: 6 additions & 4 deletions src/webhook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Webhook {

Logger logger;
Database* database;
HTTPClient http;
HTTPClient http;

boolean webhookConfigured = false;
unsigned long lastrun = 0;
Expand Down Expand Up @@ -39,16 +39,18 @@ class Webhook {

if (webhookConfigured) {
String baseURL = this->database->getValueAsString(DB_WEBHOOK);
baseURL.toLowerCase();

baseURL.replace(DEVICE_WILDCARD, device.mac);
if (device.available) {
baseURL.replace(PRESENCE_WILDCARD, getPresentString(*database, true));
} else {
baseURL.replace(PRESENCE_WILDCARD, getPresentString(*database, false));
}

http.begin(baseURL); //Specify the URL
int httpCode = http.GET(); //Make the request

http.begin(baseURL); //Specify the URL

int httpCode = http.GET(); //Make the request

if (httpCode > 0) { //Check for the returning code

Expand Down

0 comments on commit a9ce8dc

Please sign in to comment.