Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to write into server #3

Open
matak opened this issue Nov 25, 2021 · 11 comments
Open

Impossible to write into server #3

matak opened this issue Nov 25, 2021 · 11 comments

Comments

@matak
Copy link

matak commented Nov 25, 2021

There is no output from console.log in service 22222222-3333-4444-5555-666666666669.

I assume that the write data was not received? How to debug this?

For testing i used BLE scanner and nRF Connect.

@matak
Copy link
Author

matak commented Nov 25, 2021

onPartialWrite works, but onWrite never raise

@Emill
Copy link
Owner

Emill commented Nov 25, 2021

Hi. Do you use the "Full GATT Server Example (Peripheral)" as is in the readme?

@matak
Copy link
Author

matak commented Nov 25, 2021

yes, without any changes

@Emill
Copy link
Owner

Emill commented Nov 25, 2021

Hmm that works fine for me when I just tested. You could try to have "sudo btmon" running in another terminal. Then start and run the example, connect through nRF Connect and write something to that characteristic. By doing so I get the following output in btmon:

< HCI Command: Reset (0x03|0x0003) plen 0                                        #1 [hci0] 3.624676
> HCI Event: Command Complete (0x0e) plen 4                                      #2 [hci0] 3.752367
      Reset (0x03|0x0003) ncmd 1
        Status: Success (0x00)
< HCI Command: Read BD ADDR (0x04|0x0009) plen 0                                 #3 [hci0] 3.759412
> HCI Event: Command Complete (0x0e) plen 10                                     #4 [hci0] 3.762975
      Read BD ADDR (0x04|0x0009) ncmd 1
        Status: Success (0x00)
        Address: 00:15:83:75:96:CD (IVT corporation)
< HCI Command: LE Clear White List (0x08|0x0010) plen 0                          #5 [hci0] 3.766473
> HCI Event: Command Complete (0x0e) plen 4                                      #6 [hci0] 3.769836
      LE Clear White List (0x08|0x0010) ncmd 1
        Status: Success (0x00)
< HCI Command: LE Read White List Size (0x08|0x000f) plen 0                      #7 [hci0] 3.771980
> HCI Event: Command Complete (0x0e) plen 5                                      #8 [hci0] 3.775464
      LE Read White List Size (0x08|0x000f) ncmd 1
        Status: Success (0x00)
        Size: 25
< HCI Command: Set Event Mask (0x03|0x0001) plen 8                               #9 [hci0] 3.779154
        Mask: 0x2000800000008090
          Disconnection Complete
          Encryption Change
          Hardware Error
          Encryption Key Refresh Complete
          LE Meta
> HCI Event: Command Complete (0x0e) plen 4                                     #10 [hci0] 3.782353
      Set Event Mask (0x03|0x0001) ncmd 1
        Status: Success (0x00)
< HCI Command: LE Set Event Mask (0x08|0x0001) plen 8                           #11 [hci0] 3.783480
        Mask: 0x000000000000001f
          LE Connection Complete
          LE Advertising Report
          LE Connection Update Complete
          LE Read Remote Used Features Complete
          LE Long Term Key Request
> HCI Event: Command Complete (0x0e) plen 4                                     #12 [hci0] 3.786223
      LE Set Event Mask (0x08|0x0001) ncmd 1
        Status: Success (0x00)
< HCI Command: LE Read Buffer Size (0x08|0x0002) plen 0                         #13 [hci0] 3.787328
> HCI Event: Command Complete (0x0e) plen 7                                     #14 [hci0] 3.791180
      LE Read Buffer Size (0x08|0x0002) ncmd 1
        Status: Success (0x00)
        Data packet length: 0
        Num data packets: 0
< HCI Command: Read Buffer Size (0x04|0x0005) plen 0                            #15 [hci0] 3.792652
> HCI Event: Command Complete (0x0e) plen 11                                    #16 [hci0] 3.797193
      Read Buffer Size (0x04|0x0005) ncmd 1
        Status: Success (0x00)
        ACL MTU: 310  ACL max packet: 10
        SCO MTU: 64   SCO max packet: 8
