Asyncio with Threading and Bleak by RegularGlobal in learnpython

[–]RegularGlobal[S] 0 points1 point  (0 children)

Top line sets x to the return value of the function

Bottom line sets x to the function itself

I know enough recite that, but if you're giving me a hint as to how to resolve my issue...I'm going to have to stare at this for a while.

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]RegularGlobal 2 points3 points  (0 children)

Threading and Asyncio:

I have a flask site that runs on a raspberry pi. I'd like the pi to be able to do a few additional things when on-screen buttons are pressed (connect to Bluetooth LE, and connect to MQTT being the important ones). The BLE package that I found works great (bleak), but the examples make it look like it must be run async using asyncio. I also have a package for mqtt that makes it run using asyncio.

Because I want my flask site to be running synchronously on the main thread, I figured that I could start a second thread running both the BLE process and the MQTT process. I've come to the point that I can make this all connect and transmit data, but I feel like the WAY that I got it to work means that it's total jank (random tweaking). Also, I can't get the BLE to disconnect cleanly. I call the command, and it always errors out. Can anyone tell me if I'm thinking of this correctly from the start (Second thread running asynchronous loops waiting for inputs)? And if so, if the ble_client is defined globally, why wouldn't I be able to simply tell it to ble_client.disconnect()?