diff --git a/apps/sleepasandroid/README.md b/apps/sleepasandroid/README.md index 15bb2b670..c2b85189b 100644 --- a/apps/sleepasandroid/README.md +++ b/apps/sleepasandroid/README.md @@ -1,10 +1,16 @@ -# BLE GATT HRM Service +# Sleep as Android Integration -Adds the GATT HRM Service to advertise the current HRM over Bluetooth. +This app provides support for Sleep as Android using Gadgetbridge. ## Usage This boot code runs in the background and has no user interface. +For this to work you have to enable Sleep as Android support in Gadgetbridge and +select your Banglejs device. + +**Please Note**: This app does not activate the HRM sensor. It only listens to HRM events. +You may want to adjust the HRM sampling rate in the Health APP. I recommend at least one sample +every 10 minutes. ## Creator @@ -12,5 +18,5 @@ This boot code runs in the background and has no user interface. ## Aknowledgements -Special thanks to [Jonathan Jefferies](https://github.com/jjok) for creating the -bootgattbat app, which was the inspiration for this App! +Special thanks to [José Rebelo](https://github.com/joserebelo) and [Rob Pilling](https://github.com/bobrippling) +for their Code Reviews and guidance. diff --git a/apps/sleepasandroid/boot.js b/apps/sleepasandroid/boot.js index edd17b90c..16fe417f4 100644 --- a/apps/sleepasandroid/boot.js +++ b/apps/sleepasandroid/boot.js @@ -46,7 +46,10 @@ max_acceleration = {x: 0, y: 0, z: 0, mag: 0}; } - setInterval(sendSleepAsAndroidData, 10000); // Sleep as Android wants a 10-second maximum - Bangle.on("accel", updateAcceleration); // Log all acceleration events + var config = require("Storage").readJSON("sleepasandroid.json") || {}; + if (config.enabled) { // Gadgetbridge needs to enable and disable tracking by writing {enabled: true} to "sleepasandroid.json" and reloading + setInterval(sendSleepAsAndroidData, 10000); // Sleep as Android wants a 10-second maximum + Bangle.on("accel", updateAcceleration); // Log all acceleration events + } })(); diff --git a/apps/sleepasandroid/boot.min.js b/apps/sleepasandroid/boot.min.js index ae8662331..1d54f01e0 100644 --- a/apps/sleepasandroid/boot.min.js +++ b/apps/sleepasandroid/boot.min.js @@ -1 +1 @@ -(()=>{function a(A){try {Bluetooth.println('');Bluetooth.println(JSON.stringify(A))} catch (_) {console.error('Failed to send message via Bluetooth:',_)}}var b={x:0,y:0,z:0,mag:0};function c(B){var C=B.mag,_c=b.mag;C>_c&&(b=B)}function d(){var _a=Bangle.getAccel(),_b=Bangle.getHealthStatus();a({t:'sleep_as_android',accel:{x:_a.x*9.80665,y:_a.y*9.80665,z:_a.z*9.80665},bpm:_b.bpm});b={x:0,y:0,z:0,mag:0}}setInterval(d,10000);Bangle.on('accel',c)})(); +(()=>{function a(A){try {Bluetooth.println('');Bluetooth.println(JSON.stringify(A))} catch (_) {console.error('Failed to send message via Bluetooth:',_)}}var b={x:0,y:0,z:0,mag:0},e=require('Storage').readJSON('sleepasandroid.json')||{};function c(B){var C=B.mag,_c=b.mag;C>_c&&(b=B)}function d(){var _a=Bangle.getAccel(),_b=Bangle.getHealthStatus();a({t:'sleep_as_android',accel:{x:_a.x*9.80665,y:_a.y*9.80665,z:_a.z*9.80665},bpm:_b.bpm});b={x:0,y:0,z:0,mag:0}}e.enabled&&(setInterval(d,10000),Bangle.on('accel',c))})(); diff --git a/apps/sleepasandroid/config.json b/apps/sleepasandroid/config.json new file mode 100644 index 000000000..c994fef1c --- /dev/null +++ b/apps/sleepasandroid/config.json @@ -0,0 +1,3 @@ +{ + "enabled": false +} \ No newline at end of file diff --git a/apps/sleepasandroid/metadata.json b/apps/sleepasandroid/metadata.json index 08c5a2238..167f99b5b 100644 --- a/apps/sleepasandroid/metadata.json +++ b/apps/sleepasandroid/metadata.json @@ -16,6 +16,10 @@ { "name": "sleepasandroid.boot.js", "url": "boot.min.js" + }, + { + "name": "sleepasandroid.json", + "url": "config.json" } ] }