易于使用的rssi扫描包和利用rssi的自我定位。
rssi的Python项目详细描述
rssi python模块
随着物联网项目的空前高涨,在以下地区不断需要定位和本地化系统 GPS定位不可用。基于rssi的定位提供了使用 附近接入点(wifi路由器)的rssi(相对接收信号强度)。基于rssi的定位算法需要“n”号 的访问点,其中“n”>;=3个访问点。随着无线are网络和智能设备的发展, 建筑物中的wifi接入点越来越多,只要一个移动智能设备能检测到三个或更多 已知WiFi热点位置,相对容易实现自我定位(通常是WiFi接入点 位置是固定的,但要对移动的接入点进行修改。
此模块包含两个类:“rssi_scan”和“rssi_localizer”。 rssi_scan用于查找和返回范围内所有可用访问点的信息。 可以提供“networks”列表作为参数来筛选感兴趣的网络。
rssi_定位器用于自我定位,使用rssi_扫描返回的信息。这 类不能使用,除非使用三个或更多已知访问点。
本模块使用的算法完全基于朱秀艳、袁峰的算法 “基于rssi的室内定位算法”论文,发表于:https://file.scirp.org/pdf/CN_2013071010352139.pdf
存在用于网络扫描和RSSI本地化的Python和Java模块,但有必要 一个更广泛的包,可扩展到几乎无限数量的WiFi接入点。重点放在文件上 以及易用性。如果需要,这两个类都可以独立使用。
此软件包的设计应尽可能轻巧,便于在实时或软实时环境中使用。
开始
这些说明将为您在本地计算机上启动和运行项目的副本,以便进行开发和测试。
先决条件
运行这个模块需要一个python解释器。包与python 2.x或3.x兼容。
在使用这个包之前,需要安装numpy库。我们将更新此包以包含numpy依赖项。有关Numpy的安装,请参阅“与一起构建”部分。
安装
rssi包可以通过pip安装,也可以通过克隆这个github repo来安装。未来的版本将包括一个Linux的软件包安装程序。
说出步骤
pip install rssi
或
git clone https://github.com/jvillagomez/rssi_module.git
课程
rssi包包含两个类,帮助您扫描访问点(rss_scan)和基于rssi的自我定位(rssi_localizer)。 下面可以找到这两个类的方法。
rssi_扫描方法
getRawNetworkScan()
# Description:
# Runs the Ubuntu command 'iwlist' to scan for available networks.
# Returns the raw console window output (unparsed).
# ----------------------------------------------------------------
# Input: (optional)
# sudo: bool; defaults to false. False will not refresh the
# network interface upon query. Sudo=true will require
# the user will need to enter a sudo password at runtime.
# ----------------------------------------------------------------
# Returns: Raw terminal output
# {
# 'output':'''wlp1s0 Scan completed :
# Cell 01 - Address: A0:3D:6F:26:77:8E
# Channel:144
# Frequency:5.72 GHz
# Quality=43/70 Signal level=-67 dBm
# Encryption key:on
# ESSID:"ucrwpa"
# Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
# Mode:Master
# Cell 02 - Address: A0:3D:6F:26:77:82
# Channel:1
# Frequency:2.412 GHz (Channel 1)
# Quality=43/70 Signal level=-67 dBm
# Encryption key:on
# ESSID:"eduroam"
# Bit Rates:18 Mb/s; 24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
# Mode:Master''',
# 'error':''
# }
getapinfo()
# Description:
# Method returns all (or chosen) available access points (in range).
# Takes 2 optional parameters:
# 'networks' (array):
# Lists all ssid's of concern. Will return only the available access
# points listed here. If not provided, will return ALL access-points in range.
# 'sudo' (bool):
# Whether of not method should use sudo privileges. If user uses sudo
# privileges, the network manager will be refreshed and will return
# a fresh list of access-points available. If sudo is not provided,
# a cached list will be returned. Cached list gets updated periodically.
# -----------------------------------------------
# Input: (Parsed array of cell dictionaries)
# networks = (array of network names)
# ['ucrwpa','dd-wrt']
# sudo = True || False
# -----------------------------------------------
# Returns: (Array of dictionaries)
# [
# {
# 'ssid':'ucrwpa',
# 'quality':'43/70',
# 'signal':'-67'
# },
# {
# 'ssid':'dd-wrt',
# 'quality':'30/70',
# 'signal':'-42'
# }
# ]
rssi_定位器方法
getDistanceFromAP()
# Description:
# Uses the log model to compute an estimated dstance(di) from node(i)
# -------------------------------------------------------
# Input:
# accessPoint: dicitonary holding accesspoint info.
# {
# 'signalAttenuation': 3,
# 'location': {
# 'y': 1,
# 'x': 1
# },
# 'reference': {
# 'distance': 4,
# 'signal': -50
# },
# 'name': 'dd-wrt'
# }
# signalStrength: -69
# -------------------------------------------------------
# output:
# accessPoint: dicitonary holding accesspoint info.
# {
# 'signalAttenuation': 3,
# 'location': {
# 'y': 1,
# 'x': 1
# },
# 'reference': {
# 'distance': 4,
# 'signal': -50
# },
# 'name': 'dd-wrt'
# }
# signalStrength: -69,
# distance: 2
获取距离forallaps()
# Description:
# Makes use of 'getDistanceFromAP' to iterate through all
# accesspoints being used in localization and obtains the
# distance from each one of them.
# ------------------------------------------------
# Input:
# signalStrengths:
# [siganl1, siganl2, siganl3]
# [-42, -53, -77]
# ------------------------------------------------
# Output:
# [
# {
# 'distance': 4,
# 'x': 2,
# 'y': 3
# },
# {
# 'distance': 7,
# 'x': 2,
# 'y': 5
# },
# {
# 'distance': 9,
# 'x': 7,
# 'y': 3
# }
# ]
获取节点位置
# Description:
# Combines 'getDistancesForAllAPs', 'createMatrics',
# and 'computerPosition' to get the 'X' vector that
# contains our unkown (x,y) position.
# ----------------------------------------
# Input:
# signalStrengths
# [-44, -32 , -63]
# ----------------------------------------
# Output:
# x
# [2, 3]
示例用法
下面的示例演示如何在rssi模块中使用rssi_scan和rssi_定位器类。
初始化rssi_扫描
这个类帮助我们扫描可触及的所有可用访问点。 用户必须在初始化时提供网络接口名称。 即wlan0、docker0、wlp1s0
import rssi
interface = 'wlp1s0'
rssi_scanner = rssi.RSSI_Scan(interface)
扫描接入点
扫描特定接入点
import rssi
interface = 'wlp1s0'
rssi_scanner = rssi.RSSI_Scan(interface)
ssids = ['dd-wrt','linksys']
# sudo argument automatixally gets set for 'false', if the 'true' is not set manually.
# python file will have to be run with sudo privileges.
ap_info = rssi_scanner.getAPinfo(networks=ssids, sudo=True)
print(ap_info)
# prints
# [
# {
# 'ssid':'ucrwpa',
# 'quality':'43/70',
# 'signal':'-67'
# },
# {
# 'ssid':'dd-wrt',
# 'quality':'30/70',
# 'signal':'-42'
# }
# ]
扫描所有接入点
import rssi
interface = 'wlp1s0'
rssi_scanner = rssi.RSSI_Scan(interface)
ssids = ['dd-wrt','linksys']
# sudo argument automatixally gets set for 'false', if the 'true' is not set manually.
# python file will have to be run with sudo privileges.
ap_info = rssi_scanner.getAPinfo(sudo=True)
print(ap_info)
# prints
# [
# {
# 'ssid':'ucrwpa',
# 'quality':'43/70',
# 'signal':'-67'
# },
# {
# 'ssid':'dd-wrt',
# 'quality':'30/70',
# 'signal':'-42'
# },
# {
# 'ssid':'rosNet',
# 'quality':'30/70',
# 'signal':'-42'
# },
# {
# 'ssid':'openNetw',
# 'quality':'30/70',
# 'signal':'-42'
# }
# ]
初始化基于rssi的定位器
rssi_定位器
# Use:
# from rssi import RSSI_Localizer
# rssi_localizer_instance = RSSI_Localizer(accessPoints=accessPoints)
# -------------------------------------------------------
# Description:
# This class helps a user implement rssi-based localization.
# The algorithm assumes the logarithmic distance-path-loss model
# And assumes a minimum of 3 (or more) access points.
# -------------------------------------------------------
# Input:
# accessPoints: Array holding accessPoint dictionaries.
# The order of the arrays supplied will retain
# its order, throughout the entire execution.
# [{
# 'signalAttenuation': 3,
# 'location': {
# 'y': 1,
# 'x': 1
# },
# 'reference': {
# 'distance': 4,
# 'signal': -50
# },
# 'name': 'dd-wrt'
# },
# {
# 'signalAttenuation': 4,
# 'location': {
# 'y': 1,
# 'x': 7
# },
# 'reference': {
# 'distance': 3,
# 'signal': -41
# },
# 'name': 'ucrwpa'
# }]
估计到接入点的距离
from rssi import RSSI_Localizer
rssi_localizer_instance = RSSI_Localizer()
accessPoint = {
'signalAttenuation': 3,
'location': {
'y': 1,
'x': 1
},
'reference': {
'distance': 4,
'signal': -50
},
'name': 'dd-wrt'
}
signalStrength = -69
distance = rssi_localizer_instance.getDistanceFromAP(accessPoint, signalStrength)
print(distance)
# prints
# {
# 'signalAttenuation': 3,
# 'location': {
# 'y': 1,
# 'x': 1
# },
# 'reference': {
# 'distance': 4,
# 'signal': -50
# },
# 'name': 'dd-wrt',
# 'distance': 2
# }
估计所有接入点的距离
Same as the exmaple above, except accessPoints
need to be fed into the funciton inside of list.
The function will also return the same output as above in a list.
List order is persistent.
执行基于rssi的自我定位
Assuming RSSI_Scan and RSSI_Localizer have already been initialized.
ap_info = rssi.getAPinfo(networks=ssids, sudo=True)
rssi_values = [ap['signal'] for ap in ap_info]
position = localizer.getNodePosition(rssi_values)
print(position)
# prints a 1-D array holding [x,y]
使用
构建
import rssi
interface = 'wlp1s0'
rssi_scanner = rssi.RSSI_Scan(interface)
ssids = ['dd-wrt','linksys']
# sudo argument automatixally gets set for 'false', if the 'true' is not set manually.
# python file will have to be run with sudo privileges.
ap_info = rssi_scanner.getAPinfo(networks=ssids, sudo=True)
print(ap_info)
# prints
# [
# {
# 'ssid':'ucrwpa',
# 'quality':'43/70',
# 'signal':'-67'
# },
# {
# 'ssid':'dd-wrt',
# 'quality':'30/70',
# 'signal':'-42'
# }
# ]
import rssi
interface = 'wlp1s0'
rssi_scanner = rssi.RSSI_Scan(interface)
ssids = ['dd-wrt','linksys']
# sudo argument automatixally gets set for 'false', if the 'true' is not set manually.
# python file will have to be run with sudo privileges.
ap_info = rssi_scanner.getAPinfo(sudo=True)
print(ap_info)
# prints
# [
# {
# 'ssid':'ucrwpa',
# 'quality':'43/70',
# 'signal':'-67'
# },
# {
# 'ssid':'dd-wrt',
# 'quality':'30/70',
# 'signal':'-42'
# },
# {
# 'ssid':'rosNet',
# 'quality':'30/70',
# 'signal':'-42'
# },
# {
# 'ssid':'openNetw',
# 'quality':'30/70',
# 'signal':'-42'
# }
# ]
初始化基于rssi的定位器
rssi_定位器
# Use:
# from rssi import RSSI_Localizer
# rssi_localizer_instance = RSSI_Localizer(accessPoints=accessPoints)
# -------------------------------------------------------
# Description:
# This class helps a user implement rssi-based localization.
# The algorithm assumes the logarithmic distance-path-loss model
# And assumes a minimum of 3 (or more) access points.
# -------------------------------------------------------
# Input:
# accessPoints: Array holding accessPoint dictionaries.
# The order of the arrays supplied will retain
# its order, throughout the entire execution.
# [{
# 'signalAttenuation': 3,
# 'location': {
# 'y': 1,
# 'x': 1
# },
# 'reference': {
# 'distance': 4,
# 'signal': -50
# },
# 'name': 'dd-wrt'
# },
# {
# 'signalAttenuation': 4,
# 'location': {
# 'y': 1,
# 'x': 7
# },
# 'reference': {
# 'distance': 3,
# 'signal': -41
# },
# 'name': 'ucrwpa'
# }]
估计到接入点的距离
from rssi import RSSI_Localizer
rssi_localizer_instance = RSSI_Localizer()
accessPoint = {
'signalAttenuation': 3,
'location': {
'y': 1,
'x': 1
},
'reference': {
'distance': 4,
'signal': -50
},
'name': 'dd-wrt'
}
signalStrength = -69
distance = rssi_localizer_instance.getDistanceFromAP(accessPoint, signalStrength)
print(distance)
# prints
# {
# 'signalAttenuation': 3,
# 'location': {
# 'y': 1,
# 'x': 1
# },
# 'reference': {
# 'distance': 4,
# 'signal': -50
# },
# 'name': 'dd-wrt',
# 'distance': 2
# }
估计所有接入点的距离
Same as the exmaple above, except accessPoints
need to be fed into the funciton inside of list.
The function will also return the same output as above in a list.
List order is persistent.
执行基于rssi的自我定位
Assuming RSSI_Scan and RSSI_Localizer have already been initialized.
ap_info = rssi.getAPinfo(networks=ssids, sudo=True)
rssi_values = [ap['signal'] for ap in ap_info]
position = localizer.getNodePosition(rssi_values)
print(position)
# prints a 1-D array holding [x,y]
使用
构建这个包裹非常轻。本地python包之外的唯一依赖项是“numpy”。
- Numpy-基本包for使用python进行科学计算。
贡献
欢迎所有的贡献!这个包的创建是因为需要一个易于使用的模块,具有强大的文档,可扩展到所有用途。欢迎所有评论、请求和建议。
作者
- juan antonio villagomez-developer-jvillagomez
许可证
这个项目是在麻省理工学院的许可下授权的-请参见LICENSE.md文件了解详细信息
致谢
- 帽子提示朱秀岩和袁峰,为他们的出版基于rssi的室内定位。
- 向加州大学河滨分校的Akila Ganlath博士大喊。如果你不需要你的机器人的rssi定位,我就不会有mde这个包。