Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Ble Distance Problem
#5
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
Reply


Messages In This Thread
Python Ble Distance Problem - by aleynasarcanli - Feb-09-2018, 01:16 PM
RE: Python Ble Distance Problem - by buran - Feb-09-2018, 02:53 PM
RE: Python Ble Distance Problem - by aleynasarcanli - Feb-09-2018, 08:30 PM
RE: Python Ble Distance Problem - by buran - Feb-09-2018, 08:34 PM
RE: Python Ble Distance Problem - by aleynasarcanli - Feb-09-2018, 09:57 PM
RE: Python Ble Distance Problem - by buran - Feb-09-2018, 10:03 PM
RE: Python Ble Distance Problem - by aleynasarcanli - Feb-09-2018, 10:09 PM
RE: Python Ble Distance Problem - by buran - Feb-09-2018, 10:10 PM
RE: Python Ble Distance Problem - by buran - Feb-09-2018, 10:12 PM
RE: Python Ble Distance Problem - by buran - Feb-09-2018, 10:24 PM
RE: Python Ble Distance Problem - by aleynasarcanli - Feb-09-2018, 10:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Visualize Geo Map/Calculate distance zarize 1 1,951 Dec-05-2019, 08:36 PM
Last Post: Larz60+
  euclidean distance jenya56 3 2,917 Mar-29-2019, 02:56 AM
Last Post: scidam
  How to use servo motor with TFMini Distance Sensor in python script? programerguy 1 3,320 Dec-04-2018, 04:57 PM
Last Post: Larz60+
  organizing by distance gonzo620 7 4,075 Oct-16-2018, 01:41 AM
Last Post: stullis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020