-
Notifications
You must be signed in to change notification settings - Fork 2
/
access_points.py
85 lines (68 loc) · 3.38 KB
/
access_points.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# importing libraries needed
import subprocess
import numpy
import time
signal_strength = {} # for storing ssids as keys and their signal strengths in dbm as values
distances = [] # for storing the distances from different access points
ssids_required = ['Moto G (5S) Plus 3393', 'ZTE_5G_qaquFU', 'ZTE_2.4G_qaquFU']
# function to get the signal strength values and converting them into 'dbm'
def signalstrength():
subprocess.run(['netsh', 'interface', 'set', 'interface', 'name="Wi-Fi"', 'admin=disabled'])
subprocess.run(['netsh', 'interface', 'set', 'interface', 'name="Wi-Fi"', 'admin=enabled'])
time.sleep(4)
# getting the result of the command of command prompt and storing it in a variable
result = subprocess.check_output(["netsh", "wlan", "show", "network", "mode=Bssid"])
# converting the result(datatype = bytes) first into string object and storing each individual substring in a
# list cmd_output
cmd_output_list = list((result.decode('ASCII')).split())
# getting all the indexes of words SSID, Network and Signal and storing them in lists
i_SSID = [index for index, x in enumerate(cmd_output_list) if x == 'SSID']
i_Network = [index for index, x in enumerate(cmd_output_list) if x == 'Network']
i_Signal = [index for index, x in enumerate(cmd_output_list) if x == 'Signal']
# getting the ssids present near and their corresponding received signal strengths
for m in range(len(i_SSID)):
c = cmd_output_list[(i_SSID[m] + 3):i_Network[m]]
c = tuple(c)
s = " "
if s.join(c) in ssids_required:
a = cmd_output_list[i_Signal[m]+2]
a = a[0: len(a)-1]
signal_strength[s.join(c)] = ((int(a)) / 2) - 100
print(signal_strength)
return signal_strength
# function to get distance from access point
# ss = signal strength due to access point at a particular point
# rss = reference signal strength at reference distance from access point
# n = signal attenuation factor
# rd = reference distance
def calc_distance(ss, rss, n, rd):
distance = rd * (10 ** ((rss - ss) / (10 * n)))
return distance
# function to get the coordinates of point
# parameters = position of access points and distances from those access points
def coordinates(x1, y1, z1, x2, y2, z2, x3, y3, z3, distance):
A = numpy.array(
[[(2 * (x1 - x3)), (2 * (y1 - y3)), (2 * (z1 - z3))], [(2 * (x2 - x3)), (2 * (y2 - y3)), (2 * (z2 - z3))]],
dtype=float)
B = numpy.array([[x1 ** 2 + y1 ** 2 + z1 ** 2 - x3 ** 2 - y3 ** 2 - z3 ** 2 - distance[0] ** 2 - distance[2] ** 2],
[x2 ** 2 + y2 ** 2 + z2 ** 2 - x3 ** 2 - y3 ** 2 - z3 ** 2 - distance[1] ** 2 - distance[2] ** 2]],
dtype=float)
A_transp = A.transpose()
X = numpy.linalg.inv(A_transp.dot(A)).dot(A_transp.dot(B))
x0 = X[0][0]
y0 = X[1][0]
z0 = X[2][0]
return x0, y0, z0
signal_strengths = signalstrength()
pld0 = [-41.4568, -41.4568, -41.4568] # reference signal strength at a distance of 1m from different access points
att_const = [3.6105, 3.6105, 3.6105] # attenuation constant for different access points in that environment
j = 0
for i in signal_strengths:
d = calc_distance(signal_strengths[i], pld0[j], att_const[j], 1)
distances.append(d)
j += 1
print(distances)
X0, Y0, Z0 = coordinates(6, 5.5, 1, 3.5, 6, 5, 1, 1, 5, distance=distances)
print(X0)
print(Y0)
print(Z0)