我有3個或更多的節點,我想要使用基於各個之間的RSSI之間的距離估計來執行本地化。如何遠程運行python腳本,但在本地使用結果列表?
要做到這一點,我試圖在接收到的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])
所以
- 本地化[0]包含本地節點的MAC
- 本地化[1]包含發射節點的MAC
- 本地化[ 2]包含由[0]從[0]接收的信號強度
我想以某種方式合併所有節點上的所有本地化列表,以創建每個節點都有的大型列表。
有沒有一種方法,我可以通過使用paramiko(或其他)在SSH上共享產生的列表?
這只是在每個主機上生成文件的代碼,您希望以某種方式發送給主機?如果是這樣,這個問題似乎沒有關係。 – abarnert 2013-04-04 20:54:19
同時,是的,當然你可以使用'paramiko'通過SSH共享產生的列表。你是否想要['paramiko.SFTPClient'](http://www.lag.net/paramiko/docs/paramiko.SFTPClient-class.html)或其他什麼樣的代碼,或者你有不同的問題? – abarnert 2013-04-04 20:55:12