Sep-29-2021, 03:39 PM
Hello,
I would like to use Bleak library to read the datas from an Arduino nano 33 BLE sense.
I am a beginner so I am trying to do it step by step so that I understand what I do.
To start, I wanted to run the code from the library doc
I also tried after doing some research on asyncio :
I have found some codes from which I would like to get inspired, but I said I am trying to do it step by step.
https://github.com/Ladvien/arduino_ble_s...ter/app.py
https://github.com/protostax/ProtoStax_A...Central.py
Thanks in advance,
Alice
I would like to use Bleak library to read the datas from an Arduino nano 33 BLE sense.
I am a beginner so I am trying to do it step by step so that I understand what I do.
To start, I wanted to run the code from the library doc
import asyncio
from bleak import BleakScanner
async def run():
async with BleakScanner() as scanner:
await asyncio.sleep(5.0)
for d in scanner.discovered_devices:
print(d)
loop = asyncio.get_event_loop()
loop.run_until_complete(run())And I get the error Error:Traceback (most recent call last):
File "C:\Users\lemarqua\AppData\Local\Temp/ipykernel_7764/1465954928.py", line 1, in <module>
runfile('C:/Users/lemarqua/Documents/Python Scripts/test_bleak.py', wdir='C:/Users/lemarqua/Documents/Python Scripts')
File "C:\Users\lemarqua\Anaconda3\lib\site-packages\debugpy\_vendored\pydevd\_pydev_bundle\pydev_umd.py", line 167, in runfile
execfile(filename, namespace)
File "C:\Users\lemarqua\Anaconda3\lib\site-packages\debugpy\_vendored\pydevd\_pydev_imps\_pydev_execfile.py", line 25, in execfile
exec(compile(contents + "\n", file, 'exec'), glob, loc)
File "C:/Users/lemarqua/Documents/Python Scripts/test_bleak.py", line 18, in <module>
loop.run_until_complete(run())
File "C:\Users\lemarqua\Anaconda3\lib\asyncio\base_events.py", line 592, in run_until_complete
self._check_running()
File "C:\Users\lemarqua\Anaconda3\lib\asyncio\base_events.py", line 552, in _check_running
raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already runningThen I tried to add nest_asyncio: import asyncio
import nest_asyncio
nest_asyncio.apply()
from bleak import BleakScanner
async def run():
async with BleakScanner() as scanner:
await asyncio.sleep(5.0)
for d in scanner.discovered_devices:
print(d)
loop = asyncio.get_event_loop()
loop.run_until_complete(run())But now, the script compile without ending or stopping.I also tried after doing some research on asyncio :
import asyncio
#import nest_asyncio
#nest_asyncio.apply()
from bleak import BleakScanner
async def run():
async with BleakScanner() as scanner:
await asyncio.sleep(5.0)
for d in scanner.discovered_devices:
print(d)
def main():
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
loop.close()
main()I get the same Runtime errorI have found some codes from which I would like to get inspired, but I said I am trying to do it step by step.
https://github.com/Ladvien/arduino_ble_s...ter/app.py
https://github.com/protostax/ProtoStax_A...Central.py
Thanks in advance,
Alice
