Ok, I just looked at this and it's to do with HID by the look of it.
The setAddress call actually returns: INVALID_STATE which Nordic say is:
The identity address cannot be changed while the roles are running.
Which I believe means the address can't be changed while something like HID is set up.
Just FYI, you can do:
var err = "";
function onInit() {
LoopbackA.setConsole();
LoopbackB.on('data',d=>err+=d);
Then when you connect again you can see if there were any messages printed to the console.
Anyway... if you try and set the address before (as you have done) then I believe adding HID requires a softdevice restart, which loses the new address :(
So it may be possible for me to modify the firmware so it remembers that the address should be changed and then modifies it each time the softdevice restarts, but right now I think that setDevice on the current firmware won't work for you.
However:
I want to connect it to my phone, use it to pass a string of characters to the phone (based on an event), then (based on another event) I want to disconnect the Puck from the phone (without touching the phone) and have it not auto-reconnect to the phone.
It seems from this that what you want is actually a lot simpler than that. I assumed you wanted to be able to connect with another device while stopping the phone connecting, but if you just want to stop any device connecting to Puck.js, simply use NRF.sleep().
NRF.sleep() will disconnect Bluetooth and stop advertising (which makes it look like it's just disappeared/gone out of range). Just call NRF.wake() when you want to wake up and it'll start advertising and the phone will reconnect
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Ok, I just looked at this and it's to do with HID by the look of it.
The
setAddress
call actually returns:INVALID_STATE
which Nordic say is:Which I believe means the address can't be changed while something like HID is set up.
Just FYI, you can do:
Then when you connect again you can see if there were any messages printed to the console.
Anyway... if you try and set the address before (as you have done) then I believe adding HID requires a softdevice restart, which loses the new address :(
So it may be possible for me to modify the firmware so it remembers that the address should be changed and then modifies it each time the softdevice restarts, but right now I think that
setDevice
on the current firmware won't work for you.However:
It seems from this that what you want is actually a lot simpler than that. I assumed you wanted to be able to connect with another device while stopping the phone connecting, but if you just want to stop any device connecting to Puck.js, simply use
NRF.sleep()
.NRF.sleep()
will disconnect Bluetooth and stop advertising (which makes it look like it's just disappeared/gone out of range). Just callNRF.wake()
when you want to wake up and it'll start advertising and the phone will reconnect