Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not up-to-date with Bluez 5.50 stack #1

Open
dhruvkakadiya opened this issue Mar 1, 2019 · 1 comment
Open

Not up-to-date with Bluez 5.50 stack #1

dhruvkakadiya opened this issue Mar 1, 2019 · 1 comment

Comments

@dhruvkakadiya
Copy link

dhruvkakadiya commented Mar 1, 2019

There are several things need to be updated in bluez_components.py file as to support latest functionalities in the latest stack. Also several functionalities are missing like setting data values and local name in the advertisement.

For example, I have below changes in my local branch.

diff --git a/src/bluez_components.py b/src/bluez_components.py
index cbe1f2a..ab2f6be 100644
--- a/src/bluez_components.py
+++ b/src/bluez_components.py
@@ -241,12 +241,14 @@ class Advertisement(dbus.service.Object):
     def __init__(self, bus, index, advertising_type):
         self.path = self.PATH_BASE + str(index)
         self.bus = bus
+        self.local_name = None
         self.ad_type = advertising_type
         self.service_uuids = None
         self.manufacturer_data = None
         self.solicit_uuids = None
         self.service_data = None
         self.include_tx_power = None
+        self.data = None
         dbus.service.Object.__init__(self, bus, self.path)
 
     def get_properties(self):
@@ -260,14 +262,21 @@ class Advertisement(dbus.service.Object):
                                                     signature='s')
         if self.manufacturer_data is not None:
             properties['ManufacturerData'] = dbus.Dictionary(
-                self.manufacturer_data, signature='qay')
+                self.manufacturer_data, signature='qv')
         if self.service_data is not None:
             properties['ServiceData'] = dbus.Dictionary(self.service_data,
-                                                        signature='say')
+                                                        signature='sv')
+        if self.local_name is not None:
+            properties['LocalName'] = dbus.String(self.local_name)
         if self.include_tx_power is not None:
             properties['IncludeTxPower'] = dbus.Boolean(self.include_tx_power)
         return {LE_ADVERTISEMENT_IFACE: properties}
 
+        if self.data is not None:
+            properties['Data'] = dbus.Dictionary(
+                self.data, signature='yv')
+        return {LE_ADVERTISEMENT_IFACE: properties}
+
     def get_path(self):
         return dbus.ObjectPath(self.path)
 
@@ -283,13 +292,23 @@ class Advertisement(dbus.service.Object):
 
     def add_manufacturer_data(self, manuf_code, data):
         if not self.manufacturer_data:
-            self.manufacturer_data = dict()
-        self.manufacturer_data[manuf_code] = data
+            self.manufacturer_data = dbus.Dictionary({}, signature='qv')
+        self.manufacturer_data[manuf_code] = dbus.Array(data, signature='y')
 
     def add_service_data(self, uuid, data):
         if not self.service_data:
-            self.service_data = dict()
-        self.service_data[uuid] = data
+            self.service_data = dbus.Dictionary({}, signature='sv')
+        self.service_data[uuid] = dbus.Array(data, signature='y')
+
+    def add_local_name(self, name):
+        if not self.local_name:
+            self.local_name = ""
+        self.local_name = dbus.String(name)
+
+    def add_data(self, ad_type, data):
+        if not self.data:
+            self.data = dbus.Dictionary({}, signature='yv')
+        self.data[ad_type] = dbus.Array(data, signature='y')
 
     @dbus.service.method(DBUS_PROP_IFACE,
                          in_signature='s',

I have tested above changes for Bluez5-5.50 stack and they are working fine. I am also looking at changes to set advertising params as well.

@WIStudent
Copy link
Owner

Thanks for the info. I haven't actively worked on this demo project since I created it in 2016. Back then BlueZ's BLE advertisement API was still marked as experimental. I pulled the code in bluez_components.py from BlueZ's own examples, so it is no surprise that some things have changed. For now I don't have enough time to come back to this project, but I will keep this issue open so that others can see that BlueZ's API has changed in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants