在python脚本中ble in termux
我正在写我的学士学位论文,并且我已经成功地在Python编辑了一个脚本,该脚本使用BLE从Arduino Nano 33 IoT收集数据。我现在希望在我的Android手机上在Termux上运行此Python脚本:这是麻烦的!我的教授警告我,可能会出现一些试图在Android上使用BLE的问题。
使用BLE的惨淡库中的一个示例如下:
import asyncio
from bleak import BleakScanner
async def main():
devices = await BleakScanner.discover()
for d in devices:
print(d)
asyncio.run(main())
但是我在Termux上遇到了此错误:
python scanBLE.py
Traceback (most recent call last):
File "/storage/emulated/0/Download/python/scanBLE.py", line 2, in <module>
from bleak import BleakScanner
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/bleak/init.py", line 41, in <module>
if not _on_ci and not check_bluez_version(5, 43):
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/init.py", line 17, in check_bluez_version
p = subprocess.Popen(["bluetoothctl", "--version"], stdout=subprocess.PIPE)
File "/data/data/com.termux/files/usr/lib/python3.10/subprocess.py", line 966, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "/data/data/com.termux/files/usr/lib/python3.10/subprocess.py", line 1840, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'bluetoothctl'
请不要告诉我我必须扎根手机!所以我的问题是:是否有一种方法可以从termux中运行的python代码访问ble?
I'm writing my bachelor thesis and I've successfully compiled a script in python which uses BLE to gather data from an Arduino nano 33 IoT. I now wish to run this python script on termux on my android phone: here comes the trouble! My professor warned me about some problems that might occur trying to use BLE on Android.
An example from the Bleak library using BLE is the following:
import asyncio
from bleak import BleakScanner
async def main():
devices = await BleakScanner.discover()
for d in devices:
print(d)
asyncio.run(main())
but I get this error on termux:
python scanBLE.py
Traceback (most recent call last):
File "/storage/emulated/0/Download/python/scanBLE.py", line 2, in <module>
from bleak import BleakScanner
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/bleak/init.py", line 41, in <module>
if not _on_ci and not check_bluez_version(5, 43):
File "/data/data/com.termux/files/usr/lib/python3.10/site-packages/bleak/backends/bluezdbus/init.py", line 17, in check_bluez_version
p = subprocess.Popen(["bluetoothctl", "--version"], stdout=subprocess.PIPE)
File "/data/data/com.termux/files/usr/lib/python3.10/subprocess.py", line 966, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "/data/data/com.termux/files/usr/lib/python3.10/subprocess.py", line 1840, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'bluetoothctl'
Please don't tell me that I have to root my phone! So my question is: Is there a way to give access to the BLE from a python code running in termux ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论