-
• #2
A further question : If I am calling :
NRF.setAdvertising({},{ showName:false, connectable:false, scannable:false, interval:375, manufacturer:0x0590, manufacturerData:JSON.stringify(data) });
Then I try to connect to bangle via web IDE after going to 'clock'/'home'. It doesn't connect. I assume this has overridden the advertising of the device service for UART. I am forced to go to "Turn Off" under settings app. Then turn on device with BTN1 and then its restored functionality.
Is there a way to get the service before an app starts and then restore before it exits? Not sure how to work around this. I don't want my app to be destructive to the settings of the device, if you know what I mean.
Take a look here, for some specifics of my example:
https://github.com/d3nd3/bangle-remote/blob/main/ble_test.app.js -
• #3
On the Bangle,
Make Connectable
is really there to make sure you can connect even if you turned Bluetooth off withBLE:Off
in settings. As long as you leave Bluetooth on, there should be no need forNRF.wake()
.the nature of advertising is non stop broadcast at certain intervals yes? Since i'm only trying to send 1 signal(a button press), how should I design it?
Yep. I'd do it like this: http://www.espruino.com/BLE+Advertising
Basically have a counter, and increment that counter when you press the button. Advertise all the time - that way if you walk out of range, press the button, then walk back a few minutes later the button press can still get recorded.
Then I try to connect to bangle via web IDE after going to 'clock'/'home'. It doesn't connect.
If you've gone home with BTN3 then I'm surprised about that, unless your code is set to run in the background of every app? I guess it's possible Espruino doesn't reset advertising when it reloads an app, but I really thought it did :(
Is there a way to get the service before an app starts and then restore before it exits?
Actually yes, just call
setAdvertising({},{})
on theE.kill
event: http://www.espruino.com/Reference#l_E_kill -
• #4
If you've gone home with BTN3 then I'm surprised about that, unless your code is set to run in the background of every app? I guess it's possible Espruino doesn't reset advertising when it reloads > an app, but I really thought it did :(
I tested it again, can't seem to produce my initial results. It 100% still advertises, but it does have the data previously set from the app, which doesn't seem to be a problem to me. That E.kill trick might be useful in the future though.
But can I ask a question, what is purpose of Bluetooth: ON if it requires you to press Make Connectable every time you toggle it ON? Is it only for outbound usage of bluetooth, like scanning other devices and connecting to others? But not inbound?
-
• #5
I did some further testing. It turns out that something else is breaking the bluetooth. Namely from outside when I try to connect with ide and it fails, then Make Connectable doesn't work/recover it unless I use 'Turn Off' feature.
-
• #6
what is purpose of Bluetooth: ON if it requires you to press Make Connectable every time you toggle it ON?
It doesn't - or it shouldn't. Once Bluetooth is ON you should be good to go.
Make Connectable doesn't work/recover it unless I use 'Turn Off' feature.
Is it possible that some other device is trying to connect to it in the background?
-
• #7
Is it possible that some other device is trying to connect to it in the background?
Well, I'm using Node-red via EspruinoHub Debug printing the advertising? Does that count as a connection? not sure. It does have written "Connected" in green by the MQTT Listener In.
I'm trying hard to reproduce the bug, but its very hard.. :(
-
• #8
what is purpose of Bluetooth: ON if it requires you to press Make Connectable every time you toggle it ON?
It doesn't - or it shouldn't. Once Bluetooth is ON you should be good to go.
Make Connectable doesn't work/recover it unless I use 'Turn Off' feature.
Is it possible that some other device is trying to connect to it in the background?
Okay, well I can see the current behavior is that ,
"Make Connectable"
is controllingNRF.wake
andNRF.sleep
. Its also settingble.ON
andble.OFF
.If we agree that
NRF.wake
is that which triggers 'advertising' packets andble.ON
does not callNRF.wake
anywhere, its understandable why its necessary to pressMake Connectable
afterble.ON
. I just find its confusing a bit counter-intuitive to have an extra setting that seems to do same task. Under the hood there is only the wake and sleep? And thats for bothadvertising
and other bluetooth features like scanning and outbound GATT requests?Of course when you reload clock/home , it is calling
NRF.sleep
if ble.Off. But there is no where to be foundNRF.wake
?If however, the purpose of
Make connectable
is to separate functionality, inbound/outbound, there still remains an issue withMake connectable:No
as it setsBLE.off
, which would disableALL
features? That might not be the case if outbound ble requests will automatic wake from NRF.sleep, BUT it would be strange that a device can do bluetooth operations whilst user knowing a setting named bluetooth is set to off in settings.TLDR
: BLE.on means NRF.Sleep won't be called when clock is loaded /reset. But its notactually
on until NRF.Wake is called by an app or in our case "Make Connectable" in settings app. -
• #9
EspruinoHub ... Does that count as a connection?
No, not unless you explicitly tell it to connect, or connect via the
http://pi:1888/ide
ble.ON does not call NRF.wake anywhere
Bluetooth advertising being on (eg
NRF.wake()
) should be the default state after a new app is loaded, so there should be no reason to callNRF.wake()
normally since it'll already be awake...Unless I am missing something here?
-
• #10
Bluetooth advertising being on (eg NRF.wake()) should be the default state after a new app is loaded, so there should be no reason to call NRF.wake() normally since it'll already be awake...
This is only true if you have pressed MakeConnectable :Yes , atleast
once
since bluetooth option has been turned on.I wasn't fully aware that the default state was Wake(), so thx for clearing that up. So the nuisance is reduced down to having to press it Once. But think of the situation that a 3rd party app calls sleep() for whatever reason, then MakeConnectable will have to be pressed again. Do you see where i'm coming from? HM.
-
• #11
This is only true if you have pressed MakeConnectable :Yes , atleast once since bluetooth option has been turned on.
I'm still not sure I understand. If you turn the Bluetooth option on, then long-press BTN3, the Bangle should be connectable even without calling
Make Connectable
.But think of the situation that a 3rd party app calls sleep() for whatever reason, then MakeConnectable will have to be pressed again. Do you see where i'm coming from? HM.
In this case, the second you exit that app with a long-press of BTN3, Bluetooth advertising should start again as if
NRF.sleep()
was never called. If that's not the case then it's definitely a bug that should be fixed though. -
• #12
I'm still not sure I understand. If you turn the Bluetooth option on, then long-press BTN3, the Bangle should be connectable even without calling Make Connectable.
This is
not
the case.If that's not the case then it's definitely a bug that should be fixed though.
Yes I think it is.
-
• #13
Ok, thanks for bearing with me. I just filed an issue for it here and I should get it fixed for 2v09: https://github.com/espruino/Espruino/issues/1975
I was certain advertising got reset, but it seems not. I think there's code that resets it if it detects advertising data stored, but if it's not stored then nothing gets reset
I am in the process of writing an app which communicates with EspruinoHub via bluetooth.
I am using the advertising method.
The app is intended to control a smart tv, by sending mqtt commands in node-red. I have a basic button press example working, now I'm reviewing its effectiveness.
I noticed that the bangle doesn't advertise unless "Make Connectable" is pressed in settings. I looked at settings app in BangleApps and see it called NRF.wake(). My question is : should my 'app' be calling NRF.wake() at start? Because if disable bluetooth : off, then bluetooth: on is not enough for it to restore functionality(it doesnt' start advertising on bluetooth: on settings). Is that intended?
I'm not sure, but I would think that 'Make Connectable' should be re-fired if bluetooth is turned on and off?
Another question: the nature of advertising is non stop broadcast at certain intervals yes? Since i'm only trying to send 1 signal(a button press), how should I design it? Is it bad for power to keep advertising whilst app is open, is it better if I like get some confirmation back that it received signal then cancel the advertising by setting data to {} or better yet calling NRF.sleep() after verified it target smartDevice got the message?
Edit: Decided to use setTimeout for setAdvertising, but still have some uncertainties regarding restoring advertising defaults.
Thanks in advance.!