Feb-14-2019, 09:19 AM
import blescan import bluetooth._bluetooth as bluez def calculate_accuracy(txpower, rssi): if rssi == 0 or txpower == 0: return -1 else: ratio = rssi/txpower if ratio < 1: return ratio**10 else: return 0.89976 * ratio**7.7095 + 0.111 return result def scan_sock(sock): blescan.hci_le_set_scan_parameters(sock) blescan.hci_enable_le_scan(sock) sample_count = 0 while True: returnedList = blescan.parse_events(sock, 10) print "----------" for beacon in returnedList: print beacon beacon = beacon.split(',') beaconid = beacon[0] txpower = float(beacon[4]) rssi = float(beacon[5]) if 0<= calculate_accuracy(txpower, rssi)< 2: print beaconid if __name__ == '__main__': dev_id = 0 try: sock = bluez.hci_open_dev(dev_id) print "ble thread started" scan_scan(sock) except: print "error accessing bluetooth device..."
####### fig = plt.figure() #fig.set_dpi(100) #fig.set_size_inches(7, 6.5) ax = plt.axes(xlim=(0, 100), ylim=(0, 100)) patch = plt.Circle((5, -5), 0.75, color='r',fill=False,clip_on=False) c1 = plt.Circle((5, -5), 0.75, fc='y') c2 = plt.Circle((5, -5), 0.75, fc='b') c3 = plt.Circle((5, -5), 0.75, fc='r') def init(): patch.center = (50, 50) c1.center = (5,5) c2.center= (10,10) ax.add_patch(c1); ax.add_patch(c2); ax.add_patch(patch) return patch, def animate(i): raw_cell = main() print raw_cell cell = raw_cell[0] distance = cell["Distance"] print distance patch.set_radius(float(distance)); return patch, anim = animation.FuncAnimation(fig, animate, init_func=init, interval=5000, blit=True) plt.show()I have written code for matplotlib but this code does not show the actual locations. I want him to show me the distance he took at the moment.
I can get the distance. But there is one more problem I want to show on this "matplotlib.pyplot" screen according to the distances. Can I use a particle filter? How do I adapt my Particle Filter to my codes?
I can find the ibeacon distances right now. the only problem I find is that I show distances as animation using particle filter or matplotlib.
https://github.com/AtsushiSakai/PythonRo..._filter.py