DevAcademy Bluetooth LE connection problems

Hi,

I am going through the DevAcademy Bluetooth LE lessons, using nRF5 DK. But I run into problems directly in the exercise of the first lesson. Everything goes fine to step 4.2, but connecting doesn’t work. Connection is established, but almost immediately disconnection happens. LED2 is lit for a short moment. The print outs are like this:

No matter how many times I try, disconnection always happens this way. I have also tested to connect via the Bluetooth low energy desktop app using the Nordic BLE dongle. Then the connection works fine. I have tested with both nRF Connect SDK 2.3.0 and 2.0.0, and the scenario is the same for both versions.

In the desktop app it is possible to read the button state and activate notifications (and receive updates when the button is pressed). But I am not able to control LED3. I have put a breakpoint in write_led() in lbs.c (C:\...\v2.3.0\nrf\subsys\bluetooth\services\lbs.c), but the breakpoint isn't hit when I write to the LED characteristic. Though, a breakpoint in read_button() will be hit when I click "Nordic LED and Button Service", so I should be in the correct file.

 

Best regards,

Lars

Parents
  • Hello

    What phone and OS are you using when the connection doesn't work? It could be the case that the connection parameters aren't compatible with your phone OS or something similar.

    If you could set up a BLE sniffer and share logs of the communication between your devices as the disconnection happens, that would be very helpful.

    Best regards,

    Einar

  • Hi,

    I have a Samsung S21 5G with Android version 13. My computer runs Windows 10.

    Now I have installed the BLE Sniffer and captured some communication. In this file I should have recorded two attempts to connect.

    Best regards,
    Lars

    4214.Capture.pcapng

  • Lars M said:
    In this file I should have recorded two attempts to connect.

    You also seem to have recorded a lot of other things.

    If you could let me know which of these addresses belong to your devices, I might be able to help you.

  • Yes, I know there is a lot of data. I am new to this and have problems with filtering. So a fast solution now was to take my laptop and go to a place where there should be no other BLE-devices within range. I have added two capture files, one with only the dk powered, and one where I have turned on Bluetooth on my phone and tried to connect two times. I am quite confuced around what is captured. I thought the DK, phone and computer would be the only BLE devices around, but there are more Sources than three. How come? Can my phone and computer have several sources? Is it possible to figure out what is happening when the connection doesn't work?

    Capture dk.pcapng

    Capture dk and phone, 2 tries.pcapng

  • Lars M said:
    I thought the DK, phone and computer would be the only BLE devices around

    Seems like these are the only devices around this time from what I can see.

    f7 seems to be your DK, 35 has a Microsoft tag so I assume that's your laptop, 5a has a Google tag and seems to be your Android phone scanning for devices.

    But yes your phone seems to use a different source when trying to connect.

    What I think is weird is that after the initial connect packet from your phone, nothing more seems to happen until your DK continues advertising 500ms later.

    Are you filtering for LE LL packets? In that case I would be interested in seeing this log without such a filter because some of the communication on setting up a connection happens on different protocols.

    With that said, this is what error code 42 refers to:

    Might be a problem specific to your phone, have you tried with other Android phones?

    -Einar

  • Now I have captured another bunch of data. It seems that I have succeeded in filtering my DK-data.

    I have only this selected:

    I guess this selects LE LL, correct?

    I have also made this selection:

    I’m not sure what selection I had when I captured previous files, but now I get more info about the communication. Does this tell you something more interesting?

    I have not yet tested with another phone, but will hopefully have the possibility pretty soon.

    In the files from my previous post there were only my DK, phone and computer. But quite a lot of addresses were present, of which may appear just a few times. What are these addresses?

    Capture dk and phone, 3 tries.pcapng

  • Hi

    Lars M said:

    now I get more info about the communication. Does this tell you something more interesting?

    Yes this data is more interesting! You can see the devices set up a connection, negotiating connection parameters. Your DK requests to use 2M PHY, your phone acknowledges this and then starts sending read requests, but the strange part is that your DK never seems to answer any of these requests, so the phone repeats this request every 50ms for 5 seconds until it reaches a timeout. I'm not entirely sure why this happens, but it looks like the DK never receives these requests, maybe something goes wrong when the connection is supposed to swap to 2M PHY..

    Lars M said:

    In the files from my previous post there were only my DK, phone and computer. But quite a lot of addresses were present, of which may appear just a few times. What are these addresses?

    The random addresses that seem to just appear once I believe are from corrupted BLE packets. Not sure if this happens when the packet is sent or when it is sniffed, but I don't think those are real addresses, just corrupted data.

    I have put a breakpoint in write_led() in lbs.c

    Also, don't think this is the current issue, but you should avoid breakpoints when doing BLE, breakpoints in BLE functions can break BLE entirely.

    -Einar

