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