diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index 9e8d912128..49c8e09f96 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -974,9 +974,16 @@ void MQTTtoBTAction(JsonObject& BTdata) { // If the request is to be performed immediately, stop the scan // so the loop will process connections. if (BTdata.containsKey("immediate") && BTdata["immediate"].as()) { - // Move this command to the front to process first + stopProcessing(); + NimBLEScan* pScan = NimBLEDevice::getScan(); + // Move this command to the front to process first std::reverse(BLEactions.begin(), BLEactions.end()); - NimBLEDevice::getScan()->stop(); + if (pScan->isScanning()) { + pScan->stop(); + } else { + BLEconnect(); + } + startProcessing(); } # endif }