This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Pairing and key exhange with ANCS

Hi.

I've started to check if I can get ANCS compatible content provider to run in Android. The nrf52 is running out-of-box version of the nordic ancs example.

I can find it, see that it solicitates the ANCS service in the advertisement and I can try to connect it. However as it's not paired, the connection fails right away. I've read the apple developer page about the ANCS and also nordic explanation about the example.

So the problem is that I guess I need to bond the devices and exchange trusted keys. I've tried the bonding, but after the mBluetoothDevice.createBond(), the BluetoothDevice.ACTION_BOND_STATE_CHANGED- callback I get has status BOND_NONE and oldstate was BOND_BONDING. How this key-exchange is supposed to be handled? Am I missing something here?

So far I've added the service for the ANCS:

UUID: "7905F431-B5CE-4E99-A40F-4B1E122D00D0" (main service)

three characteristics for it:

  • Notification source (with CCCD)
  • Notification data source (with CCCD)
  • Notification control point (with CCCD)

The service is added to gatt server in the android side, I get the callback for the service added, and the device seems to try to connect the gatt service, but it drops it right away. I'm trying the pairing before any other connection to device or the callbacks to connectionStateChange.

EDIT: Log from nRF MCP:

I	14:51:29.845	[Server] Device with address CE:CE:67:C2:71:FE connected
D	14:51:29.858	[Broadcast] Action received:    android.bluetooth.device.action.BOND_STATE_CHANGED, bond state changed to: BOND_BONDING (11)
I	14:51:29.872	Connected to CE:CE:67:C2:71:FE
D	14:51:29.882	gatt.close()
D	14:51:29.892	[Server callback] Connection state changed with status: 0 and new state: DISCONNECTED (0)
D	14:51:30.054	wait(600ms)
I	14:51:30.077	[Server] Device disconnected
D	14:51:35.774	[Server callback] Connection state changed with status: 0 and new state: CONNECTED (2)
I	14:51:35.811	[Server] Device with address CE:CE:67:C2:71:FE connected
D	14:51:35.825	[Broadcast] Action received: android.bluetooth.device.action.BOND_STATE_CHANGED, bond state changed to: BOND_NONE (10)
I	14:51:35.841	Bonding failed
V	14:51:35.852	Connecting to CE:CE:67:C2:71:FE...
D	14:51:35.862	[Broadcast] Action received: android.bluetooth.device.action.ACL_CONNECTED
D	14:51:35.884	[Broadcast] Action received: android.bluetooth.device.action.ACL_DISCONNECTED
D	14:51:35.896	gatt = device.connectGatt(autoConnect = false)
D	14:51:35.914	[Server callback] Connection state changed with status: 0 and new state: DISCONNECTED (0)
D	14:51:35.934	gatt.close()
I	14:51:35.953	[Server] Device disconnected
D	14:51:35.968	[Server callback] Connection state changed with status: 0 and new state: DISCONNECTED (0)
I	14:51:35.982	[Server] Device disconnected
  • Ok, I have that installed. I also found some logging from the nRF MCP and it's attached to question above. Also I've got HCL logs open in wireshark. Anything specific I could check from those?

    And yes, the nRF52 with example works just fine with iPhone. And what I'm trying to do here, is to get similar communication protocol for android app so that we do not have to have both ANS and ANCS supports in the nRF board.

  • Hi Matts,

    Please capture the sniffer trace.

    And please test bonding with any example such as the proximity example. From the nRF MCP log, it's showing that the device disconnect in the pairing process. Have you made sure you don't exceed the maximum number of bonded central ?

  • And just to clarify:

    Just trying to connect with nRF MCP app with the nrf52 + ANCS example app fails similarily as my app.

    I also tested the proximity example, and I couldn't pair it, nor connect to it with nRF control panel. I get error 129 (0x81) GATT INTERNAL ERROR and Error 8 (0x08): GATT CONN TIMEOUT.

  • I suspect there could be something wrong with the phone. Could you try to test with other phone ? Also a reset on the current phone is worth to try.

    Could you check if there is any assert on the nRF52 ? Did it reset when the bonding failed ?

    Also please let me know the chip revision and the SDK, softdevice version you are testing .

  • Hi.

    No asserts with the nrf board. the board version is PCA10040 V1.1.0 2016.9 SDK is nRF5_SDK_11.0.0_89a8197.

    I'll try to get another phone HW. I was involved with another project related to bluetooth year a go. We run into situation in android end that something in non-volatile data corrupted (some setting or something) and it didn't recover without several reboots and removal of battery. This might be similar case.

    Regarding sniffer: How should I sniff the connection? I mean I have only one nrf board. Can I connect to sniffer with the android and use the siffer to analyze the connection? The setup in the instructions seems to be that two separate devices communicate and sniffer just sniffs in the side.

Related