espruino / BangleApps

Bangle.js App Loader (and Apps)
https://banglejs.com/apps
MIT License
498 stars 1.17k forks source link

[OpenHaystack (AirTag)] Module "ble_advert" not found #3667

Closed ZuriMuri closed 1 week ago

ZuriMuri commented 1 week ago

Affected hardware version

Bangle 2

Your firmware version

2v24

The bug

When I try to install 'OpenHaystack (AirTag)' with a valid advertisement key via the app loader on my Bangle 2 I get the following error:

"Uncaught Error: Module "ble_advert" not found at line 23 col 21 in .boot0"

I suppose that the "ble_advert" package is not available anymore or at least faulty. My Console prompts this:

Loading modules loadModule(ble_advert) ERROR: getURL("https://www.espruino.com/modules/ble_advert.min.js") error : HTTP 404 ERROR: getURL("https://www.espruino.com/modules/ble_advert.js") error : HTTP 404 ERROR: getURL("https://banglejs.com/apps/modules/ble_advert.min.js") error [object ProgressEvent]

I tried to manually add the module via "require("ble_advert")" and require("https://raw.githubusercontent.com/espruino/BangleApps/refs/heads/master/modules/ble_advert.js") within the IDE but it failed to RAM and FLASH. When trying to FLASH I needed to factory reset my bangle 2 because it always gets stuck on the Bluetooth loading screen.

OpenHaystack (AirTag)_error

Installed apps

No response

bobrippling commented 1 week ago

@gfwilliams we have the ble_advert module, so I guess this is an issue with it being published to espruino.com?

gfwilliams commented 1 week ago

Thanks for the report!

I tried .... but it failed to RAM and FLASH

You need to upload it to Storage with the filename ble_advert and it'd be fine. There's some info about it in https://github.com/espruino/BangleApps/blob/master/modules/README.md

... but you shouldn't have to do that!

Looks like this would have started with bcc5ae9a155402b1d804264b7cb929bbc28898f3 which is actually one of your commits @bobrippling ? I doubt this has ever worked since that change.

The App Loader parses and handles modules for any file uploaded with a '.js' extension in the url - but there was no URL specified for the file so it just copied it in verbatim. I've just pushed a fix which supplies a URL which even though it's not used and wouldn't work anyway fools the app loader into parsing the file.

Just FYI, I'm not sure where you saw those ERROR: getURL messages, but the App Loader should be checking https://www.espruino.com/modules/ and https://banglejs.com/apps/modules for minified and unminified files. It errors for the first 3 and that's expected, but presumably it does find https://banglejs.com/apps/modules/ble_advert.js and uploads it

ZuriMuri commented 1 week ago

Thank you both for the fast replies and fixes!

You need to upload it to Storage with the filename ble_advert and it'd be fine. There's some info about it in https://github.com/espruino/BangleApps/blob/master/modules/README.md

You are right - I saved the file with a ".js" extension before and that was my mistake. Uploading it manually made the errors go away.

Just FYI, I'm not sure where you saw those ERROR: getURL messages, but the App Loader should be checking https://www.espruino.com/modules/ and https://banglejs.com/apps/modules for minified and unminified files. It errors for the first 3 and that's expected, but presumably it does find https://banglejs.com/apps/modules/ble_advert.js and uploads it

The errors occured but if I recall correctly it then prompted that the minified file was loaded anyways.

Unfortunately I still can't get it to work... The key is not picked up by the apple network. I assume that the MAC address of my Bangle2 does not stay "static" as I see changing MAC addresses when I connect the app loader or IDE. The key I'm using is working with my FlipperZero over an anisette-v3-server and FindMy - I've tested that before. Maybe someone else can try if it works for them or if I need to make further adjustments to my Bangle settings for it to work?!

gfwilliams commented 1 week ago

as I see changing MAC addresses when I connect the app loader or IDE.

Well, as soon as the code for OpenHaystack is run (right after boot) the Mac should be set to what's needed for the beacon.

So you might see the Mac address come up for a fraction of a second as the old (original) one but I think after that it should stay as the right one?

