Click here to Skip to main content
15,793,546 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have a M! Mac 13.1 running Python 3.10. I'm trying to write Python code that discovers any bluetooth devices near me. This is the code...

import objc
from Cocoa import NSObject
from IOBluetooth import IOBluetoothDeviceInquiry

class BLEDeviceDiscovery(NSObject):

    def init(self):
        self = super(BLEDeviceDiscovery, self).init()
        if self is None:
            return None
        self.discovery =
        return self

    def deviceInquiryDeviceFound_(self, sender, device):
        print(f"Found a device: {device}")

    def deviceInquiryStarted_(self, sender):
        print("Starting discovery...")

    def deviceInquiryUpdatingDeviceNamesStartedDevicesRemaining_(self, sender, devicesRemaining):
        print(f"Updating names... {devicesRemaining} devices remaining.")

    def deviceInquiryCompleteWithError_aborted_(self, sender, error, aborted):
        if aborted:
            print("Device inquiry was aborted.")
        elif error:
            print(f"Error during device inquiry: {error}")
            print("Device discovery completed.")

    def start_discovery(self):

def main():
    ble_discovery = BLEDeviceDiscovery.alloc().init()

if __name__ == "__main__":
Here is the result....
(react) johnd@Johns-MacBook-Pro MacPython % python3
Traceback (most recent call last):
  File "/Volumes/T7/Programming/CrunchComm/MacPython/", line 5, in <module>
TypeError: 'module' object is not callable 

What I have tried:

According to ChatGPT, I tried the following....

It seems that there is still a discrepancy in the method signature of the delegate function deviceInquiryDeviceFound:deviceWithNames:RSSI:. The method signature expected by the framework should match exactly.
Here's the corrected code for that method:
def deviceInquiryDeviceFound_deviceWithNames_RSSI_(self, sender, device, names, rssi):
    print(f"Found a device: {device}")
    print(f"Names: {names}")
    print(f"RSSI: {rssi}")

None of this is working... ChatGPT is no help, it keeps giving me the same fixes, and I'm going back and forth many times.
Updated 28-Aug-23 13:27pm
Richard MacCutchan 25-Aug-23 4:33am    
"ChatGPT is no help"
Then don't use it, it is a machine, not a programming expert.
John Draper 2023 25-Aug-23 4:48am    
I read this document several times. I'm looking for example code on how to "Discover" BLE devices. I agree, chatGPT is brain dead, so is Can you give me some references to example code? How much would you charge for a Zoom session with this 80 year old USAF disabled veteran? I would use VirtualBox and linux but the Mac M1 don't support it. Is there anyway you can help me?
John Draper 2023 25-Aug-23 4:57am    
I have other code examples I got from ChatGPT, but everyone has errors. If you want to look at them, I can send them along as well. I'm pretty inexperienced in coding, but have been pretty successful in soliciting good responses from ChatGPT and Bard. There appears to be some kind of "Gotcha" somewhere in this code... I did try other sources of Python libraries, none successful. With my disability, I don't have much of an opportunity to meet other programmers more experienced.
Dave Kreskowiak 25-Aug-23 10:08am    
ChatGPT cannot write code. Think of it as a toddler trying to please its parents, even if it gets answers wrong. The objective to is please, not be correct.

1 solution

Share this answer
John Draper 2023 1-Sep-23 20:10pm    
After checking round with help from ChatGPT - it refers to my M1 laptop does not yet support PyBluez module. Nobody has posted a correction or workaround for this, if anyone has, please let me know.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900