Open kevincar opened 2 years ago
Sorry about the slow response, I've been travelling a bit (first time in 2 years), and am working on updates for the macOS 13 SDK.
The code samples you provided should be enough to reproduce the issue on my end. I expect to get around to this either next weekend.
I'm finally getting around to looking into this, and notice that I'm missing some information on how to reproduce this. In particular: how do I scan for a peripheral? With both the ObjC and Python variants I don't see the advertised device when using the Bluetooth settings pane on an iOS device.
I recommend using the nRF Connect app.
On macOS Sonoma I do get an advertised name when adding the following to the end of the python script to get a complete program:
from Cocoa import NSRunLoop
perifical = PyPeripheral.alloc().init()
loop = NSRunLoop.currentRunLoop()
loop.run()
That said, actually connecting using the 'nRF Connect' app on my iPhone doesn't work (failed to encrypt the connection).
And a different app ("LightBlue") that's used in a tutorial about CoreBluetooth doesn't see the name.
I'm never used CoreBluetooth myself, and to be honest I'm not sure how to debug this and if the connection error is to be expected. I did notice that I get different results in the iPhone app when I change the UUIDs. In particular, I changed the service and characteristics uuid to ones mentioned in this stackoverflow question and that changed how the service and characteristic are formatted. Sadly, still no connection possible.
UPDATE: I get the same result when I insert the Python code into a simple GUI program with the app bundle created using py2app.
On macOS Sonoma I do get an advertised name when adding the following to the end of the python script to get a complete program:
When I follow this guide and run the previous code, I can find it on the iPhone. But I encountered another problem:
self.service_name = "PyBLE-test"
When the length of my service_name exceeds 8, the device cannot be discovered.
Describe the bug When advertising a program in bluetooth peripheral mode, the local name is not broadcast when using pyobj vs Objective-C.
CBPeripheralManager startAdvertising takes a dictionary as it's argument. One of the values is CBAdvertisementDataLocalNameKey. Calling this message from Objective-C works, allowing surrounding devices that are scanning for peripherals to identify the device name as the given to the function. When doing the same from pyobjc, all bluetooth capabilities seem to work except for the name of the device. Wondering what the best way to trouble shoot this would be.
Platform information
To Reproduce
PyObjc version
Happy to edit this and attach as files to decrease verbosity
Expected behavior A call to
[[Peripheral alloc] init]
in objective-C orPyPeripheral.alloc().init()
in python will start advertising and should advertise the name as givenAdditional context I've started testing by mixing these two codes using python extensions. For example, building the peripheral file into an object file that I can then turn into a python extension and call from a
__main__
file still works. It seems at this point that name advertising begins to fail when either theCBPeripheralManager
or theCBPeripheralManagerDelegate
are initialized in pyobjc. There could be more at play but not sure.