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

nRF840 - S140 : How to fetch MAC addresses of surrounding mobile devices during nRF52840 scanning using Bluetooth 5.

Hello Nordic Team,

We are using nRF52840 ble chip with S140 nordic stack and SDK 15.2.0 on the  SEGGER IDE installed on  the Windows OS. We want nRF52840 chip  to detect surrounding mobile devices and also nRF52840 can fetch MAC addresses of mobile devices during scanning. We would like to know from your side that whether this is feasible or not ?. If yes, then can you please suggest us how to do it.

We are looking forward to hear from you.

Thanks
Bharat Gopani
Lumium Design
India.

Parents
  • Hi,

    You can find example projects that scans and logs in this post. It does active scanning as well, but you can adapt it to not do active scanning and only log the MAC address. You can refer to this post in the same thread for how to add logging of the MAC address.

  • Hello Einar,
    Thanks for the reply.
    We have procured nRF52-DK development board from Mouser India and we are using S140 stack on the Windows platform for our PoC.
    Our application requires that nRF52840 should be able to scan and fetch MAC address (public address) of surrounding Android smart phone.
    Currently, we are able to scan and fetch random private resolvable and  non resolvable addresses of surrounding Android smart phone and also public address of the smart BLE  watch but our project needs public address of the smart phone, so whether it's possible or not and if yes then how it can be done ?
    It would be helpful if you could suggest for the same.
    Thanks
    Bharat Gopani
    Lumium Design
    India
  • Hi Bharat,

    The sd_ble_gap_disconnect() function will return NRF_ERROR_INVALID_STATE if there is no active connection. See sd_ble_gap_disconnect()  API doc for details. If you know that you have an active connection, then the reason could be that the conn_handle you have provided is not for the connection you indented.

    The fact that the system is reset is just due to the error handling in your application. The SDK error handler in the SDK examples reset by default on any error, unless you have built the application with DEBUG defined (for instance by selecting the Debug build configuration if you are using SES). This is because resetting is often a sensible way to recover from an error that should not have occurred.

  • Hi Einar,

    Thanks for the support.

    Can we differentiate between process trying to connect with nRF52840 is from nRF Connect application or from bluetooth pairing on the smart phone at time of  event ble_gap_evt_connected().

    Our application requires  decision  whether user is trying to connect from nRF Connect App or bluetooth settings(pairing or bonding)  in the phone.

    Regards

    Bharat

  • Hi Bharat,

    Bharat said:
    Can we differentiate between process trying to connect with nRF52840 is from nRF Connect application or from bluetooth pairing on the smart phone at time of  event ble_gap_evt_connected().

    I cannot think of any way you can distinguish between app is used on the phone when you get the BLE_GAP_EVT_CONNECTED event. Essentially all the information you get is what you can see in ble_gap_evt_connected_t.

    Bharat said:
    Our application requires  decision  whether user is trying to connect from nRF Connect App or bluetooth settings(pairing or bonding)  in the phone.

    I think the only way to do this is to send some data (write to a characteristic) from nRF Connect (or perhaps your custom app in the future), indicating that this is what have connected. If this magic data is not written, you can assume that the user is using the native Bluetooth support in the phone (via the settings app).

  • Hello Einar,

    Thanks for the support.

    We are checking condition whether smart phone is connected or not and also peer address is resolved or not in the main loop.

    Now, if address of connected smart phone is not resolved then we are disconnecting the connection using the function err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gap_evt.conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION)  .

    However, this function returns ERROR: BLE_ERROR_INVALID_CONN_HANDLE and nRF52840 gets reset.

    Could you please tell us what is reason for this cause and how to resolve it.

    Regards

    Bharat

  • Hi,

    If sd_ble_gap_disconnect() returns BLE_ERROR_INVALID_CONN_HANDLE, then it means just what the name of the error code indicates: you have not provided a valid connection handle. You get the connection handle when you get the BLE_GAP_EVT_CONNECTED event, and with any other BLE events that are used for this connection. You must keep this handle somehow (for instance in a static variable of some sort, and provide it to sd_ble_gap_disconnect() to close the connection. Also note that this handle is no longer valid if the connection has been closed, since then it does not exist anymore.

Reply
  • Hi,

    If sd_ble_gap_disconnect() returns BLE_ERROR_INVALID_CONN_HANDLE, then it means just what the name of the error code indicates: you have not provided a valid connection handle. You get the connection handle when you get the BLE_GAP_EVT_CONNECTED event, and with any other BLE events that are used for this connection. You must keep this handle somehow (for instance in a static variable of some sort, and provide it to sd_ble_gap_disconnect() to close the connection. Also note that this handle is no longer valid if the connection has been closed, since then it does not exist anymore.

Children
  • Hi Einar,

    Thanks for your support.

    We want a nRF52 flash fixed location where we can store Password and which can not be disturbed by any part of the code.

    We found that peer manager is using fstorage for storing of the peer data.Can we store password at any fixed location using fstorage  ??

    We tried storing password at fixed location using fstorage but program execution is stopped.

    We have taken nRF_App_Proximity example as a reference and added NUS service.

    It would be grateful if you could suggest for the same.

    Regards

    Bharat

  • Hi Bharat,

    Bharat said:
    We found that peer manager is using fstorage for storing of the peer data.

    The peer manager uses FDS, which is a simple file system. It reserves a configurable number of flash pages, and use that to store records of information. The FDS in turn use fstorage for low-level flash access. Fstorage is just a library that allows you to access low-level flash operations (write and erase) in a simple way and abstracts away differences when using SoftDevice or not.

    Bharat said:
    Can we store password at any fixed location using fstorage  ??

    Yes, that is no problem. However, you need to make sure that there is no conflict with any other users of the flash. If you want to be able to update it, you should probably reserve a flash page for it. Alternatively, you can use FDS.

    Bharat said:
    We tried storing password at fixed location using fstorage but program execution is stopped.

    If program execution was affected that could indicate that you are overwriting parts of the flash that is used for something else. Have you debugged to see what happens? Do you get an error form a fstorage API call, or something else? Are you sure you are writing to a part of flash that is unused by?

Related