PunchThrough / Bean-iOS-OSX-SDK

Punch Through's SDK for speeding up development with the LightBlue Bean development platform
MIT License
172 stars 51 forks source link

Connection 'flaps' when Bean goes out of range and comes back into range #3

Open paulw11 opened 10 years ago

paulw11 commented 10 years ago

I have found that if a Bean goes out of range while connected to a device and the device re-initiates a connection then when the device comes back into range, the connection will 'flap'. The bean disconnects with the didDisconnectBean: delegate method reporting -

Error: Error Domain=PTDBean Code=100 "Validation Failed. Retry count exceeded" UserInfo=0x17806bbc0 {NSLocalizedDescription=Validation Failed. Retry count exceeded} { NSLocalizedDescription = "Validation Failed. Retry count exceeded"; }

The bean then reconnects before disconnecting a short time later with the same message.

Increasing PROFILE_VALIDATION_RETRY_TIMEOUT to 100.0f in PTDBean.m seems to resolve the issue

raykamp commented 10 years ago

Hi Paul, thank you for the info. I'll look into the problem and have a fix shortly!

raykamp commented 10 years ago

Hi @paulw11 , I'm looking into this issue currently and having difficulty recreating or understanding the problem. Can you please explain what you mean by flapping?

Is the bean repeatedly connecting/disconnection indefinitely? Can you please share your code (or some of it) where you are implementing your PTDBeanManager delegate. Are you attempting to reconnect upon disconnection?

thank you -Ray

paulw11 commented 10 years ago

Hi,

Yes, I am auto reconnecting

The code is available here - https://github.com/paulw11/BeanLock

I have included part of the debug log below. The log starts from about the time I took the Bean out of range. You can see it disconnects, and then when I bring it back into range I get repeated connection problems that seem to be caused by the validation process timing out and resetting the connection. I found that if I increased the time allowed for validation then the problem goes away.

_2014-09-03 08:27:48.057 BeanLock[12582:60b] App Message Received: MSG_ID_SERIALDATA: <0a>

2014-09-03 08:28:11.318 BeanLock[12582:60b] centralManager:didDisconnectPeripheral <CBPeripheral: 0x1780a6060 identifier = C2CF7860-366D-2831-7E34-C0DEA2A19C03, Name = "Bean862", state = disconnected>

2014-09-03 08:28:11.320 BeanLock[12582:60b] Error in didDisconnectBean: The connection has timed out unexpectedly.

2014-09-03 08:28:25.481 BeanLock[12582:60b] centralManager:didConnectPeripheral <CBPeripheral: 0x1780a6060 identifier = C2CF7860-366D-2831-7E34-C0DEA2A19C03, Name = "Bean862", state = connected>

2014-09-03 08:28:25.484 BeanLock[12582:60b] Reset validaton retry count

2014-09-03 08:28:25.844 BeanLock[12582:60b] centralManager:didDisconnectPeripheral <CBPeripheral: 0x1780a6060 identifier = C2CF7860-366D-2831-7E34-C0DEA2A19C03, Name = "Bean862", state = disconnected>

2014-09-03 08:28:25.848 BeanLock[12582:60b] Error in didDisconnectBean: The connection has failed unexpectedly.

2014-09-03 08:28:25.989 BeanLock[12582:60b] Validation retry count=0

2014-09-03 08:28:25.991 BeanLock[12582:60b] CoreBluetooth[API MISUSE] <CBPeripheral: 0x1780a6060 identifier = C2CF7860-366D-2831-7E34-C0DEA2A19C03, Name = "Bean862", state = connecting> can only accept commands while in the connected state

2014-09-03 08:28:31.044 BeanLock[12582:60b] centralManager:didConnectPeripheral <CBPeripheral: 0x1780a6060 identifier = C2CF7860-366D-2831-7E34-C0DEA2A19C03, Name = "Bean862", state = connected>

2014-09-03 08:28:31.046 BeanLock[12582:60b] Reset validaton retry count

2014-09-03 08:28:31.550 BeanLock[12582:60b] Validation retry count=0

2014-09-03 08:28:31.865 BeanLock[12582:60b] DevInfoProfile: Device Information profile found

