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

Connecting to ble device based on mac address

We are using nrf52832 in our design. It involves two nrf52832 with a bunch of sensors and one more nrf52832 which has cloud connectivity. We store the sensor information in a spi FLASH (externally interfaced to ble device) of each ble device. After collecting information for a certain time, we want to send the sensor information from first device into central device and then store the same in sd card of central device. Then collects the information from other ble device to central device. 

How can i connect to the first device and do the data transfer and then connect to second device and then do data transfer again to central device. Only unique between both the devices is MAC address. Please help me connect to devices using mac id.

Parents
  • You can indeed connect by the MAC address but the peripheral device needs to be ready to accept connections. Advertising is usually the way to do this. This is tricky though if you don't know the MAC beforehand.

    The easiest way to do this without knowing the MAC address is to filter your scan results. There are a few ways to filter. One is by device name

        err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_NAME_FILTER, m_target_periph_name);
        APP_ERROR_CHECK(err_code);

    The other is by using the UUID for the service you're targeting

        err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_UUID_FILTER, &target_uuid);
        APP_ERROR_CHECK(err_code);

    You can set this on the peripheral device by modifying the m_adv_uuids array 

    // YOUR_JOB: Use UUIDs for service(s) used in your application.
    static ble_uuid_t m_adv_uuids[] = {{BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE},{PROTOBUF_UUID_SERVICE, BLE_UUID_TYPE_BLE}};

    You'll also have to configure the service as well. I went into detail about how to configure a new service on my blog. There's also tons of examples in the SDK under the examples/ble_peripheral folder. 

    On the central, you'll have to do a device discovery to see if the device indeed has that service. You can also look in the examples/ble_central folder to see how to implement your own. The ble_app_gatts example is good. Look for the scan_filters_set and scan_start.

    Hopefully that makes sense. Let me know if I can help explain further. Slight smile

    Jared
    jaredwolff.com

Reply
  • You can indeed connect by the MAC address but the peripheral device needs to be ready to accept connections. Advertising is usually the way to do this. This is tricky though if you don't know the MAC beforehand.

    The easiest way to do this without knowing the MAC address is to filter your scan results. There are a few ways to filter. One is by device name

        err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_NAME_FILTER, m_target_periph_name);
        APP_ERROR_CHECK(err_code);

    The other is by using the UUID for the service you're targeting

        err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_UUID_FILTER, &target_uuid);
        APP_ERROR_CHECK(err_code);

    You can set this on the peripheral device by modifying the m_adv_uuids array 

    // YOUR_JOB: Use UUIDs for service(s) used in your application.
    static ble_uuid_t m_adv_uuids[] = {{BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE},{PROTOBUF_UUID_SERVICE, BLE_UUID_TYPE_BLE}};

    You'll also have to configure the service as well. I went into detail about how to configure a new service on my blog. There's also tons of examples in the SDK under the examples/ble_peripheral folder. 

    On the central, you'll have to do a device discovery to see if the device indeed has that service. You can also look in the examples/ble_central folder to see how to implement your own. The ble_app_gatts example is good. Look for the scan_filters_set and scan_start.

    Hopefully that makes sense. Let me know if I can help explain further. Slight smile

    Jared
    jaredwolff.com

Children
No Data
Related