Python Forum
Start print a text after open an async task via button
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Start print a text after open an async task via button
#1
Hello, the code in this example: https://pastebin.com/FAnuZgW1 should open a GUI. After i open the GUI i have an button and start from this an async task. Then they should send via BLE Data to an ESP and if he can't connect, he should write an text. The GUI work, but after i press the button i don't see an text in the async tast, i can only print the text in the normal function.

       

 self.pushButton.clicked.connect(on_pushButton_click)

ef on_pushButton_click():
    print("Button wurde geklickt")
    asyncio.create_task(send_data())
    # asyncio.run(send_data())

def on_pushButton_click2():
    print("dada")

async def send_data():

    on_pushButton_click2()


    await send_data(1)

    try:

        writer = lambda msg: print(msg)
        writer("sende Daten...")

        async with bleak.BleakClient(mac_address) as client:
            # String erstellen
            str_parameters = f"{Variable1},{Variable2},{Variable3},{Variable4},{Variable5},{Variable6}"

            # Byte-Array erstellen
            byte_array = str_parameters.encode('ascii')

            print("Sende Werte")
            # Array senden
            await client.write_gatt_char(UUID3, byte_array)

            # Receive data from ESP32 via BLE
            received = False  # Variable to indicate whether data has been received

            while not received:
                data = await client.read_gatt_char(UUID3)
                if data:
                    value = data.decode('utf-8')
                    print(f"{value}")
                    received = True

    except Exception as e:
        print("Nicht verbunden")
        print(e)
What did i do wrong?

THX for help
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Print text with big font and style tomtom 6 20,254 Aug-13-2024, 07:26 AM
Last Post: yazistilleriio
Shocked async was never was never awaited but the await is still in the code Nietzsche 3 1,228 Jun-04-2024, 02:28 PM
Last Post: deanhystad
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 4,045 Apr-24-2024, 05:47 AM
Last Post: Bronjer
  how to open a popup window in tkinter with entry,label and button lunacy90 1 3,088 Sep-01-2023, 12:07 AM
Last Post: lunacy90
  Saving the print result in a text file Calli 8 3,935 Sep-25-2022, 06:38 PM
Last Post: snippsat
  count certain task in task manager[solved] kucingkembar 2 1,854 Aug-29-2022, 05:57 PM
Last Post: kucingkembar
Sad Selenium: can't open a new window after clicking a button and I don't know why noahverner1995 0 2,652 Jan-22-2022, 09:55 AM
Last Post: noahverner1995
  get data from 2 async functions korenron 0 1,684 Sep-22-2021, 08:39 AM
Last Post: korenron
  Open and read multiple text files and match words kozaizsvemira 3 8,372 Jul-07-2021, 11:27 AM
Last Post: Larz60+
  Set Text in Open Dialog Box giddyhead 0 2,344 May-21-2021, 06:31 PM
Last Post: giddyhead

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020