-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdBmLoss.py
65 lines (54 loc) · 1.65 KB
/
dBmLoss.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
from math import log10
from sys import argv
'''
# estimate free space dBm attenuation:
# ...using wfi module BCM43143:
Tx = 19~20 dBm
Rx = not clear how low we can go here
d = distance Tx --> Rx
f = frequency
c = attenuation constant: meters / MHz = -27.55; see here for more info:
https://en.wikipedia.org/wiki/Free-space_path_loss
'''
f = 2400 # MHz
c = 27.55 # RF attenuation constant (in meters / MHz)
def_Tx = 20 # expected dBm transmit
def_Rx = 40 # (absolute value) of negative dBm thesh
def logdBm(num):
return 20 * log10(num)
def maxDist(Rx, Tx):
dBm = 0
d = .1 # meters!
while dBm < Tx + Rx:
dBm = logdBm(d) + logdBm(f) - Tx - Rx + c
d += .1 # meters!
return d
# Why not use this with arguments Tx + Rx from shell if we want:
def useargs():
use = bool
try:
if len(argv) == 3:
use = True
elif len(argv) == 1:
print('\n\nyou can add (default) Rx Tx arguments using the following syntax: \n \
python3 dBmLoss.py 20 40 \n \
python3 dBmLoss.py <Rx> <Tx> \
\n')
use = False
else:
print('you must use both Rx & Tx arguments or no arguments')
raise SystemExit
except:
print('you must use both Rx & Tx arguments or no arguments')
raise SystemExit
return use
def main():
if useargs() == True:
arg = [int(argv[1]), int(argv[2])]
else:
arg = [def_Rx, def_Tx]
print(str('\n ' + str(maxDist(arg[0], arg[1])*3.281) + \
' ft = max. mesh node spacing, @ \n' + \
' Rx = ' + str(arg[0]) + '\n' + \
' Tx = ' + str(arg[1])))
main()