< HCI Command: LE Read Supported States (0x08|0x001c) plen 0                    #17 [hci0] 3.798652
> HCI Event: Command Complete (0x0e) plen 12                                    #18 [hci0] 3.803167
      LE Read Supported States (0x08|0x001c) ncmd 1
        Status: Success (0x00)
        States: 0x000000001fffffff
          Non-connectable Advertising State
          Scannable Advertising State
          Connectable Advertising State
          High Duty Cycle Directed Advertising State
          Passive Scanning State
          Active Scanning State
          Initiating State
            and Connection State (Master Role)
          Connection State (Slave Role)
          Non-connectable Advertising State
            and Passive Scanning State
          Scannable Advertising State
            and Passive Scanning State
          Connectable Advertising State
            and Passive Scanning State
          High Duty Cycle Directed Advertising State
            and Passive Scanning State
          Non-connectable Advertising State
            and Active Scanning State
          Scannable Advertising State
            and Active Scanning State
          Connectable Advertising State
            and Active Scanning State
          High Duty Cycle Directed Advertising State
            and Active Scanning State
          Non-connectable Advertising State
            and Initiating State
          Scannable Advertising State
            and Initiating State
          Non-connectable Advertising State
            and Connection State (Master Role)
          Scannable Advertising State
            and Connection State (Master Role)
          Non-connectable Advertising State
            and Connection State (Slave Role)
          Scannable Advertising State
            and Connection State (Slave Role)
          Passive Scanning State
            and Initiating State
          Active Scanning State
            and Initiating State
          Passive Scanning State
            and Connection State (Master Role)
          Active Scanning State
            and Connection State (Master Role)
          Passive Scanning State
            and Connection State (Slave Role)
          Active Scanning State
            and Connection State (Slave Role)
          Initiating State
            and Connection State (Master Role)
            and Master Role & Master Role
< HCI Command: LE Set Advertising Data (0x08|0x0008) plen 32                    #19 [hci0] 3.812689
        Length: 31
        Flags: 0x06
          LE General Discoverable Mode
          BR/EDR Not Supported
        Name (complete): MyDevice
        128-bit Service UUIDs (complete): 1 entry
          Vendor specific (22222222-3333-4444-5555-666666666666)
> HCI Event: Command Complete (0x0e) plen 4                                     #20 [hci0] 3.816195
      LE Set Advertising Data (0x08|0x0008) ncmd 1
        Status: Success (0x00)
< HCI Command: LE Set Advertising Parameters (0x08|0x0006) plen 15              #21 [hci0] 3.822349
        Min advertising interval: 62.500 msec (0x0064)
        Max advertising interval: 75.000 msec (0x0078)
        Type: Connectable undirected - ADV_IND (0x00)
        Own address type: Public (0x00)
        Direct address type: Public (0x00)
        Direct address: 00:00:00:00:00:00 (OUI 00-00-00)
        Channel map: 37, 38, 39 (0x07)
        Filter policy: Allow Scan Request from Any, Allow Connect Request from Any (0x00)
> HCI Event: Command Complete (0x0e) plen 4                                     #22 [hci0] 3.826196
      LE Set Advertising Parameters (0x08|0x0006) ncmd 1
        Status: Success (0x00)
< HCI Command: LE Set Advertise Enable (0x08|0x000a) plen 1                     #23 [hci0] 3.827096
        Advertising: Enabled (0x01)
> HCI Event: Command Complete (0x0e) plen 4                                     #24 [hci0] 3.832179
      LE Set Advertise Enable (0x08|0x000a) ncmd 1
        Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 19                                       #25 [hci0] 5.919560
      LE Connection Complete (0x01)
        Status: Success (0x00)
        Handle: 68
        Role: Slave (0x01)
        Peer address type: Random (0x01)
        Peer address: 5F:EF:5B:72:84:A2 (Resolvable)
        Connection interval: 45.00 msec (0x0024)
        Connection latency: 0 (0x0000)
        Supervision timeout: 5000 msec (0x01f4)
        Master clock accuracy: 0x00
> ACL Data RX: Handle 68 flags 0x02 dlen 11                                     #26 [hci0] 6.081913
      ATT: Read By Type Request (0x08) len 6
        Handle range: 0x0001-0xffff
        Attribute type: Unknown (0x2b3a)
