bthometemp: use `ble_advert` module

pull/3480/head
Rob Pilling 2024-06-26 21:43:35 +01:00
parent 91dd1f6ec4
commit beb02e6260
3 changed files with 3 additions and 17 deletions

View File

@ -1,2 +1,3 @@
0.01: New App! 0.01: New App!
0.02: Handle the case where other apps have set bleAdvert to an array 0.02: Handle the case where other apps have set bleAdvert to an array
0.03: Use the ble_advert module

View File

@ -38,21 +38,7 @@ function onTemperature(p) {
pressure100&255,(pressure100>>8)&255,pressure100>>16 pressure100&255,(pressure100>>8)&255,pressure100>>16
]; ];
if(Array.isArray(Bangle.bleAdvert)){ require("ble_advert").set(0xFCD2, advert);
var found = false;
for(var ad in Bangle.bleAdvert){
if(ad[0xFCD2]){
ad[0xFCD2] = advert;
found = true;
break;
}
}
if(!found)
Bangle.bleAdvert.push({ 0xFCD2: advert });
}else{
Bangle.bleAdvert[0xFCD2] = advert;
}
NRF.setAdvertising(Bangle.bleAdvert);
} }
// Gets the temperature in the most accurate way with pressure sensor // Gets the temperature in the most accurate way with pressure sensor
@ -60,7 +46,6 @@ function drawTemperature() {
Bangle.getPressure().then(p =>{if (p) onTemperature(p);}); Bangle.getPressure().then(p =>{if (p) onTemperature(p);});
} }
if (!Bangle.bleAdvert) Bangle.bleAdvert = {};
setInterval(function() { setInterval(function() {
drawTemperature(); drawTemperature();
}, 10000); // update every 10s }, 10000); // update every 10s

View File

@ -1,7 +1,7 @@
{ "id": "bthometemp", { "id": "bthometemp",
"name": "BTHome Temperature and Pressure", "name": "BTHome Temperature and Pressure",
"shortName":"BTHome T", "shortName":"BTHome T",
"version":"0.02", "version":"0.03",
"description": "Displays temperature and pressure, and advertises them over bluetooth for Home Assistant using BTHome.io standard", "description": "Displays temperature and pressure, and advertises them over bluetooth for Home Assistant using BTHome.io standard",
"icon": "app.png", "icon": "app.png",
"tags": "bthome,bluetooth,temperature", "tags": "bthome,bluetooth,temperature",