Reply
  • Hi

    Lars M said:

    now I get more info about the communication. Does this tell you something more interesting?

    Yes this data is more interesting! You can see the devices set up a connection, negotiating connection parameters. Your DK requests to use 2M PHY, your phone acknowledges this and then starts sending read requests, but the strange part is that your DK never seems to answer any of these requests, so the phone repeats this request every 50ms for 5 seconds until it reaches a timeout. I'm not entirely sure why this happens, but it looks like the DK never receives these requests, maybe something goes wrong when the connection is supposed to swap to 2M PHY..

    Lars M said:

    In the files from my previous post there were only my DK, phone and computer. But quite a lot of addresses were present, of which may appear just a few times. What are these addresses?

    The random addresses that seem to just appear once I believe are from corrupted BLE packets. Not sure if this happens when the packet is sent or when it is sniffed, but I don't think those are real addresses, just corrupted data.

    I have put a breakpoint in write_led() in lbs.c

    Also, don't think this is the current issue, but you should avoid breakpoints when doing BLE, breakpoints in BLE functions can break BLE entirely.

    -Einar

Children
  • Hi,

    Packet number 214 is LL_PHY_REQ seems to contain some error. Can that give a clue to why there is problem with the communication?

    It seems that the time between the requests is 50 ms in the beginning, packet number 219 – 223. But then the read requests come much more frequent, about 7 – 8 ms (maybe 7.5 ms?).

    There is a gap in communication (of about 5 sec) after the last read request. Why is that?

    When the phone sends read requests, the red LED on my nRF52840 dongle is lit. Maybe it is turned on when packet number 214 arrives to the dongle? The LED is turned off after the 5 sec communication gap.

    Also, don't think this is the current issue, but you should avoid breakpoints when doing BLE, breakpoints in BLE functions can break BLE entirely.

    Yes, I know that breakpoints in BLE-applications probably will cause the application to crash. But setting a breakpoint and coming there will give a proof that the program comes to a certain row. And since I didn’t see expected behaviour of LED3, I put a breakpoint there to see if the code was executed. Which it wasn’t.

    Best regards,

    Lars

  • Lars M said:
    Packet number 214 is LL_PHY_REQ seems to contain some error.

    Yes, I was looking at that one, if you look at its contents it's saying that the DK prefers 2M PHY. In packet 217 the phone responds "2M PHY shall be used".

    Lars M said:
    But then the read requests come much more frequent, about 7 – 8 ms (maybe 7.5 ms?)

    Hm, it looks like you're right, and it looks like in packet 213 the phone sets the connection interval to 7,5ms so I guess that makes sense. I can't see the DK acknowledging that though, maybe that transaction is interrupted by packet 214.

    Lars M said:
    There is a gap in communication (of about 5 sec) after the last read request. Why is that?

    Hm, maybe the DK doesn't start timing out until the phone stops sending requests.

    It would be very interesting to see a capture with another phone that is able to communicate successfully to have something to compare this with, I might try later today if I have time.

    -EInar

  • Hi Einar,

    Now I have tested nRF Connect for Desktop, and captured a sequence. Everything seems to work fine. I have connected, clicked in nRF Connect for Desktop to update button status, I have activated notifications and pressed the button, I have turned on and off the LED, and I have disconnected. I guess it would look something like this when using the phone?

    /Lars

    Capture nRF Connect for Desktop.pcapng

  • Now I have tested to connect via another phone, a Samsung Galaxy A13 5G. Everything seems to work fine: connection, reading button status, button notifications, controlling the LED and disconnecting. I have attached the Wireshark file where all these features are tested. Obviously, something differs from my first phone (Samsung Galaxy S21 5G). There is an opcode, LL_CONNECTION_UPDATE_IND, that is present in the communication where things don’t work. That is where the 7.5 ms connection interval is set. Can that be the problem?

    After CONNECT_IND is sent from a phone, the next few opcodes differ in order between the two phones. Why is that? Does It matter?

    I also notice that the RGB_LED is lit red on my nRF52840 dongle (with the sniffer firmware) as long as the connection is established. Is that correct?

    /Lars

    Capture dk and second phone.pcapng

  • Lars M said:
    There is an opcode, LL_CONNECTION_UPDATE_IND, that is present in the communication where things don’t work. That is where the 7.5 ms connection interval is set. Can that be the problem?

    Yes this seems to be the main difference I can see. You could try to set a minimum preferred connection interval in your peripheral's prj.conf file:

    CONFIG_BT_PERIPHERAL_PREF_MIN_INT=[number]

    You could for instance set it to 39, which seems to be the connection interval with the other phone.

    Lars M said:
    After CONNECT_IND is sent from a phone, the next few opcodes differ in order between the two phones. Why is that? Does It matter?

    It looks like the phones are doing the same things just in a slightly different order, I don't think it should matter.

    Lars M said:

    I also notice that the RGB_LED is lit red on my nRF52840 dongle (with the sniffer firmware) as long as the connection is established. Is that correct?

    I'm not sure what the led is supposed to indicate and I'm not sure where it's documented, but indicating an established connection would make sense yes.

    -Einar

Related