1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
import enum
import logging
from btsocket import btmgmt_callback
from btsocket import btmgmt_protocol
# logger = logging.getLogger("btsocket.btmgmt_callback")
# logger.setLevel(logging.DEBUG)
logger_prot = logging.getLogger('btsocket.btmgmt_protocol')
logger_prot.setLevel(logging.INFO)
class Flags(enum.IntEnum):
CONNECTABLE = enum.auto()
GENERAL_DISCOVERABLE = enum.auto()
LIMITED_DISCOVERABLE = enum.auto()
FLAGS_IN_ADV_DATA = enum.auto()
TX_IN_ADV_DATA = enum.auto()
APPEARANCE_IN_ADV_DATA = enum.auto()
LOCAL_NAME_IN_ADV_DATA = enum.auto()
PHY_LE_1M = enum.auto()
PHY_LE_2M = enum.auto()
PHY_LE_CODED = enum.auto()
ctrl_idx = 0 # hci0
instance = 1 # Arbitrary value
flags = Flags.GENERAL_DISCOVERABLE
duration = 0x00 # 0 means use default
timeout = 0x0 # 0 means use default
adv_data = "1bfff0ff6DB643CF7E8F471188665938D17AAA26495E131415161718"
adv_data_len = len(bytes.fromhex(adv_data))
scan_rsp = "" # (0-255 Octets)
scan_rsp_len = len(bytes.fromhex(scan_rsp))
def show_result(pkt, mgmt_class):
print(pkt)
def main():
mgmt = btmgmt_callback.Mgmt()
mgmt.add_event_callback(
btmgmt_protocol.Events.CommandCompleteEvent,
show_result)
mgmt.send('AddAdvertising', ctrl_idx,
instance,
flags,
duration,
timeout,
adv_data_len,
scan_rsp_len,
adv_data,
scan_rsp)
mgmt.start()
if __name__ == '__main__':
main()
|