I have 3 questions: 1. How to set device to non-discovery mode? 2. Once the device is in non-discovery mode, How can host connect to it? 3. Can I use Master Control Panel to connect device which is in non-discovery mode?
I have 3 questions: 1. How to set device to non-discovery mode? 2. Once the device is in non-discovery mode, How can host connect to it? 3. Can I use Master Control Panel to connect device which is in non-discovery mode?
What exactly do you mean by "non-discovery mode"?
If you just mean to send advertising packets, but not be neither General Discoverable nor Limited Discoverable, this is done just by not using those flags when setting the advertising data, i.e. using BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED and not BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE or BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE.
However, if you mean to not send advertisement packets at all, you'll have to either explicitly stop advertising using sd_ble_gap_adv_stop() or wait for a timeout, and in this case, no device will be able to connect to you.
Thank you for your reply. I mean, if there's a way to make host can connect to my nrf51822 device, and also to make nrf51822 device not be displayed in the ble device list of host? BTW, if I use BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED to set advertising data, what mode is my device actually in? I try to do this, It can still be displayed in MCP.
All advertising packets can be received by any scanner, and it is hence up to the filtering done on the scanner to decide whether or not a device is shown. Even when advertising with just BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED (neither Limited nor General discoverable), some scanners may choose to show this device when scanning, and there isn't anything you can do to avoid this. This is what's called "Non-discoverable Mode" in section 9.2.2 in Volume 3, Part C of the Core Specification.
what's difference between General Discoverable and Limited Discoverable? and if no advertising, but we have bond before, can phone side do direct connect to nrf51822?
This is really a separate question and would be better off separately. However, there isn't really any conceptual difference between General discoverable and Limited discoverable advertising; they are just different modes defined by the spec. You can read about these in Volume 3, section 9.2.3 and 9.2.4.
Some devices may be using this flag to determine whether or not a device should be shown in a list of discovered devices.
If a device isn't advertising, it's impossible for any Central to connect to it. See this question for details: http://stackoverflow.com/questions/22097079/is-it-possibile-to-wake-up-a-deep-sleep-ble-device-in-android-sdk