diff --git a/apps.json b/apps.json index c46d5f8a9..936cc939c 100644 --- a/apps.json +++ b/apps.json @@ -337,5 +337,17 @@ {"name":".tfmodel","url":"gesture-tfmodel.js","evaluate":true}, {"name":"*gesture","url":"gesture-icon.js","evaluate":true} ] + }, + { + "id": "blescan", + "name": "BLE Scanner", + "icon": "blescan.png", + "description": "Scan for advertising BLE devices", + "tags" : "bluetooth", + "storage" : [ + {"name":"+blescan","url":"blescan.json"}, + {"name":"-blescan","url":"blescan.js"}, + {"name":"*blescan","url":"blescan-icon.js", "evaluate":true} + ] } ] diff --git a/apps/blescan-icon.js b/apps/blescan-icon.js new file mode 100644 index 000000000..771d36657 --- /dev/null +++ b/apps/blescan-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwxH+AH4A/AH4ATmIABrdbAgQrmAAYvEAAYtkF5QxcEZAvLGDAhJF5oxWFhYAFCBFaFzQsHAAk3CQmE1wwRFxiPFMY4uBwiSRI4uEQo4GIAAIVBxTCRFwoABJITvNrYTHRqIuCAAIvPxQSBBQwvQL6aMCBQ7sQVIQuGdIjqIGCIOEm4XHForqFIAYHBm4vTFxYMDAQKeHDIwvVRAoEDdRAvPE5QcHAoTqJDQ5eZAwS7DIZovWAodaRQLqGF6bhDABouCXYIAQF+6PUrQUQd7oMKF6wbLApYaIF45gSAgxeUF5olDBIICECJIvTm4wLAAoPHm4vTC4OK12EGJYLFI5IvJGAuE1wABGAycIBRQuKF4ouCAAIvPIgOFF6QwEL6c3IRAuMGA+EWw4GIwuusAuTeQzqGF4r0LF6AwIm4mEAA03FzAwJLAxbKFygwLd5IuaMRwthGBYvKFzQxJF5AtdGZAvEFcYA/AH4AvA==")) diff --git a/apps/blescan.js b/apps/blescan.js new file mode 100644 index 000000000..2dc563b75 --- /dev/null +++ b/apps/blescan.js @@ -0,0 +1,52 @@ +// ble-scanner +// Scan the airwaves every three seconds (which seems safe for a large number of devices) +// Using the menu feature, display a scrollable list of BLE devices on the watch + +// Dummy menu item to display until we find something +const NODEVICE = 'No devices found'; + +const SCAN_INTERVAL = 3000; + +const menu = { +}; + +menu[NODEVICE] = { + value : "", + onchange : () => {} +}; + + +function draw() { + Bangle.menu(menu); +} + +function scan() { + NRF.findDevices(devices => { + for (let device of devices) { + + // Only display devices that advertise a name + + if (device.name) { + // Remove no devices found message if it is present + if (menu[NODEVICE]) { + delete menu[NODEVICE]; + } + menu[device.name] = { + value : device.rssi, + onchange : () => {} + }; + } + } + draw(); + }, { active: true }); +} + + +function waitMessage() { + E.showMessage('scanning'); +} + +scan(); +waitMessage(); + +setInterval(scan, SCAN_INTERVAL); diff --git a/apps/blescan.json b/apps/blescan.json new file mode 100644 index 000000000..d9e7f28f1 --- /dev/null +++ b/apps/blescan.json @@ -0,0 +1,7 @@ + +{ + "name": "BLE Scanner", + "type":"app", + "icon": "*blescan", + "src": "-blescan" +} diff --git a/apps/blescan.png b/apps/blescan.png new file mode 100644 index 000000000..efe76af51 Binary files /dev/null and b/apps/blescan.png differ