title: Can't disconnect from bonded BLE device
body: <p>I'm creating application on Android where I have to talk with Microchip's RN4020 Bluetooth Low Energy module. I have to create bond with this module to exchange data and everything was working fine few days ago.</p>
  
  <p>Now yesterday from nowhere I noticed that if I lost connection or terminated connection intentionally with RN4020 I couldn't reconnect to it because to reconnect in my application I have to 1st listen for direct advertisement which is happening only if device is not connected at the given moment. I checked using UART what info my RN4020 is giving me. If I didn't bond devices and connected/disconnected multiple times UART gave me</p>
  
  <blockquote>
    <p>Connected</p>
    
    <p>Connection End</p>
    
    <p>Connected</p>
    
    <p>Connection End</p>
    
    <p>Connected</p>
    
    <p>Connection End</p>
    
    <p>...</p>
  </blockquote>
  
  <p>Now If I bonded devices, the same code gave me me only</p>
  
  <blockquote>
    <p>Connected</p>
  </blockquote>
  
  <p>Even though <code>Android Monitor</code> tab in <code>Android Studio</code> confirmed that disconnection and closing <code>BluetoothGatt</code> is done, my RN4020 didn't agree with that.</p>
  
  <p>I also downloaded another free application from <code>Play Store</code> which can connect to BLE devices and read/write characteristics. Same thing happened there. If bond is not created with RN4020 I can connect and disconnect as many times I want without problems but when bond is created my phone just stays connnected to RN4020 unless I turn off Bluetooth completely. Then after turning it back on I can catch its direct advertising but when I connect I again can't disconnect.</p>
  
  <p>Can anyone give me any idea whats going on?</p>
  
  <hr>
  
  <p><strong>EDIT :</strong> One more thing - When I go to <code>Application Manager</code> on my phone (Galaxy S4 active / Lolipop), click to Running -> Bluetooth I can see it kind of states 1 process and 11 services are running. One of these services are <code>BleAutoConnectService</code>. But anyway it doesn't change anything if I turn it off.</p>
  
  <hr>
  
  <p><strong>EDIT nr 2 :</strong> When I yesterday tested it with my friends Sony Xperia (I think it was <code>Z</code>) this happened : When creating fresh bond with RN4020 I got the following messages on UART</p>
  
  <blockquote>
    <p>Connected<br>
                                                    ConnParam: 0006,0000,07D0<br>
                                                       Bonded<br>
                                                        ConnParam: 0027,0000,07D0<br>
                                                        ConnParam: 0006,0000,07D0<br>
                                                        ConnParam: 0027,0000,07D0<br>
                                                          Connection End</p>
  </blockquote>
  
  <p>so at least that phone got disconnected after bonding. This is what datasheet says about <code>ConnParam</code>:</p>
  
  <blockquote>
    <p>When connected and connection parameters are updated by the  peer
    device, message “ConnParam” is sent to the UART. Message  “ConnParam”
    has three 16-bit parameters, which are connection  interval, slave
    latency and supervision timeout respectively.</p>
  </blockquote>
  
  <p>and when I sent <strong>'D'</strong> command to RN4020 to display critical information about it, it gave me </p>
  
  <blockquote>
    <p>Bonded=FFFFFFFFFFFF,<strong>1</strong>    //1 stands for private/random MAC address</p>
  </blockquote>
  
  <p>but <strong>with my device</strong> I was just getting</p>
  
  <blockquote>
    <p>Connected<br>
    Bonded  </p>
  </blockquote>
  
  <p>and <strong>'D'</strong> command gave me </p>
  
  <blockquote>
    <p>Bonded=FFFFFFFFFFFF,<strong>0</strong>    //0 stands for public MAC address</p>
  </blockquote>
  
  <p><strong>So yesterday I decided to sleep on it but today everything works just fine. I can connect and disconnect whether devices are bonded or not from my own phone how many times I want.</strong> I have no clue why is this happening and what to do with this random behavior.</p>