Рет қаралды 275
there is information gap in internet how to create kivy app that connects using android bluetooth to raspberry pi bluetooth.
steps to repeat:
1. server-examples (should be started on raspberry).
git clone github.com/pybluez/pybluez
sudo apt install libbluetooth-dev
python setup.py install --user
There we see in pybluez/examples/simple - rfcomm-server.py
But as example dont work the working code should be looking like this:
#!/usr/bin/env python3
import bluetooth
server_sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
server_sock.bind(("", bluetooth.PORT_ANY))
server_sock.listen(1)
port = server_sock.getsockname()[1]
uuid = "00001101-0000-1000-8000-00805F9B34FB"
bluetooth.advertise_service(server_sock, "SampleServer", service_id=uuid,
service_classes=[uuid, bluetooth.SERIAL_PORT_CLASS],
profiles=[bluetooth.SERIAL_PORT_PROFILE],
protocols=[bluetooth.OBEX_UUID]
)
print("Waiting for connection on RFCOMM channel", port)
client_sock, client_info = server_sock.accept()
print("Accepted connection from", client_info)
try:
while True:
data = client_sock.recv(1024)
if not data:
break
print("Received", data)
except OSError as e:
print(e)#pass
print("Disconnected.")
client_sock.close()
server_sock.close()
print("All done.")
*uuid could be whatever u want but it should be the same as in kivy app.
2. to build kivy app: buildozer,kivy,kivymd should be installed. could be installed by pip:
pip install buildozer,kivy,kivymd
they say NOT to install `em by pip but i did and nothing happened - everything works (i work on ubuntu).
u cant install everything to raspberry (kivy and kivymd will but buildozer fails and without it u wont build app. trust me here i tried on Bookworm).
3.after buildozer init on its dir (standard procedure to start working with it after install - buildozer init) it forms .spec file. this is something like config to future app.
at that dir you also need main file - main.py - that will be the app.
So in buildozer dir we have:
-buildozer.spec
-main.py
Copy-paste files provided to replace ONLY main.py:
main.py - drive.google.com/file/d/1U2uD...
buildozer.spec - drive.google.com/file/d/1qHXq...
because buildozer.spec usually platform specific and one shouldnt blind replace it. Try to replace and build. But if fails just take from there lines that not commented (by #).
4. Build kivy app. In dir with files above type in console:
buildozer android debug
This will make an .apk file that u can copy-paste that .apk to your android phone and install "by hands".
The end.