< ACL Data TX: Handle 68 flags 0x00 dlen 9                                      #27 [hci0] 6.097745
      ATT: Error Response (0x01) len 4
        Read By Type Request (0x08)
        Handle: 0x0001
        Error: Attribute Not Found (0x0a)
> ACL Data RX: Handle 68 flags 0x02 dlen 11                                     #28 [hci0] 6.171081
      ATT: Read By Group Type Request (0x10) len 6
        Handle range: 0x0001-0xffff
        Attribute group type: Primary Service (0x2800)
> HCI Event: Number of Completed Packets (0x13) plen 5                          #29 [hci0] 6.172423
        Num handles: 1
        Handle: 68
        Count: 1
< ACL Data TX: Handle 68 flags 0x00 dlen 18                                     #30 [hci0] 6.173194
      ATT: Read By Group Type Response (0x11) len 13
        Attribute data length: 6
        Attribute group list: 2 entries
        Handle range: 0x0001-0x0004
        UUID: Generic Attribute Profile (0x1801)
        Handle range: 0x0005-0x0009
        UUID: Generic Access Profile (0x1800)
> ACL Data RX: Handle 68 flags 0x02 dlen 11                                     #31 [hci0] 6.261177
      ATT: Read By Group Type Request (0x10) len 6
        Handle range: 0x000a-0xffff
        Attribute group type: Primary Service (0x2800)
> HCI Event: Number of Completed Packets (0x13) plen 5                          #32 [hci0] 6.262271
        Num handles: 1
        Handle: 68
        Count: 1
< ACL Data TX: Handle 68 flags 0x00 dlen 26                                     #33 [hci0] 6.262914
      ATT: Read By Group Type Response (0x11) len 21
        Attribute data length: 20
        Attribute group list: 1 entry
        Handle range: 0x000a-0x0013
        UUID: Vendor specific (22222222-3333-4444-5555-666666666666)
> ACL Data RX: Handle 68 flags 0x02 dlen 11                                     #34 [hci0] 6.351151
      ATT: Read By Group Type Request (0x10) len 6
        Handle range: 0x0014-0xffff
        Attribute group type: Primary Service (0x2800)
> HCI Event: Number of Completed Packets (0x13) plen 5                          #35 [hci0] 6.352465
        Num handles: 1
        Handle: 68
        Count: 1
< ACL Data TX: Handle 68 flags 0x00 dlen 9                                      #36 [hci0] 6.353388
      ATT: Error Response (0x01) len 4
        Read By Group Type Request (0x10)
        Handle: 0x0014
        Error: Attribute Not Found (0x0a)
> ACL Data RX: Handle 68 flags 0x02 dlen 11                                     #37 [hci0] 6.441250
      ATT: Read By Type Request (0x08) len 6
        Handle range: 0x0001-0x0004
        Attribute type: Include (0x2802)
> HCI Event: Number of Completed Packets (0x13) plen 5                          #38 [hci0] 6.442621
        Num handles: 1
        Handle: 68
        Count: 1
< ACL Data TX: Handle 68 flags 0x00 dlen 9                                      #39 [hci0] 6.454065
      ATT: Error Response (0x01) len 4
        Read By Type Request (0x08)
        Handle: 0x0001
        Error: Attribute Not Found (0x0a)
> HCI Event: LE Meta Event (0x3e) plen 10                                       #40 [hci0] 6.488094
      LE Connection Update Complete (0x03)
        Status: Success (0x00)
        Handle: 68
        Connection interval: 7.50 msec (0x0006)
        Connection latency: 0 (0x0000)
        Supervision timeout: 5000 msec (0x01f4)
> ACL Data RX: Handle 68 flags 0x02 dlen 11                                     #41 [hci0] 6.493714
      ATT: Read By Type Request (0x08) len 6
        Handle range: 0x0001-0x0004
        Attribute type: Characteristic (0x2803)
> HCI Event: Number of Completed Packets (0x13) plen 5                          #42 [hci0] 6.494392
        Num handles: 1
        Handle: 68
        Count: 1
