我有 3 个或更多节点,并且我想使用基于 RSSI 之间的每个节点之间距离的估计来执行定位。
为此,我尝试在它接收的 RSSI 的每个节点上创建一个列表,然后在所有节点之间共享这些列表。我有一个 python 脚本,它将所有 RSSI 以及接收和发送节点捕获到列表的子列表中。
代码如下:
import subprocess
def matching_line(lines, keyword):
"""Returns the first matching line in a list of lines. See match()"""
for line in lines:
matching=match(line,keyword)
if matching!=None:
return matching
return None
def match(line,keyword):
"""If the first part of line (modulo blanks) matches keyword,
returns the end of that line. Otherwise returns None"""
line=line.lstrip()
length=len(keyword)
if line[:length] == keyword:
return line[length:]
else:
return None
neighbour = [] #list of local node and neighbour's addresses
scanned = {} # dictionary containing iwlist scan results Address: RSSI
single_localisation = [[],[],[]] #list of iwlist scan results at a single node. Node's address, transmitting node's address, RSSI
all_localisation = [[],[],[]] #list of iwlist scan results from all nodes. Receiving node's address, transmitting node's address, RSSI
#Save batctl o to file - batctl o shows all the nodes nearby participating in the mesh
Proc=subprocess.Popen("batctl o > bato.txt", shell=true)
Proc.wait()
#Populate neighbour list with addresses of neighbouring nodes
with open("bat.txt") as fd:
fd.readline() #skip column headings
for line in fd:
neighbour.append(line.split()[0])
#Add local node's Address to neighbour list for later comparison
neigbour.append( subprocess.check_output("ip link show wlan0 | grep link | awk '{print $2}'",shell=True).strip())
#Scan wlan2 and save to file
Proc=subprocess.Popen("iwlist wlan2 scan | awk '/ESSID/ {print $1} /level/ {print $3}' > rssi.txt", shell=true)
Proc.wait()
#Populate scanned list with all MAC addresses and RSSIs from file
cells=cells[1:]
with open("rssi.txt") as fd:
for line in fd:
cell_line = match(line,"Cell ")
if cell_line != None:
cells.append([])
line = cell_line[-27:]
cells[-1].append(line.rstrip())
for cell in cells:
level.append(matching_line(cell,"Quality=").split()[2].split('=')[1])
address.append(matching_line(cell,"Address: "))
scanned=dict(zip(address, level))
#Test if MAC address in scanned list matches MAC address in neighbour list (and is therefore a meshed node)
for s in scanned:
if s in neighbour:
#if it does make an entry in localisation for it
localisation[0].append( subprocess.check_output("ip link show wlan0 | grep link | awk '{print $2}'",shell=True).strip())
localisation[1].append(s)
localisation[2].append(scanned[s])
所以
- localisation[0] 包含本地节点的 MAC
- localisation[1] 包含发送节点的 MAC
- localisation[2] 包含 [0] 从 [1] 接收到的信号强度
我想以某种方式合并所有节点上的所有本地化列表,以创建一个每个节点都有的大列表。
有没有一种方法可以使用 paramiko(或替代方法)通过 SSH 共享生成的列表?