Skip to content

TypeError when going from bleak to bleekWare #5

@FilMarini

Description

@FilMarini

Hi,

I've created a very simple app that connects to a device and print whatever the device is sending.

The app works well in Linux using bleak, but when I compile it for Android using bleekWare, it connects ok but when it should print on screen what it receives, it prints TypeError: 'bool' object is not callable

Here's the script Im using:

import asyncio
import toga
from toga import App, Button, Label, Box

if toga.platform.current_platform == 'android':
   from .bleekWare import bleekWareError as BLEError
   from .bleekWare.Client import Client as Client
   from .bleekWare.Scanner import Scanner as Scanner
else:
   from bleak import BleakError as BLEError
   from bleak import BleakClient as Client
   from bleak import BleakScanner as Scanner

# UUIDs for the UART service and characteristic
UART_SERVICE_UUID = "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"
UART_TX_UUID = "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"

class HelloWorld(App):

    def startup(self):
        self.label = Label("Waiting for data...")
        self.button = Button("Connect", on_press=self.connect)
        self.box = Box(children=[self.label, self.button])

        self.main_window = toga.MainWindow(title='BLE UART')
        self.main_window.content = self.box
        self.main_window.show()

    async def connect_to_device(self):
        device_address = "2C:CF:67:97:DE:C7" 
        try:
            async with Client(device_address) as client:
                if client.is_connected():
                    await client.start_notify(UART_TX_UUID, self.notification_handler)
                    self.label.text = "Connected! Waiting for data..."
                
                    # Keep the connection alive
                    while True:
                        await asyncio.sleep(1)
        except Exception as e:
            self.label.text = f"Error: {e}"

    def notification_handler(self, sender, data):
        # Handle incoming data from the Bluetooth device
        message = data.decode('utf-8')
        self.label.text = f"Received: {message}"

    def connect(self, widget):
        # Schedule the async connection task in the event loop
        asyncio.create_task(self.connect_to_device())

def main():
    return HelloWorld()

Any idea why this happens?
Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions