Skip to content

Commit

Permalink
a few fixes. Changed deepstream IP back to localhost, and supressed P…
Browse files Browse the repository at this point in the history
…open stderr
  • Loading branch information
Richard Stanley committed Jan 10, 2018
1 parent 670eccb commit 3a0afa1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion rover/core/servers/iftop/deepstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import requests
import json

roverIp = "10.42.0.1" # This ip will change periodically,
roverIp = "localhost" # This ip will change periodically,
# for now, this is the ip of the rover on openvpn

def get(recordName):
Expand Down
43 changes: 25 additions & 18 deletions rover/core/servers/iftop/iftop.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@
from deepstream import post
import subprocess, re

print("Loading: iftop")
recordName = "speed"
interface = "wlp3s0"

# Number in seconds to switch to autonomous/manual Mode
elapsedTimout = 16

obj = {}

success = ""

while success == "":
try:
success = post(obj, recordName)
success = post({"mode": "manual"}, "mode")
except:
print("Not connected to deepstream")
try:
success = post(obj, recordName)
success = post({"mode": "manual"}, "mode")
except:
print("Not connected to deepstream")
sleep(1)

ipAddress = " NOREC"
upload = 0
Expand All @@ -33,13 +35,13 @@ def getUpDownData():
try:
# command: sudo iftop -o 10s -t -s 10 -L 1 -i wlp3s0
elapsedTime = 0
p = Popen([ "iftop", "-o", "10s", "-t", "-s", "10", "-L", "1", "-i", interface ], stdout=subprocess.PIPE)
out, err = p.communicate()
print(elapsedTime)
p = Popen([ "iftop", "-o", "10s", "-t", "-s", "10", "-L", "1", "-i", interface ], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
out = p[0]
err = p[1]

uploadArr = re.findall(r"Total send rate:\s+(\d{1,}\.{0,1}\d{0,})(\w+)", out)
downloadArr = re.findall(r"Total receive rate:\s+(\d{1,}\.{0,1}\d{0,})(\w+)", out)
ipAddressArr = re.findall(r"(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})", out)
ipAddressArr = re.findall(r"IP address is:\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})", err)
if ipAddressArr is not []:
ipAddress = ipAddressArr[0]

Expand All @@ -54,15 +56,20 @@ def getUpDownData():
upload = upload * 1000000
if downloadArr[0][1] == "Mb":
download = download * 1000000
print "upload: {} {} download: {} {} ip: {}".format(upload, uploadArr[0][1], download , downloadArr[0][1], ipAddress)
post({"upload": upload, "download": download, "ip": ipAddress, "elapsed": elapsedTime}, recordName)
obj = {"upload": upload, "download": download, "ip": ipAddress, "elapsed": elapsedTime}
#print "upload: {} {} download: {} {} ip: {}".format(upload, uploadArr[0][1], download , downloadArr[0][1], ipAddress)
dsSuccess = post(obj, recordName)
print(obj)
uploadArr = []
downloadArr = []
except:
try:
post({}, "speed")
print("No data from interface: " + interface)
sleep(1)
post({}, "speed")
print("No data from interface: " + interface)
sleep(1)
except:
print("cannot connect to deepstream.")
print("cannot connect to deepstream.")


def checkElapsedTime():
global elapsedTime
Expand All @@ -82,4 +89,4 @@ def checkElapsedTime():
t2 = Thread(target=checkElapsedTime)

t1.start()
t2.start()
t2.start()

0 comments on commit 3a0afa1

Please sign in to comment.