Skip to content

Commit

Permalink
make blu gw script more rebust on startup (openhab#16304)
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Michels <markus7017@gmail.com>
Co-authored-by: markus7017 <markus7017@gmail..com>
Signed-off-by: Jørgen Austvik <jaustvik@acm.org>
  • Loading branch information
2 people authored and austvik committed Mar 27, 2024
1 parent 5d85497 commit 120dc7c
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 120dc7c

Please sign in to comment.