Skip to content

Commit

Permalink
nRF5x: Fix INVALID_PARAM error when connecting to other BLE device wh…
Browse files Browse the repository at this point in the history
…en maxInterval or NRF.setLowPowerConnection specified
  • Loading branch information
gfwilliams committed Jan 8, 2024
1 parent 91e45d6 commit d594469
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
ESP8266/others: Fix ArrayBuffers with 12 bit JsVars (previously they overflowed)
Ensure E.setDST disables E.setTimeZone, and vice-versa.
Added console.debug/info/warn/error as aliases of console.log
nRF5x: Fix INVALID_PARAM error when connecting to other BLE device when maxInterval or NRF.setLowPowerConnection specified

2v19 : Fix Object.values/entries for numeric keys after 2v18 regression (fix #2375)
nRF52: for SD>5 use static buffers for advertising and scan response data (#2367)
Expand Down
9 changes: 9 additions & 0 deletions targets/nrf5x/bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -3450,6 +3450,15 @@ void jsble_central_connect(ble_gap_addr_t peer_addr, JsVar *options) {
v = jsvGetFloatAndUnLock(jsvObjectGetChildIfExists(options,"maxInterval"));
if (!isnan(v)) gap_conn_params.max_conn_interval = (uint16_t)(MSEC_TO_UNITS(v, UNIT_1_25_MS)+0.5);
}
/* From NRF SDK: If both conn_sup_timeout and max_conn_interval are specified, then the following constraint applies:
conn_sup_timeout * 4 > (1 + slave_latency) * max_conn_interval
that corresponds to the following Bluetooth Spec requirement:
The Supervision_Timeout in milliseconds shall be larger than
(1 + Conn_Latency) * Conn_Interval_Max * 2, where Conn_Interval_Max is given in milliseconds.
*/
unsigned int minSupTimeout = (((1+gap_conn_params.slave_latency) * gap_conn_params.max_conn_interval) + 4) >> 2; // round up (ceil)
if (gap_conn_params.conn_sup_timeout < minSupTimeout)
gap_conn_params.conn_sup_timeout = minSupTimeout;

ble_gap_addr_t addr;
addr = peer_addr;
Expand Down

0 comments on commit d594469

Please sign in to comment.