< ACL Data TX: Handle 68 flags 0x00 dlen 13                                     #43 [hci0] 6.497225
      ATT: Read By Type Response (0x09) len 8
        Attribute data length: 7
        Attribute data list: 1 entry
        Handle: 0x0002
        Value: 200300052a
> ACL Data RX: Handle 68 flags 0x02 dlen 11                                     #44 [hci0] 6.508668
      ATT: Read By Type Request (0x08) len 6
        Handle range: 0x0003-0x0004
        Attribute type: Characteristic (0x2803)
> HCI Event: Number of Completed Packets (0x13) plen 5                          #45 [hci0] 6.509551
        Num handles: 1
        Handle: 68
        Count: 1
< ACL Data TX: Handle 68 flags 0x00 dlen 9                                      #46 [hci0] 6.510530
      ATT: Error Response (0x01) len 4
        Read By Type Request (0x08)
        Handle: 0x0003
        Error: Attribute Not Found (0x0a)
> ACL Data RX: Handle 68 flags 0x02 dlen 9                                      #47 [hci0] 6.523689
      ATT: Find Information Request (0x04) len 4
        Handle range: 0x0004-0x0004
> HCI Event: Number of Completed Packets (0x13) plen 5                          #48 [hci0] 6.524427
        Num handles: 1
        Handle: 68
        Count: 1
< ACL Data TX: Handle 68 flags 0x00 dlen 10                                     #49 [hci0] 6.525999
      ATT: Find Information Response (0x05) len 5
        Format: UUID-16 (0x01)
        Handle: 0x0004
        UUID: Client Characteristic Configuration (0x2902)
> ACL Data RX: Handle 68 flags 0x02 dlen 11                                     #50 [hci0] 6.538809
      ATT: Read By Type Request (0x08) len 6
        Handle range: 0x0005-0x0009
        Attribute type: Include (0x2802)
> HCI Event: Number of Completed Packets (0x13) plen 5                          #51 [hci0] 6.539493
        Num handles: 1
        Handle: 68
        Count: 1
< ACL Data TX: Handle 68 flags 0x00 dlen 9                                      #52 [hci0] 6.540732
      ATT: Error Response (0x01) len 4
        Read By Type Request (0x08)
        Handle: 0x0005
        Error: Attribute Not Found (0x0a)
> ACL Data RX: Handle 68 flags 0x02 dlen 11                                     #53 [hci0] 6.553744
      ATT: Read By Type Request (0x08) len 6
        Handle range: 0x0005-0x0009
        Attribute type: Characteristic (0x2803)
< ACL Data TX: Handle 68 flags 0x00 dlen 20                                     #54 [hci0] 6.555418
      ATT: Read By Type Response (0x09) len 15
        Attribute data length: 7
        Attribute data list: 2 entries
        Handle: 0x0006
        Value: 020700002a
        Handle: 0x0008
        Value: 020900012a
> HCI Event: Number of Completed Packets (0x13) plen 5                          #55 [hci0] 6.555425
        Num handles: 1
        Handle: 68
        Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5                          #56 [hci0] 6.569687
        Num handles: 1
        Handle: 68
        Count: 1
> ACL Data RX: Handle 68 flags 0x02 dlen 11                                     #57 [hci0] 6.569904
      ATT: Read By Type Request (0x08) len 6
        Handle range: 0x0009-0x0009
        Attribute type: Characteristic (0x2803)
< ACL Data TX: Handle 68 flags 0x00 dlen 9                                      #58 [hci0] 6.571045
      ATT: Error Response (0x01) len 4
        Read By Type Request (0x08)
        Handle: 0x0009
        Error: Attribute Not Found (0x0a)
> ACL Data RX: Handle 68 flags 0x02 dlen 11                                     #59 [hci0] 6.583828
      ATT: Read By Type Request (0x08) len 6
        Handle range: 0x000a-0x0013
        Attribute type: Include (0x2802)
> HCI Event: Number of Completed Packets (0x13) plen 5                          #60 [hci0] 6.584554
        Num handles: 1
        Handle: 68
        Count: 1
< ACL Data TX: Handle 68 flags 0x00 dlen 9                                      #61 [hci0] 6.586567
      ATT: Error Response (0x01) len 4
        Read By Type Request (0x08)
        Handle: 0x000a
        Error: Attribute Not Found (0x0a)
