Hi Rohit,
Thank you for your reply. But I am still having a few problems. I don't want to send scanRequest right at the beginning but only if a certain value is received from the initial advertisement packet.
Here is the scenario.....
In my code say device A sends a certain value (that increments every second) to device B as part of an Advertising structure with type TRICKLE_TYPE (Here TRICKLE_TYPE is custom type that I have added in the GapAdvertisingData.h ). Device B should then send a scan request to device A only if a certain value is received, after which the device A should send a scan Response. In my code, I have put the following statement so that data in array scanResponse is sent only when the scan request is received:
ble_device.accumulateScanResponse(GapAdvertisingData::TRICKLE_TYPE,(uint8_t *)scanResponse, sizeof(scanResponse));
However, when I check on Master Control Panel, right at the beginning I can see data in array ScanResponse being advertised. Is it wrong to put the accumulateScanResponse() function along with statements calling accumulateAdvertisingPayload() to populate the initial advertisement packet? I don't want the Scan Response advertising structure to appear till the scan request has been received.
Also, in the code in Device B, I am checking for the value received in the advertisement callback and only if it is a required value I use ble.gap().setActiveScanning(true); to send scan request. Is it possible to dynamically change the scan parameters like this or I need to stopScan then setActiveScanning and then startScan again.
Kind Regards
Swati Sehgal
Hi,
We're on our way to extending the BLE_API to allow the programming of devices to take on the role of a BLE Central. As a step in this direction, we'd like to propose APIs to support scanning:
extensions to top-level APIs to support scanning
/** * Setup parameters for GAP scanning--i.e. observer mode. * @param interval Scan interval (in milliseconds) [valid values lie between 2.5ms and 10.24s]. * @param window Scan Window (in milliseconds) [valid values lie between 2.5ms and 10.24s]. * @param timeout Scan timeout (in seconds) between 0x0001 and 0xFFFF, 0x0000 disables timeout. */ ble_error_t setScanningParams(uint16_t interval = GapScanningParams::SCAN_INTERVAL_MAX, uint16_t window = GapScanningParams::SCAN_WINDOW_MAX, uint16_t timeout = 0); ble_error_t setScanningInterval(uint16_t interval); ble_error_t setScanningWindow(uint16_t window); ble_error_t setScanningTimeout(uint16_t timeout); /** * Start scanning (Observer Procedure) based on the scan-params currently * in effect. * * @param callback The application callback to be invoked upon receiving * every advertisement report. Can be passed in as NULL, in which case * scanning may not be enabled at all. */ ble_error_t startScanning(Gap::AdvertisementReportCallback_t callback); /** * Stop scanning. The current scanning parameters remain in effect. * * @retval BLE_ERROR_NONE if successfully stopped scanning procedure. */ ble_error_t stopScanning(void);extensions to Gap.h
enum AdvertisementType_t { ADV_IND = 0x00, /**< Connectable undirected. */ ADV_DIRECT_IND = 0x01, /**< Connectable directed. */ ADV_SCAN_IND = 0x02, /**< Scannable undirected. */ ADV_NONCONN_IND = 0x03, /**< Non connectable undirected. */ }; ... typedef void (*AdvertisementReportCallback_t)(const address_t peerAddr, int8_t rssi, bool isScanResponse, AdvertisementType_t type, uint8_t advertisingDataLen, const uint8_t *advertisingData);Please comment. Thanks.