2014-09-03 08:28:31.867 BeanLock[12582:60b] OadProfile: OAD service found

2014-09-03 08:28:31.870 BeanLock[12582:60b] GattSerialProfile: GATT Serial Pass profile found

2014-09-03 08:28:31.873 BeanLock[12582:60b] BatteryProfile: Battery Monitoring profile found

2014-09-03 08:28:32.284 BeanLock[12582:60b] DevInfoProfile: Found all Device Information characteristics

2014-09-03 08:28:32.494 BeanLock[12582:60b] OadProfile: Found all OAD characteristics

2014-09-03 08:28:32.614 BeanLock[12582:60b] GattSerialProfile: Found all GATT Serial Pass characteristics

2014-09-03 08:28:32.734 BeanLock[12582:60b] BatteryProfile: Found all Battery Monitoring characteristics

2014-09-03 08:28:32.794 BeanLock[12582:60b] DevInfoProfile: Device Firmware Version Found

2014-09-03 08:28:32.944 BeanLock[12582:60b] OadProfile: OAD Characteristic set to "Notify"

2014-09-03 08:28:33.064 BeanLock[12582:60b] GattSerialProfile: Gatt Serial Characteristic set to "Notify"

2014-09-03 08:28:33.066 BeanLock[12582:60b] Stopped scanning.

2014-09-03 08:28:33.274 BeanLock[12582:60b] BatteryProfile: Battery Monitor Characteristic set to "Notify"

2014-09-03 08:28:33.333 BeanLock[12582:60b] BatteryProfile: Battery Level Found: 2.5425 Volts

_2014-09-03 08:28:33.338 BeanLock[12582:60b] App Message Received: MSG_ID_CC_TEMPREAD: <14>

2014-09-03 08:28:35.992 BeanLock[12582:60b] Validation retry count=1

2014-09-03 08:28:35.997 BeanLock[12582:60b] DevInfoProfile: Device Information profile found

2014-09-03 08:28:35.999 BeanLock[12582:60b] DevInfoProfile: Found all Device Information characteristics

2014-09-03 08:28:36.001 BeanLock[12582:60b] OadProfile: OAD service found

2014-09-03 08:28:36.003 BeanLock[12582:60b] OadProfile: OAD Characteristics of peripheral found

2014-09-03 08:28:36.005 BeanLock[12582:60b] GattSerialProfile: GATT Serial Pass profile found

2014-09-03 08:28:36.007 BeanLock[12582:60b] GattSerialProfile: Found all Gatt Serial characteristics

2014-09-03 08:28:36.009 BeanLock[12582:60b] BatteryProfile: Battery Monitoring profile found

2014-09-03 08:28:36.011 BeanLock[12582:60b] BatteryProfile: Found all Battery Monitoring characteristics

2014-09-03 08:28:36.064 BeanLock[12582:60b] DevInfoProfile: Device Firmware Version Found

2014-09-03 08:28:36.124 BeanLock[12582:60b] BatteryProfile: Battery Monitor Characteristic set to "Notify"

2014-09-03 08:28:36.244 BeanLock[12582:60b] BatteryProfile: Battery Level Found: 2.525 Volts

2014-09-03 08:28:45.995 BeanLock[12582:60b] Validation retry count=2

2014-09-03 08:28:45.997 BeanLock[12582:60b] Error: Error Domain=PTDBean Code=100 "Validation Failed. Retry count exceeded" UserInfo=0x178267580 {NSLocalizedDescription=Validation Failed. Retry count exceeded} {

}

2014-09-03 08:28:46.000 BeanLock[12582:60b] Error in didConnectToBean: Validation Failed. Retry count exceeded

2014-09-03 08:28:46.002 BeanLock[12582:60b] centralManager:didDisconnectPeripheral <CBPeripheral: 0x1780a6060 identifier = C2CF7860-366D-2831-7E34-C0DEA2A19C03, Name = "Bean862", state = disconnected>

2014-09-03 08:28:46.012 BeanLock[12582:60b] centralManager:didConnectPeripheral <CBPeripheral: 0x1780a6060 identifier = C2CF7860-366D-2831-7E34-C0DEA2A19C03, Name = "Bean862", state = connected>

