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

Connection between two hidden NRF51822 modules

Hello

First of all, I would like to apologize if a similar question was already asked but all this BLE matter is so broad that it defeats me. I am planning to put two NRF51822 devices into my project. I want one of the devices to pull one of the GPIO pins down as soon as the other one is in the range of 10-30m. Also, I want it to be secure, I don't want anyone else to scan my devices, copy them and control the pin with another one. I want slave device to consume as low energy as possible.

My idea is:

  1. make both devices undiscoverable so it will be difficult to scan for them.
  2. The master device (the one that controls the GPIO pin) will advertise only to the slave one and it will be visible only for the slave one.
  3. The slave device will check if it is in range of 10-30-m and if so it will send back a message/password or whatever to master. If it is not in range it won't send any message.
  4. If master receives the message it pulls the pin down.
  5. Repeat points 2-4 each 1s.

Is it possible to implement such routine? Or are there any better ideas? I am a total newbie in BLE. I managed to run simple advertising example but nothing more. I would appreciate a guidance, not a readymade solution.

vldzero

  • You are right. The type was BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE and it seems like my Android won't try to connect with any other type. So I decided to use another nrf51822 device to scan and to connect instead of nrfConnect. I made one modification to the code I attached one answer ago. I changed whitelist of the advertiser to public. ble_gap_addr_t whitelist_addr = {BLE_GAP_ADDR_TYPE_PUBLIC,{0xfc, 0x45, 0x92, 0x76, 0xc4, 0x0c}} ;

    Then I opened examples\ble_central\ble_app_multilink_central\pca10028\s130 as it seems to be the easiest example to modify. The comment says Start scanning for peripherals and initiate connection to devices which advertise. so I assumed that adding the whitelist to the central device will result in connecting to the device which address is pointed by the whitelist.

  • So basically the peripheral has address of the cental in its whitelist and central has address of peripheral in its whitelist.

    The only modification I made to ble_app_multilink_central example was this:

      ble_gap_whitelist_t  whitelist;
      ble_gap_addr_t *p_whitelist_addr[1];
      ble_gap_addr_t  whitelist_addr =
      {
    		BLE_GAP_ADDR_TYPE_RANDOM_STATIC,
    		{0xdb, 0x3d, 0x9d, 0xd6, 0xc6, 0x3b}
       } ; //MAC addres of pheripheral
    /** @brief Scan parameters requested for scanning and connection. */
    static const ble_gap_scan_params_t m_scan_params =
    {
        .active   = 1, //0
        .interval = SCAN_INTERVAL,
        .window   = SCAN_WINDOW,
        .timeout  = SCAN_TIMEOUT,
    
        #if (NRF_SD_BLE_API_VERSION == 2)
            .selective   = 1,	//0
            .p_whitelist = &whitelist, // NULL,
        #endif
    
        #if (NRF_SD_BLE_API_VERSION == 3)
            .use_whitelist  = 0,
            .adv_dir_report = 0,
        #endif
    };
    
  • Unfortunately, those two devices do not connect. Is the whole idea wrong?

    EDIT. I just removed all whitelists from both devices and they still do not connect... even though I can connect to the advertiser with nrfConnect. Seems like central device is a problem now.

  • ble_app_multilink_central example will not connect to ble_app_template example, it will connect to the ble_app_blinky example.

    I recommend you to use ble_app_hrs and ble_app_hrs_c as starting points. ble_app_hrs_c will try to connect to ble_app_hrs.

    Also, I think BLE_GAP_ADDR_TYPE_PUBLIC is incorrect, it should be BLE_GAP_ADDR_TYPE_RANDOM_STATIC.

  • Hi,

    I have similar problem... I'm using nrf51822, s130 and sdk 12.3.0... once I retrieve whitelist and set it to adv_params whitelist, then advertise messages are sent out only when I set fp (filter policy) to any...

    In case that i set it to scan/conn/both filter I won't see any advertise message on phone... there is no message also on sniffer... any suggestions?

    Is it possible to get any additional example for BLE_GAP_ADV_FP_FILTER_SCANREQ and BLE_GAP_ADV_FP_FILTER_BOTH options? I could found only for BLE_GAP_ADV_FP_ANY and BLE_GAP_ADV_FP_FILTER_CONNREQ

    Thank you!

    BR, Matej

Related