But I do wonder whether those changes that were made might have broken it somehow. Were you able to test it when you made the changes @bobrippling?

It might be interesting to connect with the Web IDE and write the old code to openhaystack.boot.js:

{
const key = E.toUint8Array("KEYVALUE"); // public key - copy this out of what was in openhaystack.boot.js before
const mac = [ key[0] | 0b11000000, key[1], key[2], key[3], key[4], key[5] ].map(x => x.toString(16).padStart(2, '0')).join(':'); // mac address
const adv = [ 0x1e, 0xff, 0x4c, 0x00, 0x12, 0x19, 0x00, key[6], key[7], key[8], key[9], key[10], key[11], key[12], key[13], key[14], key[15], key[16], key[17], key[18], key[19], key[20], key[21], key[22], key[23], key[24], key[25], key[26], key[27], key[0] >> 6, 0x00 ]; // advertising packet
NRF.setAddress(mac);
NRF.setAdvertising([adv,{}],{whenConnected: true, interval: 1000}); // advertise AirTag *and* normal device name (to remain connectable)
}
bobrippling commented 1 week ago

Yes I have a horrible feeling something's broken - I'll test with the old code too and see if I get any reports coming through

ZuriMuri commented 1 week ago

It might be interesting to connect with the Web IDE and write the old code to openhaystack.boot.js:

I tried it yesterday and here is what I've found:

but

  1. The screen freezes while displaying "Reloading" or "Loading" - as soon as I long press the button it unfreezes but then the MAC becomes dynamic again

  2. While the screen was frozen the Bangle was still accesible via IDE/App Loader so I let it stay that way for a couple hours to see if BLE adverts are picked up by the "find my" network. Unfortunately the signal was not picked up eventhough I had Apple devices with Bluetooth in sight/reach all the time.

I will look into how the payload for ble advertisement is formed in openhaystack and compare if I identify any differences. Maybe something changed there as well with byte-sequences etc. which might be the cause of the signal not getting picked up.

gfwilliams commented 1 week ago

The screen freezes while displaying "Reloading" or "Loading" -

I think that's probably a sign that there's been an error while executing the code (so maybe there was some typo when you pasted it into the IDE?) - if you reload it with the IDE connected I'd hope it would tell you what the error was if there was one.

ZuriMuri commented 1 week ago

There was indeed an error which I was able to solve. However the MAC does not stay the same with the Bangle but keeps changing after I upload the key.

I analyzed both payloads and the ble advertisement is identically (no error there). So I'd assume that the reason it is not working is that the bangle still changes its MAC eventhough it is not supposed to :(

gfwilliams commented 1 week ago

That's really strange. Can you put your finger on when the Bangle changes MAC address? Like when you change apps, or just seemingly randomly?

And does it change just between two MAC addresses, or multiple different ones?

ZuriMuri commented 1 week ago

So I tried to go with a clean uninstall/install but still can't figure out why the signal is not picked up by the FindMy network. All it ever states is: "BLE connected, queuing BLE restart for later".

When your changes in the Git Repo are pushed to the official bangle app website I'll gladly give it another try...

In the meantime someone else can maybe test if it is working for them or if they are having similar issues?! 😕

gfwilliams commented 4 days ago

All it ever states is: "BLE connected, queuing BLE restart for later".

That's what you'd expect - it can't change some things while the BLE connection is active as it has to restart the bluetooth stack for them.

It's not possible you're just constantly staying connected to the Bangle so it's not getting a chance to advertise is it?

ZuriMuri commented 4 days ago

Negative, I did disconnect. Tried it once the app was updated, disconnected and then held the button to reload and vice versa. Still the same outcome.

bobrippling commented 1 day ago

To double-check, is this with the code revert to before bcc5ae9?

ZuriMuri commented 1 day ago

I tried both actually, the NRF.setAdvertising and require("ble_advert") and they didn't work for me :/

bobrippling commented 6 hours ago

Interesting - have you seen it working in the past, ever? If not, it could be that your watch isn't being picked up by any devices capable of adding it to the FindMy network

bobrippling commented 6 hours ago

Similarly - I haven't been able to get my watch on the network for a while (#3566), perhaps something's up