Gatttool stop receiving notification after seconds (Not because of disconnection)

1.1k Views Asked by At

I use gattool to connect with BLE device on Linux virtual machine(Ubuntu). There are three roles in the system: peripheral, central, and laptop(only receiving logging info for debugging)

After connecting, I need to send out a message to the peripheral so that it will send out logging information to Linux when the central interacts with the peripheral. So my code is like this:

connect
# cmd for the peripheral sending out logging
char-write-cmd 0x000f 70
# enable notification
char-write-req 0x000c 0100 --listen

It can print out the notification normally, if the peripheral can keep sending out logging to laptop. But if the peripheral stops sending out the logging for (4-5) seconds, and resumes after that, the laptop will no longer print out the message. But it is not disconnected, because I can still write to the peripheral and receive normal feedback after that. And also no error like (gatttool:5840): GLib-WARNING **: Invalid file descriptor.

What's the possible reason for it and how can to fix it? Thanks!

Sample result:

[02:02:02:02:02:02][LE]> connect 
Attempting to connect to 02:02:02:02:02:02
Connection successful
[02:02:02:02:02:02][LE]> char-write-cmd 0x000f 70
listen:02:02:02:02][LE]> char-write-req 0x000c 0100 --l
Characteristic value was written successfully
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 31 0d 0a 
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 31 0d 0a 
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 30 0d 0a 
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 31 0d 0a 
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 30 0d 0a 
[02:02:02:02:02:02][LE]> char-write-cmd 0x000f 01
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 31 0d 0a 
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 30 0d 0a 
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 31 0d 0a 
Notification handle = 0x000b value: 31 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 64 00 00 

After testing, I think it's more close to "receive the notification and store it, but does not print it out to the terminal until the next command to the gatttool" If I send out some commands to the peripheral, which means the peripheral will also send some commands to the laptop, it will print out the "saved" notifications no matter what next command to gatttool is. Test result:

[02:02:02:02:02:02][LE]> char-desc
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 30 0d 0a 
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 30 0d 0a 
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 30 0d 0a 
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 30 0d 0a 
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 30 0d 0a 
handle: 0x0001, uuid: 00002800-0000-1000-8000-00805f9b34fb
handle: 0x0002, uuid: 00002803-0000-1000-8000-00805f9b34fb

[02:02:02:02:02:02][LE]> char-read-hnd 0x0007
Notification handle = 0x000b value: 4f 55 54 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 35 0d 0a 
Notification handle = 0x000b value: 50 4f 53 5f 49 4e 53 31 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 35 0d 0a 
Notification handle = 0x000b value: 50 4f 53 5f 49 4e 53 31 5f 4e 4f 5f 4d 4f 54 0d 0a 
Notification handle = 0x000b value: 43 4d 44 3a 30 35 0d 0a 
Characteristic value/descriptor: 08 00 10 00 00 00 64 00 

The result from btmon. The peripheral sends out the notifications at around 19:36:30, but the timestamp on btmon is 19:37 when I send another cmd on Linux.

> ACL Data RX: Handl.. flags 0x02 dlen 5  #40 [hci0] 2019-10-18 19:36:13.577156
      ATT: Write Response (0x13) len 0
< ACL Data TX: Handl.. flags 0x00 dlen 9  #41 [hci0] 2019-10-18 19:37:02.057819
      ATT: Write Request (0x12) len 4
        Handle: 0x000c
          Data: 0100
> ACL Data RX: Hand.. flags 0x02 dlen 19  #42 [hci0] 2019-10-18 19:37:02.154325
      ATT: Handle Value Notification (0x1b) len 14
        Handle: 0x000b
          Data: 4f55545f4e4f5f4d4f540d0a
0

There are 0 best solutions below