1

This is a rather intricate question. I am having trouble writing some code that will capture incoming bluetooth packets from a certain device. I am on mac and using lightblue, if anyone could help me out or point me in the right direction I would be very happy.

Here is the code I am using:

import bluetooth  
hostMACAddress = '00:1f:e1:dd:08:3d' #example address, not the real one
port = 3 
backlog = 1
size = 1024
s = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
s.bind((hostMACAddress, port))
s.listen(backlog)
try:
    client, clientInfo = s.accept()
    while 1:
        data = client.recv(size)
        if data:
            print(data)
            client.send(data) # Echo back to client
except: 
     print("Closing socket")
     client.close()
     s.close()

With the code above I am trying to capture the incoming packets that are sent from the external device. I get an error, and I believe I am not doing it right. I get this error when running:

import bluetooth 
  File "/Library/Python/2.6/site-packages/bluetooth/__init__.py", line 36, in <module>
from osx import *
  File "/Library/Python/2.6/site-packages/bluetooth/osx.py", line 3, in <module>
    raise NotImplementedError
NotImplementedError

I have never done anything with communications and I am very confused.

Thank you for reading

Kennet Celeste
  • 4,593
  • 3
  • 25
  • 34
Bob
  • 353
  • 5
  • 14
  • @SylvainLeroux Updated question. Thank you for your advice. Sorry for the inconvenience. – Bob Apr 11 '15 at 16:23
  • Looking at the code, the exception is thrown probably due to `device not found`, are you sure the bluetooth device is turned on and being searchable? – Anzel Apr 11 '15 at 16:39
  • @Anzel System Preferences and Bluetooth Settings both say that the device is connected – Bob Apr 11 '15 at 19:46
  • Then are you sure your library `bluetooth` has indeed installed properly and successfully? Normally the installation will require some other dependencies to be installed (like C extension etc.). I am not familiar to BT protocol so cannot really offer any helpful advice. – Anzel Apr 11 '15 at 20:05
  • @Anzel I will check instilatio again, thank you for your advice – Bob Apr 11 '15 at 21:12

0 Answers0