Skip to content

Instantly share code, notes, and snippets.

@patchedsoul
Created February 4, 2020 16:45
Show Gist options
  • Save patchedsoul/6fb3bed0f4812cb0af794b8747aac12c to your computer and use it in GitHub Desktop.
Save patchedsoul/6fb3bed0f4812cb0af794b8747aac12c to your computer and use it in GitHub Desktop.
pydbus advertisement experiment
#!/usr/bin/env python3
import pydbus
from gi.repository import GLib
class Advertisement(object):
"""
<node>
<interface name="org.bluez.LEAdvertisement1">
<method name="Release">
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<annotation name="org.freedesktop.DBus.Properties.PropertiesChanged" value="const"/>
<property name="Type" type="s" access="read"/>
<property name="ServiceUUIDs" type="as" access="read"/>
<property name="ManufacturerData" type="a{sv}" access="read"/>
<property name="SolicitUUIDs" type="as" access="read"/>
<property name="ServiceData" type="a{sv}" access="read"/>
<property name="IncludeTxPower" type="b" access="read"/>
</interface>
</node>
"""
def __init__(self, bus):
self.Type = 'peripheral'
self.ServiceUUIDs = []
self.ManufacturerData = {}
self.SolicitUUIDs = []
self.ServiceData = {}
self.IncludeTxPower = False
bus.register_object('/nic/twigpilot', self, None)
def Release(self):
print('{}: Advertisement Released!'.format(self))
def main():
bus = pydbus.SystemBus()
adaptor = bus.get('org.bluez', '/org/bluez/hci0')
adaptor.Powered = True
adaptor.Alias = 'SeeMe'
advertisement = Advertisement(bus)
advertisement.IncludeTxPower = True
#adaptor.RegisterAdvertisement('/nic/twigpilot', {})
loop = GLib.MainLoop()
try:
loop.run()
except KeyboardInterrupt:
loop.quit()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment