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
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 923 Apr-24-2024, 05:47 AM
Last Post: Bronjer
  how to open a popup window in tkinter with entry,label and button lunacy90 1 901 Sep-01-2023, 12:07 AM
Last Post: lunacy90
  Saving the print result in a text file Calli 8 1,813 Sep-25-2022, 06:38 PM
Last Post: snippsat
  count certain task in task manager[solved] kucingkembar 2 1,133 Aug-29-2022, 05:57 PM
Last Post: kucingkembar
  Print text with big font and style tomtom 5 14,153 Mar-03-2022, 01:29 AM
Last Post: tomtom
Sad Selenium: can't open a new window after clicking a button and I don't know why noahverner1995 0 1,990 Jan-22-2022, 09:55 AM
Last Post: noahverner1995
  get data from 2 async functions korenron 0 1,231 Sep-22-2021, 08:39 AM
Last Post: korenron
  Open and read multiple text files and match words kozaizsvemira 3 6,771 Jul-07-2021, 11:27 AM
Last Post: Larz60+
  Set Text in Open Dialog Box giddyhead 0 1,681 May-21-2021, 06:31 PM
Last Post: giddyhead
  Schedule a task and render/ use the result of the task in any given time klllmmm 2 2,109 May-04-2021, 10:17 AM
Last Post: klllmmm

Forum Jump:

User Panel Messages

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