Added script to log wifi strength
[ros_wild_thumper.git] / scripts / wifistrength.py
1 #!/usr/bin/env python
2 # -*- coding: iso-8859-15 -*-
3
4 import os
5 import re
6 import rospy
7 import tf
8 import tf2_ros
9 from time import sleep
10
11 rospy.init_node('wifi_strength')
12
13 tfBuffer = tf2_ros.Buffer()
14 listener = tf2_ros.TransformListener(tfBuffer)
15 regex_lq = re.compile("Link Quality=(\d*)/(\d*)")
16 while not rospy.is_shutdown():
17         f = os.popen("export LANG=C; /sbin/iwconfig wlan0")
18         for line in f:
19                 line = line.strip()
20                 match_lq = regex_lq.match(line)
21                 if match_lq is not None:
22                         lq = float(match_lq.group(1)) / float(match_lq.group(2))
23                         pos = tfBuffer.lookup_transform("map", 'base_link', rospy.Time(0), rospy.Duration(1.0))
24                         print "{'x':%.2f, 'y':%.2f, 'link':%.2f}," % (pos.transform.translation.x, pos.transform.translation.y, lq)
25                         sleep(0.5)