I'm having a problem at the moment with code based on Espruino on nrf52.
I connect as follows:
memset(&m_scan_param, 0, sizeof(m_scan_param));
m_scan_param.active = 1; // Active scanning set.
m_scan_param.interval = MSEC_TO_UNITS(100, UNIT_0_625_MS); // Scan interval.
m_scan_param.window = MSEC_TO_UNITS(90, UNIT_0_625_MS); // Scan window.
m_scan_param.timeout = 4; // 4 second timeout.
memset(&gap_conn_params, 0, sizeof(gap_conn_params));
gap_conn_params.min_conn_interval = MSEC_TO_UNITS(7.5, UNIT_1_25_MS);
gap_conn_params.max_conn_interval = MSEC_TO_UNITS(500, UNIT_1_25_MS);
gap_conn_params.slave_latency = 0;
gap_conn_params.conn_sup_timeout = MSEC_TO_UNITS(4000, UNIT_10_MS);
addr = peer_addr;
err_code = sd_ble_gap_connect(&addr, &m_scan_param, &gap_conn_params);
Connecting from one device running Espruino to another (both nRF52832DK), and 65.5 seconds after getting a BLE_GAP_EVT_CONNECTED the DK acting as central Espruino gets a BLE_GAP_EVT_DISCONNECTED event. Every time it disconnects, and every time it takes 65.5 seconds.
This doesn't happen when a PC/Android phone acts as Central connecting to a DK, and it doesn't happen when a DK acting as central connects to something else. It's only when one DK connects to another.
Any idea what might be the problem?
If needed I can supply a hex file and the sample code to reproduce this.
Original Sniffer trace (sniffingbroken?): nrf52dk_disconnect.pcapng
Connected, start notifications, send one notification, then it exits
These traces I just connected it and didn't do anything else:
Android nRF Connect -> DK trace (disconnected by me after 70s) : nrf52dk_android.pcapng
iOS nRF Connect -> DK trace (disconnected by me after 70s) : nrf52dk_ios_nrfconnect.pcapng
DK -> DK trace (disconnected itself after 65.5s) : nrf52dk_espruino.pcapng
Have you checked the reason that you get with the disconnected event?
Thanks - I wasn't even aware that existed! It's BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION - so I guess 'remote user' is the DK as a peripheral. The only times I personally call disconnect on the peripheral are BLE_GATTC_EVT_TIMEOUT/BLE_GATTS_EVT_TIMEOUT - and I just checked and those events don't get received
The peripheral reports BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION - but I'm certain I'm not calling sd_ble_gap_disconnect. Is there some kind of 'heartbeat' that the peripheral is expecting but doesn't get?
I don't think you will get BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION without calling sd_ble_gap_disconnect(), but I'm not 100%. Are you absolutely sure you are not calling sd_ble_gap_disconnect()?
Yes, pretty sure. I guess it could be called from one of Nordic's libs - eg ble-conn-params - but I'd expected that if it did, I'd get a different reason than BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION, since it sends BLE_HCI_CONN_INTERVAL_UNACCEPTABLE?