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
And I get the error
But now, the script compile without ending or stopping.
I also tried after doing some research on asyncio :
I get the same Runtime error
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
1 2 3 4 5 6 7 8 9 10 11 |
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()) |
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 running
Then I tried to add nest_asyncio: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
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()) |
I also tried after doing some research on asyncio :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
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 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