Enable deactivation of BLE connect (#895)

Useful if you want to scan continuously for BLE device, in this case you should deactivate the BLE connect to avoid concurrency between scan and connect
This commit is contained in:
Florian authored and GitHub committed 2021-03-14 12:53:26 -05:00
1 parent e2feb0bc24
commit 8afb1c5223
4 files changed
+41 -3

No files matched your search

+12 -2
View File
@@ -744,7 +744,7 @@ void coreTask(void* pvParameters) {
} else if (!ProcessLock) {
BLEscan();
// Launching a connect every BLEscanBeforeConnect
if (!(scanCount % BLEscanBeforeConnect) || scanCount == 1)
if ((!(scanCount % BLEscanBeforeConnect) || scanCount == 1) && bleConnect)
BLEconnect();
dumpDevices();
}
@@ -1462,7 +1462,8 @@ void BTforceScan() {
BTtoMQTT();
Log.trace(F("Scan done" CR));
# ifdef ESP32
BLEconnect();
if (bleConnect)
BLEconnect();
# endif
} else {
Log.trace(F("Cannot launch scan due to other process running" CR));
@@ -1519,6 +1520,15 @@ void MQTTtoBT(char* topicOri, JsonObject& BTdata) { // json object decoding
publishOnlySensors = (bool)BTdata["onlysensors"];
Log.notice(F("New value onlysensors: %T" CR), publishOnlySensors);
}
# ifdef ESP32
// Attempts to connect to elligible devices or not
if (BTdata.containsKey("bleconnect")) {
Log.trace(F("Do we initiate a connection to retrieve data" CR));
Log.trace(F("Previous value: %T" CR), bleConnect);
bleConnect = (bool)BTdata["bleconnect"];
Log.notice(F("New value bleConnect: %T" CR), bleConnect);
}
# endif
// MinRSSI set
if (BTdata.containsKey("minrssi")) {
// storing Min RSSI for further use if needed
+8
View File
@@ -709,6 +709,14 @@ void pubMqttDiscovery() {
"", "", true, subjectMQTTtoBTset, //set,payload_avalaible,payload_not avalaible,is a gateway entity, command topic
"", "", "", "", true // device name, device manufacturer, device model, device mac, retain
);
createDiscovery("switch", //set Type
"", "BT: Connect to devices", (char*)getUniqueId("bleconnect", "").c_str(), //set state_topic,name,uniqueId
"", "", "", //set availability_topic,device_class,value_template,
"{\"bleconnect\":true}", "{\"bleconnect\":false}", "", //set,payload_on,payload_off,unit_of_meas,
0, //set off_delay
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoBTset, //set,payload_avalaible,payload_not avalaible ,is a gateway entity, command topic
"", "", "", "", true // device name, device manufacturer, device model, device mac, retain
);
# endif
# endif
}
+4
View File
@@ -36,6 +36,10 @@ extern void launchBTDiscovery();
extern int btQueueBlocked;
extern int btQueueLengthSum;
extern int btQueueLengthCount;
# ifndef AttemptBLECOnnect
# define AttemptBLECOnnect true //do we by default attempt a BLE connection to sensors with ESP32
# endif
bool bleConnect = AttemptBLECOnnect;
#endif
/*----------------------BT topics & parameters-------------------------*/