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

Setting new set of advertisements produces NoReply error #423

Open
andpuc23 opened this issue Jan 23, 2025 · 0 comments
Open

Setting new set of advertisements produces NoReply error #423

andpuc23 opened this issue Jan 23, 2025 · 0 comments

Comments

@andpuc23
Copy link

andpuc23 commented Jan 23, 2025

I use bluezero to advertise the data to BLE devices around me without pairing to them.
I try to implement the following sequence: (it works in Java already, using that is not an option)

  1. Advertise "query" command to devices
  2. Each device responds with its unique id
  3. Advertise "flash" command with specific device id (all devices whose id is different ignore the command)

I can send "query" and receive the responses (using bleak library), the problem arises when I need to send 2-nd command.

Here's the code stripped of sensitive and non-relevant data:

class BluetoothSender:
    beacon = broadcaster.Beacon()
    def __init__(self):    
        self.ad_manager = advertisement.AdvertisingManager(self.beacon.dongle.address)
        self.ads = []
        
    def add_advertisement(self, manufacturer_data, uid):
        global ad_id
        new_ad = advertisement.Advertisement(ad_id+1, 'broadcast')
        ad_id += 1
        new_ad.manufacturer_data(INGY_ID, manufacturer_data)
        # converting uid to format "12345678-1234-1234-1234-1234567890AB"
        new_ad.service_UUIDs = [uid_str] # in 
        self.ads.append(new_ad)
        self.ad_manager.register_advertisement(new_ad)

    def start_advertising(self):
        if not self.beacon.dongle.powered:
            self.beacon.dongle.powered = True
        for ad in self.ads:
            ad.start()
        
    def unregister_ads(self):
        for ad in self.ads:
            ad.stop()
            self.ad_manager.unregister_advertisement(ad)
        self.ads = []


    async def advertise_for(self, timeout_seconds):
        p = Process(target=self.start_advertising)
        p.start()
        await asyncio.sleep(timeout_seconds)
        p.terminate()

driver code:

beacon = BluetoothSender()

beacon.add_advertisement(manufacturer_data, uuid)

task = asyncio.create_task(beacon.advertise_for(time))
await task


 uuid, man_data = flash_command.encode()

# tried with the old beacon object as well
del beacon
new_beacon = BluetoothSender()

new_beacon.add_advertisement(man_data, uuid)
new_task = asyncio.create_task(new_beacon.advertise_for(time))

await new_task

Everything goes fine until I try to advertise the 2-nd time. On ad.start() DBus throws an error:

Failed to register advertisement: org.freedesktop.DBus.Error.UnknownMethod: Method "RegisterAdvertisement" with signature "sa{sv}" on interface "org.bluez.LEAdvertisingManager1" doesn't exist

I found this answer at stackoverflow, however I do not understand if this is done when I create a new beacon object (I guess so?) or not.

In any case, there is this issue and I require your help.

Thanks in advance!

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

1 participant