-
• #2
I'm not sure what to suggest here I'm afraid... The way
setServices
works it shouldn't really be able to call the handler twice. What if you add some kind of 'print' statement insideonWrite: (e) => cc.read(new Uint8Array(e.data))
just in case yourcc.read
method is doing something internally?You could also check on your watch to ensure your code isn't in there twice (eg in two separate files). You could check with:
require("Storage").list().forEach(f=>{ if (require("Storage").read(f).includes("0xf012")) print(f); });
If it's ok, it should be in just
.boot0
and in yourapp.boot.js
file -
• #3
I found the issue, and its not Espruino/Bangle. The callback isn't called twice (should have count it earlier) but the returned message on Nordic UART is processed twice on the remote side (Arch Linux, Intel 7260, Bluez 5.66). But only if I didn't remove the device using
bluetoothctl
after a reset.Sorry for the distraction!
For future reference: when the custom characteristic is added, and my Bluez already knows about the Nordic UART from previous discover, it would immediately disconnect after connect. So I'm forced to remove and rediscover. If, however, it knows about the custom characteristic and the custom characteristic is added during a reset, it wouldn't disconnect after connect but process incoming messages twice. Or at least thats what I see and I'm able to reproduce. Remove and rediscover solves the issue for me.
-
• #4
when the custom characteristic is added, and my Bluez already knows about the Nordic UART from previous discover, it would immediately disconnect after connect. So I'm forced to remove and rediscover.
That's a good one to know... I had occasionally got into an odd state that required removal of the device (and IIRC that is somewhere in the bluetooth troubleshooting docs) but I didn't know why!
Out of interest, how do you remove? Just with the OS's Bluetooth Menu, or via some command-line? I find the OS menu very difficult as it's got about 1000 devices in it for me!
-
• #5
With
bluetoothctl
s shell you can executeremove {MAC}
as well asscan le
,devices
,scan off
. And as a last resortpower off
andpower on
. It does remember previous commands but won't autocomplete afaik. I assume there are cmdline arguments for scripting.
Hi,
there is
NRF.setServices
and I have no trouble setting up a custom service and characteristics when executing code in the IDE, and use it thereafter. Then I tried to put this in a.boot.js
file and an issue pops up: the writable characteristic callsonWrite
twice each time a message arrives.So I thought its because
setServices
is called multiple times (e.g. after long-press BTN3), but even the following doesn't solve it:When I run its parts individually, everything works (e.g. first
has_service
returns false, thensetServices
, thenhas_service
returns true) and I get oneonWrite
per message. When I do a hard reset with this in the boot file and write to the characteristic,onWrite
gets called twice.It would be great if anyone could shed some light on this :)
edit:
.t
is 1