This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Proper S110 cleanup on link loss/disconnect?

Folks, Here's a specific question and a larger question, of which the first is a part.

  1. What's the proper way to insure S110 BLE stack cleanup on disconnect due to link loss, especially so I can quickly restart advertising to reestablish the connection?

  2. Is there a document on "link management", i.e., handling link connections, reconnection attempts, possible peer error states, with or without bonding, etc., to try to keep two devices connected in as robust a way as possible?

Context: I'm using the S110 stack, version 5.1 on an nRF51822 (production version C0, IIRC) and SDK 4.4.2 (limited to this version by the IC prod. version). BTW, tried the version 6.0 stack but failed (probably because I didn't go through the migration instructions). Communicating with an iPhone 5, running iOS 7.1 and the current Core Bluetooth framework.

Problem: When the connection is running stably for awhile, I cause a disconnect (either by moving out of range or by killing the iPhone app). S110 senses disconnect and issues BLE_GAP_EVT_DISCONNECTED event, which my app picks up and sets the saved connection handle variable to BLE_CONN_HANDLE_INVALID. I use this to realize that I'm no longer connected and attempt to go back into advertising mode by regenerating the advertising params structure and calling sd_ble_gap_adv_start again. But it fails with error 8: "NRF_ERROR_INVALID_STATE Invalid state, operation disallowed in this state". So I'm clearly missing some cleanup step.

I've tried making sure the app-task/event queue is empty by running app_sched_execute() before starting advertising again, delaying 1 sec. to give the stack time to settle, both to no avail. BTW, is there an easy way to inquire as to the current state of the stack? I must have missed it.

Any comments and help appreciated,

Mike

Parents
  • Pål, Thanks for the feedback. At the app level, I have an FSM (Finite State Machine, implemented by a switch statement in C), so I shouldn't be calling advertising start multiple times. But there might be something happening at lower levels. I'll check. BTW, what's the S110 behavior if it loses connection and signals that to the app, causing the connection handle to go invalid, but goes back in range before the central tears down the connection. Will the S110 reconnect by itself? (Is this a possible situation? Too many error states and recovery paths to consider :-) Mike (who's going off to read the "best practices" section in the iOS Core Bluetooth documentation on link maintenance)

Reply
  • Pål, Thanks for the feedback. At the app level, I have an FSM (Finite State Machine, implemented by a switch statement in C), so I shouldn't be calling advertising start multiple times. But there might be something happening at lower levels. I'll check. BTW, what's the S110 behavior if it loses connection and signals that to the app, causing the connection handle to go invalid, but goes back in range before the central tears down the connection. Will the S110 reconnect by itself? (Is this a possible situation? Too many error states and recovery paths to consider :-) Mike (who's going off to read the "best practices" section in the iOS Core Bluetooth documentation on link maintenance)

Children
No Data
Related