I can pair but I can't send commands

Hi,

With fimware version 2.6.6, I don’t know why when I try to read status Nuki, via bluetooth, I always get the same issue:

[D][blecentral.cpp:296] get_context(): Loading pairing context from nvs
[D][blecentral.cpp:313] get_context(): 
app_id 3468362736
auth_id 3431672

[D][nuki.cpp:207] create_challenge_payload(): CL Request Data 10 bytes (Unencrypted):
F0  03  BB  CE  01  00  0C  00 
F6  53 
[D][nuki.cpp:94] encrypt_payload(): client is encrypting payload message 10 bytes...
[D][nuki.cpp:100] encrypt_payload(): Authorization_id = CEBB03F0
[D][nuki.cpp:104] encrypt_payload(): crypto_secretbox_xsalsa20poly1305 (c,m,mlen,n,k)
[D][nuki.cpp:105] encrypt_payload(): m : 
F0  03  BB  CE  01  00  0C  00 
F6  53 
[D][nuki.cpp:107] encrypt_payload(): mlen : 10 
[D][nuki.cpp:108] encrypt_payload(): n : 
88  0E  64  B5  7B  32  CA  BE 
B0  B4  16  88  93  05  EB  E7 
25  FC  12  5C  5A  90  24  06 
[D][nuki.cpp:110] encrypt_payload(): k : 
5E  7E  F2  24  AD  E7  D5  EE 
A5  10  B4  52  6D  17  6E  F7 
B4  BF  07  0D  46  8F  7E  1B 
05  21  56  7F  EC  EA  7A  48 
[D][nuki.cpp:59] current_state(): Request lock state: CL sends 56 bytes.
 53  8C  D0  8F  08  12  FA  83 
 F6  21  44  AC  33  BB  EF  9F 
 0F  B9  01  F2  9C  89  B8  87 
 F0  03  BB  CE  1A  00  0A  BF 
 DD  DD  83  0F  34  85  39  48 
 D1  59  A1  56  AA  2D  59  AA 
 8B  2D  13  33  AB  52  2F  A9  

[D][nuki.cpp:338] processMessage(): client receives 7 bytes from uuid a92ee201-5501-11e4-916c-0800200c9a66
[D][nuki.cpp:339] processMessage(): expected indication message KEYTURNER_STATES_IND
        12  00  20  00  00  13  D7 
[E][nuki.cpp:479] get_commandId(): Command Id: ERROR_REPORT >> K_ERROR_NOT_AUTHORIZED.

I’m using the following parameters to make encryption message:

#define CRYPTO_SECRETBOX_KEYBYTES 32U
#define CRYPTO_PUBLIC_KEYBYTES 32U
#define CRYPTO_SCALARMULT_BYTES 32U
#define CRYPTO_SECRETBOX_NONCEBYTES 24U
#define crypto_secretbox_NONCEBYTES CRYPTO_SECRETBOX_NONCEBYTES 
#define CRYPTO_SECRETBOX_ZEROBYTES 32U
#define CRYPTO_SECRETBOX_MACBYTES 16U
#define crypto_secretbox_MACBYTES CRYPTO_SECRETBOX_MACBYTES
#define CRYPTO_AUTH_HMAC_BYTES 32U

The Diffie-Hellman key function dh1

crypto_scalarmult_curve25519(s,sk,pk)

static const unsigned char _0[16];

static const unsigned char sigma[17] = “expand 32-byte k”;

crypto_core_hsalsa20(k,_0,s,sigma)

The authentication function h1

HMAC-SHA256

crypto_secretbox_xsalsa20poly1305 (c,m,mlen,n,k)

Below You can see how I get the shared key:

[D][nuki.cpp:35] pairing(): Start Pairing: CL sends 0 bytes.
 [D][nuki.cpp:234] create_request_public_key_payload(): client is sending request public key...
01  00  03  00  27  A7 
[D][nuki.cpp:338] processMessage(): client receives 20 bytes from uuid a92ee101-5501-11e4-916c-0800200c9a66
[D][nuki.cpp:339] processMessage(): expected indication message PUBLIC_KEY_IND
  03  00  76  3F  24  FE  D3  6A 
  46  3C  2C  41  93  F5  09  BE 
  B4  C3  E2  8D 
  78  7E  DE  25  69  20  35  B0 
  FA  35  F0  24  C4  3B  58  92 
[D][nuki.cpp:483] get_commandId(): Command Id: PUBLIC_KEY.
[D][nuki.cpp:360] send_response(): Received Public Key
[D][nuki.cpp:244] create_write_public_key_payload(): client is sending client public key...
[D][nuki.cpp:362] send_response(): client sends 36 bytes:
 03  00  88  12  89  23  9E  5E 
 4A  3F  1C  37  72  B7  57  AF 
 91  67  ED  20  BF  ED  11  86 
 FF  66  C5  D9  9F  4D  DA  49 
 74  22  2F  51 
[D][nuki.cpp:338] processMessage(): client receives 20 bytes from uuid a92ee101-5501-11e4-916c-0800200c9a66
[D][nuki.cpp:339] processMessage(): expected indication message CHALLENGE_AUTHENTICATION_IND
  04  00  28  60  D0  74  66  FC 
  DC  97  5B  8D  0B  03  C5  5E 
  D4  82  EC  FD 
  41  0C  23  DF  8A  28  3B  51 
  C9  FA  18  8E  97  41  4F  36 
[D][nuki.cpp:349] processMessage(): Process this message [36 bytes]
[D][nuki.cpp:373] send_response(): Received challenge for authenticator
[D][nuki.cpp:257] create_authorization_authenticator_payload(): client is sending authorization authenticator...
[D][nuki.cpp:269] create_authorization_authenticator_payload(): The key derivation function kdf1 - crypto_core_hsalsa20(k,_0,s,sigma): shared secret calculated
  5E  7E  F2  24  AD  E7  D5  EE 
  A5  10  B4  52  6D  17  6E  F7 
  B4  BF  07  0D  46  8F  7E  1B 
  05  21  56  7F  EC  EA  7A  48 
[D][nuki.cpp:279] create_authorization_authenticator_payload(): The The authentication function h1 HMAC-SHA256: authentication calculated
  28  AA  E4  D2  3C  F5  C2  A1 
  12  2B  DE  2E  03  7B  4F  CD 
  00  A5  CD  CA  AF  5E  9E  A9 
  BB  7D  0D  54  80  BA  2D  BD 
[D][nuki.cpp:375] send_response(): client sends 36 bytes:
  05  00  28  AA  E4  D2  3C  F5 
  C2  A1  12  2B  DE  2E  03  7B 
  4F  CD  00  A5  CD  CA  AF  5E 
  9E  A9  BB  7D  0D  54  80  BA 
  2D  BD  29  F6 

Thank you!