> ACL Data RX: Handle 68 flags 0x02 dlen 11                                     #62 [hci0] 6.598728
      ATT: Read By Type Request (0x08) len 6
        Handle range: 0x000a-0x0013
        Attribute type: Characteristic (0x2803)
> HCI Event: Number of Completed Packets (0x13) plen 5                          #63 [hci0] 6.599417
        Num handles: 1
        Handle: 68
        Count: 1
< ACL Data TX: Handle 68 flags 0x00 dlen 27                                     #64 [hci0] 6.601578
      ATT: Read By Type Response (0x09) len 22
        Attribute data length: 21
        Attribute data list: 1 entry
        Handle: 0x000b
        Value: 0a0c0067666666666655554444333322222222
> ACL Data RX: Handle 68 flags 0x02 dlen 11                                     #65 [hci0] 6.613748
      ATT: Read By Type Request (0x08) len 6
        Handle range: 0x000c-0x0013
        Attribute type: Characteristic (0x2803)
> HCI Event: Number of Completed Packets (0x13) plen 5                          #66 [hci0] 6.614423
        Num handles: 1
        Handle: 68
        Count: 1
< ACL Data TX: Handle 68 flags 0x00 dlen 27                                     #67 [hci0] 6.615337
      ATT: Read By Type Response (0x09) len 22
        Attribute data length: 21
        Attribute data list: 1 entry
        Handle: 0x000d
        Value: 020e0068666666666655554444333322222222
> ACL Data RX: Handle 68 flags 0x02 dlen 11                                     #68 [hci0] 6.628716
      ATT: Read By Type Request (0x08) len 6
        Handle range: 0x000e-0x0013
        Attribute type: Characteristic (0x2803)
> HCI Event: Number of Completed Packets (0x13) plen 5                          #69 [hci0] 6.629572
        Num handles: 1
        Handle: 68
        Count: 1
< ACL Data TX: Handle 68 flags 0x00 dlen 27                                     #70 [hci0] 6.630887
      ATT: Read By Type Response (0x09) len 22
        Attribute data length: 21
        Attribute data list: 1 entry
        Handle: 0x000f
        Value: 08100069666666666655554444333322222222
> HCI Event: Number of Completed Packets (0x13) plen 5                          #71 [hci0] 6.644576
        Num handles: 1
        Handle: 68
        Count: 1
> ACL Data RX: Handle 68 flags 0x02 dlen 11                                     #72 [hci0] 6.644708
      ATT: Read By Type Request (0x08) len 6
        Handle range: 0x0010-0x0013
        Attribute type: Characteristic (0x2803)
< ACL Data TX: Handle 68 flags 0x00 dlen 27                                     #73 [hci0] 6.646575
      ATT: Read By Type Response (0x09) len 22
        Attribute data length: 21
        Attribute data list: 1 entry
        Handle: 0x0011
        Value: 1012006a666666666655554444333322222222
> ACL Data RX: Handle 68 flags 0x02 dlen 11                                     #74 [hci0] 6.658671
      ATT: Read By Type Request (0x08) len 6
        Handle range: 0x0012-0x0013
        Attribute type: Characteristic (0x2803)
> HCI Event: Number of Completed Packets (0x13) plen 5                          #75 [hci0] 6.659417
        Num handles: 1
        Handle: 68
        Count: 1
< ACL Data TX: Handle 68 flags 0x00 dlen 9                                      #76 [hci0] 6.659880
      ATT: Error Response (0x01) len 4
        Read By Type Request (0x08)
        Handle: 0x0012
        Error: Attribute Not Found (0x0a)
> ACL Data RX: Handle 68 flags 0x02 dlen 9                                      #77 [hci0] 6.673687
      ATT: Find Information Request (0x04) len 4
        Handle range: 0x0013-0x0013
< ACL Data TX: Handle 68 flags 0x00 dlen 10                                     #78 [hci0] 6.675158
      ATT: Find Information Response (0x05) len 5
        Format: UUID-16 (0x01)
        Handle: 0x0013
        UUID: Client Characteristic Configuration (0x2902)
