Giter Site home page Giter Site logo

btdemo's Introduction

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

btdemo's People

Contributors

elsampsa avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.