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

NUS with Scanner

I can scan beacons with Scanner. and can use NUS (ble_periperall\ble_app_uart ) to get connect with device.

My goal is to combine both application Have NUS Service to connect with Mobile and Scanner for scanning and sending beacon data to Uart.

After combining code, I can connect to device using Mobile. and Device also receives the beacon.

When when I connect with device it stops Scanner. I want to make connection to configure device and Scanner should also work at this time.

Thank You

Bivay   



Parents
  • Hello,

    You must start scanning again after the connection has been made. You probably need to increase the number of central connections that the device has, or else you will get an error when you try to start the scan when you are already connected. 

    Search for NRF_SDH_BLE_CENTRAL_LINK_COUNT and NRF_SDH_BLE_TOTAL_LINK_COUNT. They should both be set to 2.

    Best regards,

    Edvin

  • Thanks for response.

    I want to send beacon data using NUS to mobile. and its only possible if scanner and NUS works simultaneously.

    Please consider above statement to help me.

    Thank You

    Bivay

  • Sorry, I mixed the nus_c and nus. 

    Either way, you need to start scanning in addition to advertising. In that case, you must set NRF_SDH_BLE_CENTRAL_LINK_COUNT to 1, NRF_SDH_BLE_PERIPHERAL_LINK_COUNT to 1 and NRF_SDH_BLE_TOTAL_LINK_COUNT to 2.

    Then you start scanning like it is done in the ble_central examples, and you start advertising like it is done in the ble_perpheral examples.

    If you want some further inspiration, you can check out the example found in:

    SDK\exapmles\ble_central_and_peripheral\experimental\ble_app_hrs_rscs_relay, which does both scanning and advertising.

    Best regards,

    Edvin

Reply
  • Sorry, I mixed the nus_c and nus. 

    Either way, you need to start scanning in addition to advertising. In that case, you must set NRF_SDH_BLE_CENTRAL_LINK_COUNT to 1, NRF_SDH_BLE_PERIPHERAL_LINK_COUNT to 1 and NRF_SDH_BLE_TOTAL_LINK_COUNT to 2.

    Then you start scanning like it is done in the ble_central examples, and you start advertising like it is done in the ble_perpheral examples.

    If you want some further inspiration, you can check out the example found in:

    SDK\exapmles\ble_central_and_peripheral\experimental\ble_app_hrs_rscs_relay, which does both scanning and advertising.

    Best regards,

    Edvin

Children
  • Dear,

    Thanks for support, From our help I get one step ahead. When I connect to NUS Device with scanner, Scanner works as expected, I can see data of beacon on logger even after connection. But There is another issue After connection when I transmit data from Mobile to Device, It doesn't receive data and scanner is also stopped for some time about 9 seconds.

    In mobile I get Two Errors:

    ERROR 133 (0x85): GATT ERROR

    ERROR 8 (0x8) : GATT CONN TIMEOUT

    After this message device again start scanning of beacon and advertise.

    If I didn't send data on NUS Bus then Scanner works but NUS get disconnect with below error after nearby 9 seconds.

    ERROR 8 (0x8) : GATT CONN TIMEOUT

    But when at event BLE_GAP_EVT_CONNECTED, if I stop scanning using sd_ble_gap_scan_stop(), NUS Bus works. and at event BLE_GAP_EVT_DISCONNECTED I start scanning again.

    Please Help me regarding this.

    Thank You

    Bivay

  • It looks like your nRF application is crashing. Have you tried monitoring the log from the nRF5840?

    If it says "Fatal error" somewhere, try to add DEBUG in your preprocessor definitions. (Let me know what IDE you are using if you are not sure how to do this).

    BR,

    Edvin

  • Dear Edvin,

    Thanks for help I will debugging in code. but there is no "fatal error". code is running as expected after above error. This is found from log of start print. If I provide you my code can you please look for issue in it.

    My Goal is a Android mobile is connected to My NRF52840 device. This device scans the beacon continuously and transmit beacon data to Android Mobile in NUS.

    My problem is when scanning runs can't use NUS. and when use NUS can't use scan for beacon. Both scan and NUS runs independent perfectly. My goal is to run both simultaneously.

    Please find attachement. 

    I am using Segger Studio 4.20 as IDE.

    SDK: nRF5_SDK_16.0.0_98a08e2

    Please copy code in following folder : nRF5_SDK_16.0.0_98a08e2\examples\ble_peripheral

    Thank You

    Bivay

    ble_app_uart - v1.zip

     
  • bivay said:
    My problem is when scanning runs can't use NUS. and when use NUS can't use scan for beacon.

     Can you explain why you can't use them? What happens if you try to use NUS while scanning? And what happens if you try to scan while you use NUS?

  • I already described my issue, but once again:

    I am using the attached code with sdk16.0.0, extract to nRF5_SDK_16.0.0_98a08e2\examples\ble_peripheral.

    When this code starts, I get beacon data on RTT Viewer, and get advertisement in Android NRF Connect Application. When I press connect button on NRF Connect Application, New tab is opned and shows connected, but in this situation I didn't get beacon data on RTT viewer by Scanner Module. 

    Then, after some time in NRF Connect Application, Device get disconnect with following error:

    ERROR 8 (0x8) : GATT CONN TIMEOUT

    And then in RTT viewer I can see beacon data again.

    I can confirm that NRF52840 is not reset or reboot or hangs during this process.


    But when at event BLE_GAP_EVT_CONNECTED, if I stop scanning using sd_ble_gap_scan_stop(), NUS Bus works perfectly (Can't see beacon data on RTT viewer). and at event BLE_GAP_EVT_DISCONNECTED (when I disconnect manually from NRF Connect Application), when start scanning again, it scan and shows beacon data on RTT viewer.

    My problem is when scanning runs can't use NUS. and when use NUS can't use scan for beacon. Both scan and NUS runs independent perfectly. My goal is to run both simultaneously.

    Thank You 

    Bivay

Related