Connection Seems to Hang

The mechanism for detecting a broken connection may not be working or may be having problems. I am using an Arduino Nano 33 IoT. Frequently, when connecting to a peripheral (using peripheral.connect()) the code would crash, specifically when the RSSI power detected was -80 dBm or less. I have since modified that from comments suggested by other users to include a "minimum good RSSI" level detector, which seems to work about 90% of the time when I set the limit to -78 dBM (anything equal or greater is allowed to connect, otherwise I force a disconnect).

My code detects the "unacceptable" power level and does bail out, but sometimes it takes a while, and I suspect the .connect() routine may not be working so well. Here is my code for detecting a connection:

  if (peripheral.connect() && (txPower >= MIN_GOOD_RSSI)) {

Here is an example of a connection attempt to a peripheral that is about 17 feet away through two walls:

16:18:50.636 -> Found fa:cc:44:74:60:53 'myPeripheral' 0xf009
16:18:50.636 -> Scanning stopped
16:18:50.636 ->  Connecting ... Peripheral disconnected
16:18:51.105 ->  failed to connect!  (power level = -86 dBm)             // 500 ms - slow but I'll take it
16:18:51.105 ->  *** Connection failure - ignoring device ***
16:18:51.105 -> Scanning started
16:18:51.198 -> TABLE DATA: devCount = 1 servCount = 4 charCount = 12 descCount = 1
16:18:51.245 -> 
16:18:51.245 -> Found fa:cc:44:74:60:53 'myPeripheral' 0xf009
16:18:51.245 -> Scanning stopped
16:18:51.245 ->  Connecting ... Peripheral disconnected                  // 200 ms - somewhat better
16:18:51.433 ->  failed to connect!  (power level = -86 dBm)
16:18:51.433 ->  *** Connection failure - ignoring device ***
16:18:51.433 -> Scanning started
16:18:51.527 -> TABLE DATA: devCount = 1 servCount = 4 charCount = 12 descCount = 1
16:18:51.573 -> 
16:18:51.573 -> Found fa:cc:44:74:60:53 'myPeripheral' 0xf009
16:18:51.573 -> Scanning stopped
16:18:51.573 ->  Connecting ... Peripheral disconnected                  // 5 seconds - what the what?
16:18:56.542 ->  failed to connect!  (power level = -87 dBm)
16:18:56.542 ->  *** Connection failure - ignoring device ***
16:18:56.589 -> Scanning started
16:18:56.683 -> TABLE DATA: devCount = 1 servCount = 4 charCount = 12 descCount = 1

I don't know what's going on with the connect() member function but it seems like it's doing some deep thinking regarding how stable the radio link actually is. In any case, sometimes, this part will just hang forever, and since I don't have any visibility into it I would suspect there is a call or a return from a NINA register that is not happening.

What would be nice is a couple of things. First, a way to clear the NINA (and maybe some ARM) registers that are responsible for profile data. I am having problems seeing duplicate advertised "ghost" services and descriptors that seem to be from a previous scan. Second, a watchdog timer for the Nano that allows you to slap Uncle SAMD every now and then when it falls asleep.

These are just suggestions for the Arduino Gods/Goddesses to ponder. I am just a mortal trying to understand his place in this universe.

  • Fred