BLE Examples generic advertise
In order for a BLE device to be found via a search, it needs to be set up to advertise. This example will create an advertisement with a customized name.
Prerequisites
- The example was tested against a smartphone with BLE capabilities, using a simple BLE monitor tool.
- The Bluetooth device must already be set up via the device's manual's instructions (without the use of the
hciconfig
command!) andbluetoothd
started via system as noted above. - Be running as
root
user or a user with proper permissions.
Running
Before this is run, we're going to set a custom advertising name to make it more identifiable.
sed -i -e "s/'TestAdvertisement'/'TS_BLE_Demo'/" /usr/local/lib/bluez/test/example-advertisement
Additionally, some embedded modules are not able to handle longer advertisement lengths, we're going to comment out an example nonstandard advertisement type in order to support all platforms.
sed -i -e "s/self.add_data/#self.add_data/" /usr/local/lib/bluez/test/example-advertisement
Run the example with:
root@tsimx28:~# /usr/local/lib/bluez/test/example-advertisement & Advertising forever... GetAll returning props Advertisement registered root@tsimx28:~#
If there are any errors, check that all of the prerequisites have been satisfied.
On another BLE compatible device, running a scan will return our device named "TS_BLE_Demo." This device can be connected to, the example will start up a number of simple services. For example, the device name can be read. The following screenshot from a smartphone reads the "Device Name" value.