Skip to content

Commit cfa6f42

Browse files
committed
If ble_advert sets the advertisement and it's too long (eg BTHome sends too much info) then don't advertise the Bangle's name
1 parent 0cee7cd commit cfa6f42

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

modules/ble_advert.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,20 @@ var advertise = function (options) {
1717
if (!options.manufacturer)
1818
options.manufacturer = false;
1919
}
20+
var adv = clone(Bangle.bleAdvert);
2021
try {
21-
NRF.setAdvertising(clone(Bangle.bleAdvert), options);
22+
NRF.setAdvertising(adv, options);
2223
}
2324
catch (e) {
24-
console.log("ble_advert error", e);
25+
if (e.toString().includes("INVALID_LENGTH")) {
26+
options.showName = false;
27+
try {
28+
NRF.setAdvertising(adv, options);
29+
}
30+
catch (e) {
31+
console.log("ble_advert error", e);
32+
}
33+
}
2534
}
2635
};
2736
var manyAdv = function (bleAdvert) {

modules/ble_advert.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,18 @@ const advertise = (options: SetAdvertisingOptions) => {
4141
// taking effect for later calls.
4242
//
4343
// This also allows us to identify previous adverts correctly by id.
44+
let adv = clone((Bangle as BangleWithAdvert).bleAdvert);
4445
try {
45-
NRF.setAdvertising(clone((Bangle as BangleWithAdvert).bleAdvert), options);
46+
NRF.setAdvertising(adv, options);
4647
} catch (e) {
47-
console.log("ble_advert error", e);
48+
if ((e as Error).toString().includes("INVALID_LENGTH")) {
49+
options.showName=false; // if the advertising is too long, automatically remove the Bangle's name from advertisements
50+
try {
51+
NRF.setAdvertising(adv, options);
52+
} catch (e) {
53+
console.log("ble_advert error", e);
54+
}
55+
}
4856
}
4957
};
5058

0 commit comments

Comments
 (0)