Skip to content

elsampsa/btdemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Bluetooth + DBus + gobject demo

Very simple python code, for learning bluetooth control by dbus.

Some preliminaries:

sudo apt-get install python3-dbus
sudo apt install bluez bluez-tools
systemctl --user start obex

Play with this demo program like this:

ipython3
%run bt_studio.py

# now you have managed_objects & devices_by_adr dictionaries
init()

devices_by_adr.keys() # shows you device address strings (i.e. macs)
# get mac address like this:
# str(devices_by_adr["58_C9_35_2F_A1_EF"]["Address"]) 

device = get_device("your-device-address-string")
# device = get_device("58_C9_35_2F_A1_EF")

adapter = get_adapter()

# wanna test pairing, but the device is already paired?  Do this:
adapter.RemoveDevice(device) 
adapter.StartDiscovery() # discovery the device again

# re-init the "devices_by_adr" dictionary
init() 

# create & set an agent that manages pairing (pin codes, etc.)
# in the current example all connections are accepted
# agent will run in the background
use_agent()

# send a file with obex file push to your mobile phone
# before that, you must install obex file transfer client/server on your mobile phone
# in google apps there are several alternatives
client = get_obex_client()

# source: your linux box hci interface mac, target: phone's interaface mac
session = get_obex_session(client, "9C:B6:D0:8C:5D:D6", "58:C9:35:2F:A1:EF") 
send_obex_file(session, "/home/sampsa/bluez/client/test.py")
del_obex_session(session)

stop_agent()
exit

For more information, consult the bt_studio.py file itself.

Links

pygobject and threading dbus-python notes 1 pygobject

Copyright

2019 Sampsa Riikonen

License

WTFPL

About

python bluetooth dbus demo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages