-
-
I'm now including milliseconds also for more precision. Bangle.js 2 doesn't support setting time at millisecond precision, but this works quite nicely (wait until next exact second and then set time):
let delta = 1000 - (received_time % 1000); setTimeout(function() { setTime((received_time + delta) / 1000); }, delta);
-
Scan response timing seems deterministic only in relation to preceding advertising packet. For that to be useful I'd need to
a) know the exact time when preceding advertising packet was sent
b) set response packet content after preceding advertising packet has been sent, so it's uptodateI don't think either of those are possible with normal APIs since advertising isn't meant to be used for sending time-sensitive data like this. (Sure both would be possible in theory with custom Bluetooth protocol stack.)
-
I think connecting will result in a much more accurate time than relying on the right advertisement being picked up at the right time.
I thought so too but in my tests that connection takes several seconds while advertisement-solution can be improved down to e.g. 50ms delay between updating advertisement, so using connection is a lot worse for some reason.
bluetoth timing is strict, advertising packets are timed/spaced in deterministic way
No it's not deterministic - Bluetooth protocol has builtin random delay for timing which is around 10 ms or so, so accuracy better than that is not possible using normal API. (But yeah it's good enough.)
-
-
btw, there is a Python BlueZ example here and Bangle.js 2 does see those messages, so that would probably be better base (no need for bash or sudo), but I don't really know python so I didn't try modifying that code.
-
Currently accuracy is quite bad - that
sudo hcitool
sets up repeated broadcast which I change every second, so accuracy is about 1 second here.To get better accuracy I'd need to learn how to send broadcast at once without delay. BLE seems to have inherent random delay of around ~10 ms so e.g. 1 ms accuracy is not possible, but I think that accuracy of <100ms should be possible.
-
I can't resist trying to learn something new, so I managed to implement quick&dirty BLE time broadcast for Debian 11.
Broadcast side (bash, bluez), one broadcast per second for 60 seconds:
sudo hciconfig hci0 leadv 3 for (( n=1; n<60; n++ )) do time=$(date +%s) hex=$(printf '%010X' $time) echo $hex sudo hcitool -i hci0 cmd 0x08 0x0008 1E 02 01 1A 1A FF FF FF \ ${hex:0:2} ${hex:2:2} ${hex:4:2} ${hex:6:2} ${hex:8:2} \ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 sleep 1 done sudo hciconfig hci0 noleadv
Receiver side,
received_time
is Unix timestamp in seconds:packets=100; NRF.setScan(function(d) { packets--; if (packets == 0) { NRF.setScan(); } else if (d.manufacturer == 65535) { let received_time = 0; for (let i = 0; i < 5; i++) { received_time <<= 8; received_time += d.manufacturerData[i]; } } });
-
hmm, ok, I thought I read somewhere that Bangle.js 2 only supports one Bluetooth connection at a time.
I wouldn't mind a custom solution. I'm a programmer and my Debian 11 desktop computer is synced to NTP and has Bluetooth dongle, but I don't know enough of Bluetooth to try implementing something like that.
-
I've removed Bangle.js 2 from Gadgetbridge and done full software reset. What else I need to do to be able to again use Bangle.js 2 with https://banglejs.com/apps/ ?
-
BTW there is also BLE service for time defined so one could have some accurate time source around (e.g. ESP32 connected to internet adverting this over BLE) and then have app on bangle to scan for it and sync the time.
Wouldn't I need to manually unpair Bangle.js 2 from my phone, pair to that timesource, then unpair from timesource and pair with phone?
-
-
I paired my Bangle.js 2 to Gadgetbridge but forgot to install "Android Integration app".
Now when I go to https://banglejs.com/apps/ to install that the connection always fails.
How can I unpair Bangle.js 2 from Gadgetbridge so that I can use https://banglejs.com/apps/ to install "Android Integration app" ?
-
That page doesn't mention anything about syncing time, as far as I can see. ...
Yes, it lists what is supported - time is not listed so it's not supported.
I have not seen that Bangle.js 2 is that inaccurate...
For example I synced my Bangle.js 2 yesterday evening and it had <1s error. Currently error is already over 3s and it's been well under 24 hours. (Acceptable error is 2s at max, but preferably well under 1s.)
-
-
According to [1] Bangle.js 2 doesn't support getting time from Gadgetbridge.
Also [2] says that "sync time" only syncs when watch gets connected to phone, which is not enough. Bangle.js 2 is quite inaccurate and needs sync several times per day.
[1] https://www.espruino.com/Gadgetbridge#how-it-works-internally
[2] https://codeberg.org/Freeyourgadget/Gadgetbridge/wiki/Configuration -
-
Is it possible to automatically sync Bangle.js 2 time to smartphone time? Either by somehow requesting smartphone time from Bangle.js 2, or by "pushing" time from smartphone to Bangle.js 2 ?
(I'm not interested syncing to GPS time as GPS doesn't work indoors, and internet access isn't implemented yet so I can't sync to my webserver yet.)
-
-
-
I'm trying to follow this tutorial: https://www.espruino.com/Bangle.js+Development
When I get to
reset();
the Web IDE answers with following and Bangle.js 2 is stuck with screen which says just "Reloading...".>reset(); =undefined ____ _ | __|___ ___ ___ _ _|_|___ ___ | __|_ -| . | _| | | | | . | |____|___| _|_| |___|_|_|_|___| |_| espruino.com 2v11 (c) 2021 G.Williams Uncaught Error: Function not found! at line 13 col 667 in .boot0 ...oad('welcome.app.js')})}})()(function(){var settings=require("Storage"... ^ at line 1 col 152 ...age').read('bootupdate.js')); throw "Storage Updated!"} ^ >
Also
Bangle.buzz();
doesn't seem to do anything andBangle.beep();
makes watch vibrate. -
-
It seems that the 0-10ms random delay is not added to first advertisement, only to subsequent advertisements.
I'm currently testing code like this which seems to give quite steady rate of one advertisement every second (I hope to publish full code soon, maybe tomorrow):
For example here are differences in milliseconds of Bangle.js 2 time and my computer time for 5 minutes, one update every 10 seconds:
You can even see the clock drift here. With 1.73s/day you'd expect clock to drift 6ms in 5 minutes - at least for this short test it's clearly more than that.