Searching for devices
There are four different ways of scanning the network which corresponds with four defined functions in the Bluetooth module API. In this functions, some parameters like inquiry power, inquiry time, number of devices, etc, have to be specified. Each function is described below.
ScanNetwork(Time, Power)
This function allows a simple scan of network. Inquiry time and TX power must be specified. Inquiry results are limited to 250 and they are stored in SD card file. The total of discovered devices is returned.
The usual time to discover about 20 devices is rounding 10 seconds, but time can be set from 1 to 48. Keep in mind that this time is approximated because time value is internally multiplied by 1.28 (predefined firmware value). That means that you can do inquiries until 61 seconds long. Besides that, some time is spent to process and save data.
Next example makes an inquiry of 10 seconds, but the real time spent is 12.8 plus parsing and saving data processes. Number of discovered devices is stored in public variable numberOfDevices.
TX power values are predefined as constants because Bluetooth module only has the capability of transmit at seven values. Any integer value can be entered here but module will round it to the nearest valid value.
In the Waspmote Development section you can find a complete example about using this function:
https://development.libelium.com/bt-pro-01-normal-scan/
ScanNetworkName(Time, Power)
This function is equal to scanNetwork but it also includes friendly names, when they are available. User should take into account that friendly names have to be asked to each discovered device and this fact takes some extra time. By default this time is limited to 60 seconds but it can be changed modifying parseNames() in WaspBT_Pro.cpp.
Device names are saved after the inquiry data, showing each MAC address with their friendly name. When the device friendly name is not available, default value for name is "NONAME".
This function is very slowly and most of time "friendly names" are not available so keep it in mind when using this function.
In the Waspmote Development section you can find a complete example about using this function:
http://www.libelium.com/development/waspmote/examples/bt-pro-04-scan-with-friendly-name
ScanNetworkLimited(MAX_DEVICES, power)
This function scans the network in the same way of scanNetwork, but now you can limit your scan to a specific number. If this number is reached, the inquiry stops. However, if maximum is not reached, the module continues inquiring until maximum time.
Next example shows an inquiry at maximum power until find four devices. If four devices are present, they will be stored on the SD card.
In the Waspmote Development section you can find a complete example about using this function:
https://development.libelium.com/bt-pro-02-limited-scan/
ScanDevice(MAC, maxtime, power)
This function is used to know if a specific device is present inside detection area of Bluetooth module. Devices are commonly identified by its MAC address. When defining variables containing MAC addresses, be sure that they are defined with the format \"00:1a:16:e8:c2:01\", otherwise scanDevice() will not find specified the device. In addition, the class of device has 6 hexadecimal digits and RSSI value is shown in dBm.
The maximum scanning time is defined by maxtime. This function scans network until the desired device is found. Once the device is found, it is saved into the SD card file. However, if the device is not found, the inquiry will continue until maxtime is reached.
The returned value of this function is 1 if the device is found. Otherwise, it returns 0.
In the Waspmote Development section you can find a complete example about using this function:
https://development.libelium.com/bt-pro-03-scan-specific-device/
PrintInquiry()
By default, discovered devices are not shown through USB because they are only saved on the SD card. If the user wants to view discovered devices just use printInquiry() function after the scan function and discovered devices in the last inquiry will be shown. Use this function only for debugging purposes due to it can become slow when the SD card files are big.
Last updated