This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to Keep Bond Alive?

[PLEASE READ THE EDIT FIRST]

So, first of all, I am new to bluethoot development and I am not 100% familiar with all the inner workings of the protocol.

I am trying to make a simple bluetooth FOB (some call it token) so I can use my Moto X 2nd Gen "trusted devices" functionality to keep the screen unlocked while the phone detects my FOB.

I have a Bluefruit LE which runs a nRF8001 connected to an Arduino Nano.

I got some project example files from Nordic and using the HID Keyboard with 2 bonds template worked very well.

The problem is, I don't want my phone showing a dummy external keyboard all the time, so I tried to make a new project of my own. I opened nRFgo Studio, and created a new Service with a new Characteristic, all empty will no pipes, and I changed the HID Keyboard template code and services.h.

So far the only thing I manage to do is to connect, bond, and then it loses the connection.

I get this output from the Serial line:

Port open
Arduino setup
Evt Device Started: Setup
Evt Device Started: Standby
Advertising started : Waiting to be connected and bonded
Evt Connected
Evt Bond Status
Disconnected/timed out
eeprom_write_offset
2
bond_number
0
Dynamic Data read and stored successfully
Already bonded : Advertising started : Waiting to be connected
Disconnected/timed out
Previous Bond present. Restoring bond 255     (this 255 seems odd but the code corrects it automatically to 0 before using it)
EEPROM Header (4 bytes):
84
2
1C
76
--

My code is kinda big to post in here so I posted it here and the nRFgo Studio's services.h here.

I would appreciate any help with this, I think it's just a little thing that's missing so I can finish this project and make it work.

Thanks a lot!!


EDIT 1

I just tried running the Proximity Template Example (yes, I should have started with this one, but I didn't see it in the list, my bad!).... and IT DIDN'T WORK TOO!

This is the Serial Monitor output for the Proximity Template:

Port open
Arduino setup
Evt Device Started: Setup
Evt Device Started: Standby
No Bond present in EEPROM.
Advertising started : Waiting to be connected and bonded
Evt Connected
Evt Pipe Status
Evt Pipe Status
Evt Pipe Status
phone Detected.
Do more stuff here. when your phone is detected
Evt link connection interval changed
Evt Disconnected. Link Lost or Advertising timed out
Dynamic Data read and stored successfully
Link Loss Alert: Alert level = 
NO_ALERT
Using existing bond stored in EEPROM.
   To delete the bond stored in EEPROM, connect Pin 6 to 3.3v and Reset.
   Make sure that the bond on the phone/PC is deleted as well.
Advertising started. Connecting.

This makes me very confused, because I believe this should be exactly the kind of service that this Moto X functionality should be waiting for. So, for the Keyboard, it works....but for a Proximity tag it doesn't?? What could be missing in the code? Maybe some heartbeat signal? Any clues?


EDIT 2

I downloaded the nRF Toolbox app and when I go to the Proximity option and click CONNECT, the phone says it's connected to the bluetooth device and the screen will remain unlocked...but if I close the app this is lost, the same way as if I clicked DISCONNECT.

What could be triggering this connection? Can I make it work the same way with an arduino code?

Related