aboutsummaryrefslogtreecommitdiff
path: root/ParrotZik.py
diff options
context:
space:
mode:
Diffstat (limited to 'ParrotZik.py')
-rw-r--r--ParrotZik.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/ParrotZik.py b/ParrotZik.py
index 73df83b..4510e27 100644
--- a/ParrotZik.py
+++ b/ParrotZik.py
@@ -1,6 +1,11 @@
#!/usr/bin/env python
-import bluetooth
+import sys
+if sys.platform == "darwin":
+ import lightblue
+else:
+ import bluetooth
+
import ParrotProtocol
import struct
from BeautifulSoup import BeautifulSoup
@@ -9,7 +14,11 @@ class ParrotZik(object):
def __init__(self,addr=None):
uuid = "0ef0f502-f0ee-46c9-986c-54ed027807fb"
- service_matches = bluetooth.find_service( uuid = uuid, address = addr )
+
+ if sys.platform == "darwin":
+ service_matches = lightblue.findservices( name = "RFCOMM", addr = addr )
+ else:
+ service_matches = bluetooth.find_service( uuid = uuid, address = addr )
if len(service_matches) == 0:
print "Failed to find Parrot Zik RFCOMM service"
@@ -23,7 +32,11 @@ class ParrotZik(object):
print "Connecting to \"%s\" on %s" % (name, host)
- self.sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
+ if sys.platform == "darwin":
+ self.sock=lightblue.lightblueSocket( lightblue.RFCOMM )
+ else:
+ self.sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
+
self.sock.connect((host, port))
self.sock.send('\x00\x03\x00')
@@ -115,10 +128,9 @@ class ParrotZik(object):
self.sock =""
return
data = self.sock.recv(7)
- len = struct.unpack('B', data[1])[0]
data = self.sock.recv(1024)
data=BeautifulSoup(data)
return data
def Close(self):
- self.sock.close()
+ self.sock.close() \ No newline at end of file