Python - Thread not outputting Event Log

Viewed 19

I'm currently writing a project where i'm starting some Bluetooth Low-Energy advertisement in a thread and want to log in the console, when a device connects to the advertisement.

But the logs are sadly never triggered when someone connects. I'm sure i'm doing something wrong when I start the advertisement in a different thread but i'm not sure what.

My code looks like that:

class BluetoothController:

    def __init__(self):
        self.adapter_address = list(adapter.Adapter.available())[0].address
        self.ble_uart = peripheral.Peripheral(adapter_address=self.adapter_address,
                                              local_name=config.BLUETOOTH_APP_NAME)

    def setup_ble(self):
        self.set_service_and_characteristic()
        self.set_listeners()

    def start_advertising(self):
        self.start_threadened(self.ble_uart.publish)

    def set_service_and_characteristic(self):
        self.ble_uart.add_service(srv_id=1, uuid=config.BLUETOOTH_SERVICE_UUID, primary=True)
        self.ble_uart.add_characteristic(srv_id=1, chr_id=1, uuid=config.BLUETOOTH_CHARACTERISTIC_UUID,
                                         value=[], notifying=False,
                                         flags=['write', 'write-without-response'],
                                         write_callback=BluetoothDevice.uart_write,
                                         read_callback=None,
                                         notify_callback=None)

    def set_listeners(self):
        self.ble_uart.on_connect = BluetoothDevice.on_connect
        self.ble_uart.on_disconnect = BluetoothDevice.on_disconnect

    def start_threaded(starting_function):
       thread = Thread(target=starting_function)
       thread.start()
       return thread

The listeners are never triggered after start_advertising is started in another thread.

0 Answers
Related