bla bla bla bla jupyter has no spellcheck so drink when you find spelling errors
https://github.com/hackgnar/pyubertooth
Why not just use the provided CLI C tools and C libs?
In [1]:
import time
import sys
sys.path.insert(0,"/Users/rholeman/src/pyubertooth")
from pyubertooth.ubertooth import Ubertooth, ubertooth_rx_to_stdout
from pylibbtbb.bluetooth_packet import BtbbPacket
import bluetooth
In [2]:
u = Ubertooth()
In [3]:
print "serial: %s" % u.cmd_get_serial()
print "part number: %s" % u.cmd_get_partnum()
print "board id: %s" % u.cmd_get_board_id()
In [4]:
for data in u.rx_stream(count=5):
print data
u.cmd_stop()
In [5]:
u.cmd_led_specan()
In [6]:
u.cmd_stop()
In [9]:
u.cmd_get_channel()
Out[9]:
In [8]:
u.cmd_set_channel(50)
In [38]:
for i in range(10):
print u.cmd_get_clock()
In [37]:
u.cmd_set_clock()
In [39]:
for i in range(10):
time.sleep(1)
u.cmd_set_usrled(state=i%2)
In [40]:
for i in range(100):
time.sleep(0.1)
x = u.cmd_get_clock()
u.cmd_set_usrled(state=x%2)
x = u.cmd_get_clock()
u.cmd_set_rxled(state=x%2)
x = u.cmd_get_clock()
u.cmd_set_txled(state=x%2)
We can even add some different spins on this by changing settings while doing live streams. For example, we can add channel survey (this wasnt always available in the CLI) with the following:
channel = u.cmd_get_channel()
channel += 1
u.cmd_set_channel(channel % 79)
In [47]:
results = []
for data in u.rx_stream():
channel = u.cmd_get_channel()
channel += 1
u.cmd_set_channel(channel % 79)
pkt = BtbbPacket(data=data)
if pkt.LAP:
results.append(pkt)
print pkt
if len(results) > 10:
break
u.cmd_stop()
In [49]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
tmp = {}
for i in results:
if i.LAP in tmp:
tmp[i.LAP] += 1
else:
tmp[i.LAP] = 1
LAPs = tmp.keys()
lap_count = tmp.values()
y_pos = np.arange(len(LAPs))
fig = plt.figure(figsize=(10, 5))
plt.barh(y_pos, lap_count, align='center', alpha=0.4)
plt.yticks(y_pos, LAPs)
plt.xlabel('count')
plt.title('who is out there?')
plt.show()
In [50]:
u_results = list(set([i.LAP for i in results]))
u_results
Out[50]:
In [ ]:
brute_uap = [chr(x).encode("hex") for x in range(256)]
brute_uap
for i in brute_uap:
address = "0000%s%s" % (i,u_results[0])
print "trying %s" % address
try:
results = bluetooth.find_service(address=address)
if results:
print results
break
except:
pass