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

  • I'm not sure what you mean by undiscoverable, the peripheral/slave has to advertise for the central/master to know that it is there.

    The central/master doesn't advertise, it scans, the peripheral/slave advertise.

    You can use a private resolve address in the peripheral to enforce privacy. Then if it bonds with the central only the central will be able to resolve the address and recognize the peripheral.

    What you need to figure out is how to pair. Can you pair these devices in a safe environment? Do they have any inputs or output? Can they use a preshared key? It is a bit difficult to recommend something when I know so little about your application, maybe you can explain a bit more?

    The only option for measuring estimating the range is by using RSSI, Received Signal Strength Indication, so you can look into that. Many questions in here about that.

  • So I would do something like this:

    1. Use random resolvable address, don't put confidential information into the advertising packet. Advertise with whitelist to reject connection requests from unknown masters.
    2. Figure out how to pair and bond safely. Only allow the one central to bond.
    3. Use a big advertising interval on the peripheral to save power, use aggressive scanning on the central if you want short latency on establishing connection. You should tune this.
    4. After connection is established, use the RSSI to estimate the range between the devices.
  • Thanks Petter The device will be a simple wirelessly controlled relay. While the slave is in range of central one the relay controlled by the master will energize. It is all part of a bigger system but BLE will play an essential role. With your input and my tiny knowledge about BLE, I simplified the list.

    1. The slave will advertise with a whitelist. I won't use random resolvable address for now since it would take me too much time. When the device is functional I will have time to improve the safety.
    2. Slave will run service where an ID will be stored. If the ID is accepted by the master it will energize the relay.
    3. If the device is out of range master will de-energize the relay.
  • Anyway. I am stuck at point 1 of my list... I am using SDK_12.2.0, S130 I work with examples/ble_peripheral/ble_app_template and nRF Connect on my mphone.

    After adding sd_ble_gap_whitelist_set function when I try to build the project I get: Error: L6218E: Undefined symbol sd_ble_whitelist_set (referred from main.o). Is it sdk_config.h? If so I cannot find anything that would enable that function.

  • sd_ble_gap_whitelist_set() is not supported by S130.

    The whitelist has be set when you start to advertise:

    /**@brief GAP advertising parameters.*/
    typedef struct
    {
      uint8_t               type;                 /**< See @ref BLE_GAP_ADV_TYPES. */
      ble_gap_addr_t       *p_peer_addr;          /**< For @ref BLE_GAP_ADV_TYPE_ADV_DIRECT_IND mode only, known peer address. */
      uint8_t               fp;                   /**< Filter Policy, see @ref BLE_GAP_ADV_FILTER_POLICIES. */
      ble_gap_whitelist_t  *p_whitelist;          /**< Pointer to whitelist, NULL if no whitelist or the current active whitelist is to be used. */
      uint16_t              interval;             /**< Advertising interval between 0x0020 and 0x4000 in 0.625 ms units (20ms to 10.24s), see @ref BLE_GAP_ADV_INTERVALS.
                                                       - If type equals @ref BLE_GAP_ADV_TYPE_ADV_DIRECT_IND, this parameter must be set to 0 for high duty cycle directed advertising.
                                                       - If type equals @ref BLE_GAP_ADV_TYPE_ADV_DIRECT_IND, set @ref BLE_GAP_ADV_INTERVAL_MIN <= interval <= @ref BLE_GAP_ADV_INTERVAL_MAX for low duty cycle advertising.*/
      uint16_t              timeout;              /**< Advertising timeout between 0x0001 and 0x3FFF in seconds, 0x0000 disables timeout. See also @ref BLE_GAP_ADV_TIMEOUT_VALUES. If type equals @ref BLE_GAP_ADV_TYPE_ADV_DIRECT_IND, this parameter must be set to 0 for High duty cycle directed advertising. */
      ble_gap_adv_ch_mask_t channel_mask;         /**< Advertising channel mask. See @ref ble_gap_adv_ch_mask_t. */
    } ble_gap_adv_params_t;
    

    You can also let the advertising module handle it.

    Add options.ble_adv_whitelist_enabled = true; in advertising_init().

    Then you need to handle the BLE_ADV_EVT_WHITELIST_REQUEST event that you get in on_adv_evt(), by replying with ble_advertising_whitelist_reply().

Related