Feb-09-2018, 09:57 PM
(This post was last modified: Feb-09-2018, 09:58 PM by aleynasarcanli.)
Code below, i want to make if in range, print beacon id (range 2 meters)
import blescan import sys import bluetooth._bluetooth as bluez dev_id = 0 try: sock = bluez.hci_open_dev(dev_id) print "ble thread started" except: print "error accessing bluetooth device..." sys.exit(1) blescan.hci_le_set_scan_parameters(sock) blescan.hci_enable_le_scan(sock) def calculate_accuracy(txpower, rssi): if rssi == 0: return -1 else: ratio = rssi/txpower if ratio < 1: return ratio**10 else: return 0.89976 * ratio**7.7095 + 0.111 while True: returnedList = blescan.parse_events(sock, 10) print "----------" for beacon in returnedList: print beacon beaconid = beacon.split(",")[0] txpower = beacon.split(",")[4] rssi = beacon.split(",")[5] calculate_accuracy(txpower, rssi) if calculate_accuracy < 2: print beaconid