]> git.basschouten.com Git - openhab-addons.git/commitdiff
make blu gw script more rebust on startup (#16304)
authorMarkus Michels <markus7017@gmail.com>
Fri, 19 Jan 2024 09:53:46 +0000 (04:53 -0500)
committerGitHub <noreply@github.com>
Fri, 19 Jan 2024 09:53:46 +0000 (10:53 +0100)
Signed-off-by: Markus Michels <markus7017@gmail.com>
Co-authored-by: markus7017 <markus7017@gmail..com>
bundles/org.openhab.binding.shelly/src/main/resources/scripts/oh-blu-scanner.js

index c1583a92ec7152887ed019a914b0d97341947250..3dd38932ad727a4ed0f673849f015b6838c058b0 100644 (file)
@@ -150,11 +150,22 @@ function scanCB(ev, res) {
   }
 }
 
+// retry several times to start the scanner if script was started before
+// BLE infrastructure was up in the Shelly
+function startBLEScan() {
+    let bleScanSuccess = BLE.Scanner.Start({ duration_ms: SCAN_DURATION, active: true }, scanCB);
+    if( bleScanSuccess === null ) {
+        console.log('Unable to start OH-BLU Scanner, make sure Shelly Gateway Support is disabled in device config.');
+        Timer.set(3000, false, startBLEScan);
+    } else {
+        console.log('Success: OH-BLU Event Gateway running');
+    }
+ }
 let BLEConfig = Shelly.getComponentConfig('ble');
 if(BLEConfig.enable === false) {
-  console.log('Error: BLE not enabled, unable to start OH-BLU Scanner');
+    console.log('Error: BLE not enabled, unable to start OH-BLU Scanner');
 } else {
-    BLE.Scanner.Start({ duration_ms: SCAN_DURATION, active: true }, scanCB);
-    console.log('OH-BLU Event Gateway running');
+    Timer.set(1000, false, startBLEScan);
 }
  
\ No newline at end of file