2014-09-03 08:28:46.013 BeanLock[12582:60b] Reset validaton retry count

2014-09-03 08:28:46.516 BeanLock[12582:60b] Validation retry count=0

2014-09-03 08:28:46.521 BeanLock[12582:60b] DevInfoProfile: Device Information profile found

2014-09-03 08:28:46.523 BeanLock[12582:60b] OadProfile: OAD service found

2014-09-03 08:28:46.525 BeanLock[12582:60b] GattSerialProfile: GATT Serial Pass profile found

2014-09-03 08:28:46.528 BeanLock[12582:60b] BatteryProfile: Battery Monitoring profile found

2014-09-03 08:28:46.532 BeanLock[12582:60b] DevInfoProfile: Found all Device Information characteristics

2014-09-03 08:28:46.534 BeanLock[12582:60b] OadProfile: Found all OAD characteristics

2014-09-03 08:28:46.537 BeanLock[12582:60b] GattSerialProfile: Found all GATT Serial Pass characteristics

2014-09-03 08:28:46.539 BeanLock[12582:60b] BatteryProfile: Found all Battery Monitoring characteristics

2014-09-03 08:28:46.542 BeanLock[12582:60b] GattSerialProfile: Error trying to set Characteristic to "Notify"

2014-09-03 08:28:46.544 BeanLock[12582:60b] BatteryProfile: Error trying to set Battery Monitor Characteristic to "Notify"

2014-09-03 08:28:46.545 BeanLock[12582:60b] GattSerialProfile: Error trying to set Characteristic to "Notify"

2014-09-03 08:28:46.547 BeanLock[12582:60b] BatteryProfile: Error trying to set Battery Monitor Characteristic to "Notify"

2014-09-03 08:28:46.548 BeanLock[12582:60b] GattSerialProfile: Error trying to set Characteristic to "Notify"

2014-09-03 08:28:46.550 BeanLock[12582:60b] BatteryProfile: Error trying to set Battery Monitor Characteristic to "Notify"

2014-09-03 08:28:46.757 BeanLock[12582:60b] centralManager:didDisconnectPeripheral <CBPeripheral: 0x1780a6060 identifier = C2CF7860-366D-2831-7E34-C0DEA2A19C03, Name = "Bean862", state = disconnected>

2014-09-03 08:28:46.759 BeanLock[12582:60b] Error in didDisconnectBean: Unknown error.

2014-09-03 08:28:48.085 BeanLock[12582:60b] centralManager:didConnectPeripheral <CBPeripheral: 0x1780a6060 identifier = C2CF7860-366D-2831-7E34-C0DEA2A19C03, Name = "Bean862", state = connected>

2014-09-03 08:28:48.087 BeanLock[12582:60b] Reset validaton retry count

2014-09-03 08:28:48.590 BeanLock[12582:60b] Validation retry count=0

2014-09-03 08:28:48.794 BeanLock[12582:60b] DevInfoProfile: Device Information profile found

2014-09-03 08:28:48.797 BeanLock[12582:60b] OadProfile: OAD service found

2014-09-03 08:28:48.800 BeanLock[12582:60b] GattSerialProfile: GATT Serial Pass profile found

2014-09-03 08:28:48.802 BeanLock[12582:60b] BatteryProfile: Battery Monitoring profile found

2014-09-03 08:28:49.035 BeanLock[12582:60b] DevInfoProfile: Found all Device Information characteristics

2014-09-03 08:28:49.214 BeanLock[12582:60b] OadProfile: Found all OAD characteristics

2014-09-03 08:28:49.335 BeanLock[12582:60b] GattSerialProfile: Found all GATT Serial Pass characteristics

2014-09-03 08:28:49.454 BeanLock[12582:60b] BatteryProfile: Found all Battery Monitoring characteristics

2014-09-03 08:28:49.514 BeanLock[12582:60b] DevInfoProfile: Device Firmware Version Found

2014-09-03 08:28:49.634 BeanLock[12582:60b] OadProfile: OAD Characteristic set to "Notify"