> HCI Event: Number of Completed Packets (0x13) plen 5                          #79 [hci0] 6.676653
        Num handles: 1
        Handle: 68
        Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5                          #80 [hci0] 6.692307
        Num handles: 1
        Handle: 68
        Count: 1
> HCI Event: LE Meta Event (0x3e) plen 10                                       #81 [hci0] 6.755506
      LE Connection Update Complete (0x03)
        Status: Success (0x00)
        Handle: 68
        Connection interval: 45.00 msec (0x0024)
        Connection latency: 0 (0x0000)
        Supervision timeout: 5000 msec (0x01f4)
> ACL Data RX: Handle 68 flags 0x02 dlen 11                                    #82 [hci0] 13.658756
      ATT: Write Request (0x12) len 6
        Handle: 0x0010
          Data: 79656168
< ACL Data TX: Handle 68 flags 0x00 dlen 5                                     #83 [hci0] 13.668528
      ATT: Write Response (0x13) len 0
> HCI Event: Number of Completed Packets (0x13) plen 5                         #84 [hci0] 13.748991
        Num handles: 1
        Handle: 68
        Count: 1

The javascript console prints:

A new value was written: <Buffer 79 65 61 68>

@matak
Copy link
Author

matak commented Nov 25, 2021

javascript console

onPartialWrite true 0 ttttt onPartialWrite true 0 hhhh

btmon

`
Bluetooth monitor ver 5.50
= Note: Linux version 4.19.104-300.el8.armv7hl (armv7l) 0.213955
= Note: Bluetooth subsystem version 2.22 0.213971
= New Index: AA:AA:AA:AA:AA:AA (Primary,UART,hci0) [hci0] 0.213973
= Open Index: AA:AA:AA:AA:AA:AA [hci0] 0.213974
= Index Info: AA:AA:AA:AA:AA:AA (Broadcom Corporation) [hci0] 0.213976
@ USER Open: node (privileged) version 2.22 {0x0001} [hci0] 0.213978
@ MGMT Open: btmon (privileged) version 1.14 {0x0002} 0.214094

ACL Data RX: Handle 64 flags 0x02 dlen 11 #1 [hci0] 9.140043
ATT: Write Request (0x12) len 6
Handle: 0x0010
Data: 68686868
< ACL Data TX: Handle 64 flags 0x00 dlen 5 #2 [hci0] 9.143117
ATT: Write Response (0x13) len 0
HCI Event: Number of Completed Packets (0x13) plen 5 #3 [hci0] 9.362093
Num handles: 1
Handle: 64
Count: 1

`

using centos 8 on raspberry, instaled in node_modules

"dependencies": { "ble-host": "^1.0.3", "hci-socket": "^1.0.0" }

@matak
Copy link
Author

matak commented Nov 25, 2021

sorry now it starts to working, really dont understand it is few hours i tested again and again and now i get response, the only think what i did was to start btmon

@Emill
Copy link
Owner

Emill commented Nov 25, 2021

Note that, as written in the documentation at https://github.com/Emill/node-ble-host/blob/master/docs/api/gatt-server.md#characteristiconpartialwriteconnection-needsresponse-offset-value-callback, onPartialWrite overrides onWrite, so you should only have one of these two present in your code.

@matak
Copy link
Author

matak commented Nov 25, 2021

i know, but i tested before without partial, partial was just test if any write is made

@Emill
Copy link
Owner

Emill commented Nov 25, 2021

Not sure but maybe if you have modified the gatt db your phone could potentially incorrectly have cached the old gatt db so it becomes out of sync and therefore writes could fail. Otherwise if you can reproduce the issue I would appreciate a full btmon log.

@matak
Copy link
Author

matak commented Nov 25, 2021

thanks, now it works

P.S.: is there an example how the communication architecture should be build if i need answer?

i sent some message, for example command to list some values, and i need the anser to get me the list which i want to render on phone

so i should note that i am waiting for list, and waiting for read callback? after i write command like LIST?

when i received callback value of list, so i delete that i am waiting for and can continue in communication?

@Emill
Copy link
Owner

Emill commented Nov 25, 2021

A common approach is to use "Write Without Response" for the "commands" and then to use "Notifications" for delivering the response. Just make sure you have negotiated a large enough MTU so the response fits within the notification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants