No Connecting After going away

Hi everyone,

I implement nrf5_SDK_17.0.2 ble_app_uart example and I use an android app like nRF_Connect to receive the uart data on my phone.

My problem is that when I go away from the place I cannot connect again after coming back. So I need to reset my nrf52840 DK first, and then I can connect my phone to my nrf52840 DK.

What is the trick?

Thanks.

Parents
  • Hello,

    My problem is that when I go away from the place I cannot connect again after coming back. So I need to reset my nrf52840 DK first, and then I can connect my phone to my nrf52840 DK.

    What is the trick?

    Have you verified that the peripheral device is still advertising when you return to it? How long are you gone for?
    Could it be that the advertising duration has expired, and so the device has stopped advertising and gone into SYSTEM_OFF sleep? This is the default behavior of the BLE NUS example, if you have not changed this.

    Best regards,
    Karl

  • Hi Karl,

    Thanks for your replay. I came back sooner, so I could connect my phone to the DK.

  • rezaei said:
    Thanks for your replay.

    No problem at all, I am happy to help!

    rezaei said:
    I came back sooner, so I could connect my phone to the DK.

    Great, so then it likely was that the advertising timed out. To avoid this being an issue in the future you could either increase the advertising duration, or set it to 0 which means unlimited advertising duration - which never times out. The main drawback of this is that the device will use a lot of power over time, if there is little to no chance for a connection happening for a certain duration of time.

    Best regards,
    Karl

  • Thank you from your description.

    I have a question. I want to know when I'm going away from the ble area. How can I know that? I want to show this notification.

  • rezaei said:
    I have a question. I want to know when I'm going away from the ble area. How can I know that? I want to show this notification.

    By this, do you mean that you would like to show a notification in your application when you are getting further away from the device, or that would like to show this notification once you are too far away from the device - i.e the connection is broken?
    In the former case, you could potentially use RSSI to judge this, but RSSI is not a very reliable estimate for distance since it is influenced by so many other factors such as line of sight, environment noise, packet reflections etc.

    Best regards,
    Karl

Reply
  • rezaei said:
    I have a question. I want to know when I'm going away from the ble area. How can I know that? I want to show this notification.

    By this, do you mean that you would like to show a notification in your application when you are getting further away from the device, or that would like to show this notification once you are too far away from the device - i.e the connection is broken?
    In the former case, you could potentially use RSSI to judge this, but RSSI is not a very reliable estimate for distance since it is influenced by so many other factors such as line of sight, environment noise, packet reflections etc.

    Best regards,
    Karl

Children
  • Hi Karl,

    I try to show RSSI in my app, but after connecting the RSSI is always 0.

    This is my code:

    BleManager.getInstance().connect(mac_id, new BleGattCallback() {
                @Override
                public void onStartConnect() {
                    
                }
    
                @Override
                public void onConnectFail(BleDevice bleDevice, BleException exception) {
    
                }
    
                @Override
                public void onConnectSuccess(BleDevice bleDevice, BluetoothGatt gatt, int status) {
                    Toast.makeText(getContext(), String.valueOf(bleDevice.getRssi()), Toast.LENGTH_LONG).show();
                }
    
                @Override
                public void onDisConnected(boolean isActiveDisConnected, BleDevice device, BluetoothGatt gatt, int status) {
    
                }
            })

    What do you think?

  • rezaei said:
    I try to show RSSI in my app, but after connecting the RSSI is always 0.

    If I recall correctly you will have to enable RSSI readings before using the get function, if you have not done so already. Also, RSSI is in relation to each packet that the device receives.

    Please keep in mind my earlier comment about RSSI being a poorly accurate measurement for distance. You can find multiple tickets here on the forum discussing this, and how other factors greatly contribute to the fluctuations in RSSI, but it mainly adds up to that the RSSI may be used to categorize the device as either near, far, or gone.

    Best regards,
    Karl

Related