This repository was archived by the owner on Mar 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtxpower-check.py
More file actions
executable file
·167 lines (121 loc) · 3.94 KB
/
Copy pathtxpower-check.py
File metadata and controls
executable file
·167 lines (121 loc) · 3.94 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/python3
# -*- coding: utf-8; -*-
import json
import os
import os.path
import sys
# taken from gluon 2016.2.4 libiwinfo hardware.txt
model_offsets = {
"Ubiquiti PicoStation2 HP": 1000,
"Ubiquiti LiteStation2": 1000,
"Ubiquiti LiteStation5": 500,
"Ubiquiti NanoStation2": 1000,
"Ubiquiti NanoStation5": 500,
"Ubiquiti NanoStation Loco2": 1000,
"Ubiquiti NanoStation Loco5": 500,
"Ubiquiti Bullet2": 1000,
"Ubiquiti Bullet5": 500,
"Ubiquiti PicoStation M2": 1200,
"Ubiquiti NanoStation M2": 1100,
"Ubiquiti NanoStation Loco M2": 800,
"Ubiquiti NanoStation M5": 1600,
"Ubiquiti Bullet M2": 1200,
"Ubiquiti Bullet M5": 500,
}
def get_name(nodes, node_id):
for n in nodes['nodes']:
if 'nodeinfo' not in n:
continue
if 'node_id' not in n['nodeinfo']:
continue
if node_id != n['nodeinfo']['node_id']:
continue
if 'hostname' not in n['nodeinfo']:
continue
return n['nodeinfo']['hostname']
return None
# WARNING this is not actually 100% correct because it depends also on
# configured channel width
#
# from see wireless-regdb.git/tree/db.txt?h=master-2017-03-07
def get_regdb(frequency):
if frequency >= 2400 and frequency <= 2483.5:
return 2000
if frequency >= 5150 and frequency <= 5250:
return 2000
if frequency >= 5250 and frequency <= 5350:
return 2000
if frequency >= 5470 and frequency <= 5725:
return 2700
if frequency >= 5725 and frequency <= 5875:
return 1400
if frequency >= 57000 and frequency <= 66000:
return 4000
return None
def get_limits(model, txpowers):
offset = 0
if model in model_offsets:
offset = model_offsets[model]
limits = []
for power in txpowers:
if 'frequency' not in power:
continue
if 'mbm' not in power:
continue
regdb = get_regdb(power['frequency'])
if not regdb:
continue
limit = {
'frequency': power['frequency'],
'mbm': power['mbm'] + offset,
'regdb': regdb,
}
# skip nodes which have a correct txpower limit
if limit['mbm'] <= limit['regdb']:
continue
limits.append(limit)
return limits
def print_limits(node_limits, nodes):
for node_id, data in node_limits.items():
name = get_name(nodes, node_id)
if name:
print(" * %s" % name)
print(" - https://vogtland.freifunk.net/map/#!/map/%s" % node_id)
for limit in data:
cur = limit['mbm']
freq = limit['frequency']
regdb = limit['regdb']
print(" - %u.%03u GHz: %3u.%02u dBm (limit %3u.%02u dBm)" % (
int(freq / 1000), int(freq % 1000),
int(cur / 100), int(cur % 100),
int(regdb / 100), int(regdb % 100)))
def main():
if len(sys.argv) != 2:
print("./txpower-check.py nodes.json")
sys.exit(1)
nodes_in = sys.argv[1]
# load
nodes = json.load(open(nodes_in))
node_limits = {}
for n in nodes['nodes']:
if 'statistics' not in n:
continue
if 'txpower' not in n['statistics']:
continue
if 'nodeinfo' not in n:
continue
if 'node_id' not in n['nodeinfo']:
continue
if 'hardware' not in n['nodeinfo']:
continue
if 'model' not in n['nodeinfo']['hardware']:
continue
node_id = n['nodeinfo']['node_id']
txpowers = n['statistics']['txpower']
model = n['nodeinfo']['hardware']['model']
limits = get_limits(model, txpowers)
if limits:
node_limits[node_id] = limits
print_limits(node_limits, nodes)
if __name__ == "__main__":
main()