2014-09-03 08:28:49.754 BeanLock[12582:60b] GattSerialProfile: Gatt Serial Characteristic set to "Notify"

2014-09-03 08:28:49.756 BeanLock[12582:60b] Stopped scanning.

2014-09-03 08:28:49.994 BeanLock[12582:60b] BatteryProfile: Battery Monitor Characteristic set to "Notify"

2014-09-03 08:28:50.054 BeanLock[12582:60b] BatteryProfile: Battery Level Found: 2.5425 Volts

_2014-09-03 08:28:50.058 BeanLock[12582:60b] App Message Received: MSG_ID_CC_TEMPREAD: <14>

2014-09-03 08:28:56.519 BeanLock[12582:60b] Validation retry count=1

2014-09-03 08:28:56.524 BeanLock[12582:60b] DevInfoProfile: Device Information profile found

2014-09-03 08:28:56.526 BeanLock[12582:60b] DevInfoProfile: Found all Device Information characteristics

2014-09-03 08:28:56.528 BeanLock[12582:60b] OadProfile: OAD service found

2014-09-03 08:28:56.530 BeanLock[12582:60b] OadProfile: OAD Characteristics of peripheral found

2014-09-03 08:28:56.532 BeanLock[12582:60b] GattSerialProfile: GATT Serial Pass profile found

2014-09-03 08:28:56.534 BeanLock[12582:60b] GattSerialProfile: Found all Gatt Serial characteristics

2014-09-03 08:28:56.535 BeanLock[12582:60b] BatteryProfile: Battery Monitoring profile found

2014-09-03 08:28:56.538 BeanLock[12582:60b] BatteryProfile: Found all Battery Monitoring characteristics

2014-09-03 08:28:56.565 BeanLock[12582:60b] DevInfoProfile: Device Firmware Version Found

2014-09-03 08:28:56.624 BeanLock[12582:60b] BatteryProfile: Battery Monitor Characteristic set to "Notify"

2014-09-03 08:28:56.684 BeanLock[12582:60b] BatteryProfile: Battery Level Found: 2.56 Volts

2014-09-03 08:29:06.522 BeanLock[12582:60b] Validation retry count=2

2014-09-03 08:29:06.524 BeanLock[12582:60b] Error: Error Domain=PTDBean Code=100 "Validation Failed. Retry count exceeded" UserInfo=0x170276240 {NSLocalizedDescription=Validation Failed. Retry count exceeded} {

}

2014-09-03 08:29:06.527 BeanLock[12582:60b] Error in didConnectToBean: Validation Failed. Retry count exceeded

2014-09-03 08:29:06.530 BeanLock[12582:60b] centralManager:didDisconnectPeripheral <CBPeripheral: 0x1780a6060 identifier = C2CF7860-366D-2831-7E34-C0DEA2A19C03, Name = "Bean862", state = disconnected>

2014-09-03 08:29:06.539 BeanLock[12582:60b] centralManager:didConnectPeripheral <CBPeripheral: 0x1780a6060 identifier = C2CF7860-366D-2831-7E34-C0DEA2A19C03, Name = "Bean862", state = connected>

On Wed, Sep 3, 2014 at 3:23 AM, kamp0145 notifications@github.com wrote:

Hi @paulw11 https://github.com/paulw11 , I'm looking into this issue currently and having difficulty recreating or understanding the problem. Can you please explain what you mean by flapping?

Is the bean repeatedly connecting/disconnection indefinitely? Can you please share your code (or some of it) where you are implementing your PTDBeanManager delegate. Are you attempting to reconnect upon disconnection?

thank you -Ray

— Reply to this email directly or view it on GitHub https://github.com/PunchThrough/Bean-iOS-OSX-SDK/issues/3#issuecomment-54186558 .

peterworth commented 9 years ago

Hi, what's the status with this issue now? I have the exact same problem, setting PROFILE_VALIDATION_RETRY_TIMEOUT higher made a big difference (very glad i found this thread - thanks paul!), but it still happens occasionally

raykamp commented 9 years ago

@peterworth, we are in the process of reworking the connection process. So this issue will soon be resolved in the next major release.

For now, does it help if you set PROFILE_VALIDATION_RETRIES to be 1 ?