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

GET PERIPHERAL DEVICES' MAC ADDRESS AND SEND THROUGH UART

Hi all, I am working on a project for which I use nRF52832 with SDK15.2 and SD132. What I need is that nRF52 should transmit and receive command through serial UART as a central, can scan all NUS peripheral devices, read all the scanned NUS peripheral devices peer addresses and send back to PC. For example,

1.) The PC sends the command "scan on", then the central starts scanning and let PC knows if it can discover nearby NUS peripheral devices.

2.) When the PC receives this info, it will send the command "devices" to the nRF52 and it should send back all the NUS peripheral devices' peer address to the PC.

3.) Among these peripheral devices, the PC will send the command "connect AA:BB:CC:DD:EE:FF" and then nRF52 should connect to that device and start communicate through TX and RX characteristics of NUS.

So, it's a combination of ble_app_interactive and ble_app_uart_c but I don't know how can I get all the scanned NUS peripherals addresses (since I can't understand the ble_app_interactive cli concept). How can I do it ? Thanks and sorry for the long question form.

Parents
  • Hi,

    I think you can start by modifying the event handling for BLE_GAP_EVT_ADV_REPORT in ble_m.c so that only NUS peripherals are added to the device list (i.e., only call to device_to_list_add and address_to_cmd_add when a NUS peripheral is found). You can ble_app_uart_c as a reference on how you can filter NUS peripherals based on the NUS UUID. First, you need to add the base NUS UUID with sd_ble_uuid_vs_add() in your central code, then you can check for BLE_UUID_NUS_SERVICE match in the advertisement report.   

  • Hi Vidar Berg, thanks so much for your answer. Please let me correct if I am wrong. In the central mode tutorial

    use ble_adv_uuid_find() function to check the UUID of the NUS and then connected if it's match. Is that right? and do I still need to check for the service match check if the UUID is matched?

  • Hi,

    You typically parse the advertisement packet to determine if the advertisement packet belongs to a peripheral you want to connect to. Like in this case, you want to connect to peripherals including the NUS service UUID in the advertisement packet.

    "use ble_adv_uuid_find() function to check the UUID of the NUS and then connected if it's match" Correct. 

    AnthonyThet said:
    and do I still need to check for the service match check if the UUID is matched?

    It's optional to include service UUIDs in the advertisement packet (unless you're using a BT SIG defined service/profile that requires it). Normally you include a subset of the service UUIDs, enough to uniquely identify the type of peripheral.  You will still have to do a service discovery after connection. 

  • Thanks Vidar, but I still stuck at this. I created a ble_m.c file as in the "ble_app_interactive" and I created a case in ble_evt_handler but I don't know how to get the data from ble_adv_report (I just checked if the uuid check is matched or not.).

    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
        ret_code_t            err_code;
        ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt;
    		scan_evt_t						scan_evt;
    		// I need to get data from ble adv report 
        switch (p_ble_evt->header.evt_id)
        {
    				case BLE_GAP_EVT_ADV_REPORT:
    						if(/*UUID_check match*//*scan_evt.params.filter_match.filter_match.uuid_filter_match == true*/)
    						{
    						    /* do the device to add list */
    							NRF_LOG_DEBUG("BLE_GAP_EVT_ADV_REPORT\n");
    							device_to_list_add(&p_gap_evt->params.adv_report);
    							
    						}
    						
    						break;
    			
                    case BLE_GAP_EVT_CONNECTED:
                            break;
        }
    }

    And to be honest, I also quite don't know how to proceed like where do I need to get scan NUS devices address (in ble_app_interactive, it uses m_device to display the scan devices list when you type in "Devices" , but I don't know how can I do?)

    Sorry, I am just a newbie in BLE world especially Nordic, please help me and really thanks again and appreciate your help.

  • What I need is
    1. scan the NUS peripherals and store all the scanned peripheral addresses.
    2. when UART received "devices", it transmit all the scanned peripheral addresses.

    3. when UART received "connect AA:BB:CC:DD:EE:FF", the central will connect to that particular peripheral.

    But still I couldn't make it yet.

Reply Children
Related