Search code examples
bluetooth-lowenergybluez

continue advertising after connection bluez


I have setup advertising in bluez using hcitool The device sow up as expected.

The setup is done as follow:

#advertising
sudo hcitool -i hci0 cmd 0x08 0x0008 18 02 01 06 02 0a 00 11 07 9e ca dc 24 0e e5 a9 e0 93 f3 a3 b5 01 00 40 6e 00 00 00 00 00 00 00
#scan response
sudo hcitool -i hci0 cmd 0x08 0x0009 0d 0c 09 6f 6f
#setup advertising interval
sudo hcitool -i hci0 cmd 0x08 0x0006 80 02 c0 03 00 00 00 00 00 00 00 00 00 07 00
#turn advertising on
sudo hcitool -i hci0 cmd 0x08 0x000a 01

After a devie connect the advertising is gone. How kan I keep continuing advertising?

I did a workaround calling sudo hcitool -i hci0 cmd 0x08 0x000a 01 repeatedly.

Another question is how setup the advertising above using the d-bus interface.

ps. Many info have been found in Bluetooth specification 5.0 (Core_v5.0.pdf), 7.8.5 LE Set Advertising Parameters command p.1321


Solution

  • Most stacks/implementations (including BlueZ) will automatically switch off adverts when a device's state switches from advertising to accepting an incoming connection. The reason for this is that according to the stack Link Layer states (Please see picture below which is available Bluetooth specification v5.1, Vol 6, Part B, Section 1.1: Link Layer States), the state of the device should change from Advertising to Connected as the device cannot be in two different states at the same time.

    enter image description here

    However, once you are in a connection you can restart your adverts as you have done manually. Please have a look at the answer below for more information:-

    Link Layer state for more than one simultaneous connection

    I hope this helps.