Skip to content

Commit

Permalink
First station commit with all Jan-Jun 2017 work
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Carlos Aguilera Perez committed Aug 26, 2017
0 parents commit 00bef40
Show file tree
Hide file tree
Showing 28 changed files with 1,920 additions and 0 deletions.
Binary file added 1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DronePhoto1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DronePhoto2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file added __pycache__/bluetoothServer.cpython-34.pyc
Binary file not shown.
Binary file added __pycache__/challenges.cpython-34.pyc
Binary file not shown.
Binary file added __pycache__/variables.cpython-34.pyc
Binary file not shown.
Binary file added __pycache__/xbee.cpython-34.pyc
Binary file not shown.
222 changes: 222 additions & 0 deletions auvsiServerCommunication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
#!/usr/bin/env python
import sys
import json
import requests
'''
server = IP
server = http://...
'''
url2 = 'http://betatestback.journeytheapp.com' ;
url = 'http://ec2-52-0-198-215.compute-1.amazonaws.com' ;

teamCode = 'VTEC' ;
PORT = 8080 ;
#PORT = 80;
PORT_AUVSI = 8080 ;

retryCount = 0 ;
connectionLost = False;
courseA = 'courseA';
courseB = 'courseB';
courseC = 'courseC';

def send_http_followLeader(course):
'''
GET
/followLeader/{course}/{teamCode}
'''
'''
expected return value {"code":"23"}
'''
addr = '/followLeader/';

server = url + addr + course + '/' + teamCode ;

r = requests.get(server);

#print(server)

if(r.status_code == 200):
print ('Status 200: OK');
print((r.text))
elif(r.status_code == 400):
print('Status 400: The requested Form isnt Ok, Please check it');
elif(r.status_code == 404):
print('Status 404: Course or Team are Wrong');
elif(r.status_code == 500):
print('Status 500: The gate assigment is broken');
elif(r.status_code == 503):
print('Status 503: Please try the request again');
if(retryCount < 100):
send_http_heartbeat(course,timestamp,challenge,latitude,longitude)
else:
retryCount = 0;
connectionLost = True;

def send_http_heartbeat(course,timestamp,challenge,latitude,longitude):
'''
POST
/heartbeat/
course
teamCode
timestamp = YYYYMMDDHHMMSS in UTC
challenge = "speed", "docking", "path", "follow" or "return"
latitude = hddd.dddddd
longitude = hddd.dddddd
'''
'''
expected return value {"success":<status>}
status = true //Run still active
status = felse //Run have ended
'''
addr = '/heartbeat/' + course + '/' + teamCode;

server = url + addr ;

payload = {"timestamp":str(timestamp),"challenge":challenge,"position":{"datum":"WGS84","latitude":round(latitude,6),"longitude":round(longitude,6)}}

r = requests.post(server, data=json.dumps(payload), headers={'Content-type': 'application/json'}) ;

#print("-----Heartbeat: ")
#print(challenge)
#print(r)
#print(payload)

if(r.status_code == 200):
print ('Status 200: OK');
print((r.text))
elif(r.status_code == 400):
print('Status 400: The requested Form isnt Ok, Please check it');
elif(r.status_code == 404):
print('Status 404: Course or Team are Wrong');
elif(r.status_code == 500):
print('Status 500: The gate assigment is broken');
elif(r.status_code == 503):
print('Status 503: Please try the request again');
if(retryCount < 100):
send_http_heartbeat(course,timestamp,challenge,latitude,longitude)
else:
print("Response unexpected")


def send_http_start(course):
'''
POST
/run/start
course
teamCode
'''
'''
expected return value {"success":<status>}
status = true //Run still active
status = felse //Run have ended
'''
addr = '/run/start/' + course + '/' + teamCode;

server = url + addr ;

#print(server)
r = requests.post(server);

#print(server)
#print(payload)

if(r.status_code == 200):
print ('Status 200: OK');
print((r.text))
elif(r.status_code == 400):
print('Status 400: The requested Form isnt Ok, Please check it');
elif(r.status_code == 404):
print('Status 404: Course or Team are Wrong');
elif(r.status_code == 500):
print('Status 500: The gate assigment is broken');
elif(r.status_code == 503):
print('Status 503: Please try the request again');
if(retryCount < 100):
send_http_heartbeat(course,timestamp,challenge,latitude,longitude)

def send_http_end(course):
'''
POST
/run/end
course
teamCode
'''
'''
expected return value {"success":<status>}
status = true //Run still active
status = felse //Run have ended
'''
addr = '/run/end/' + course + '/' + teamCode;

server = url + addr ;

print(server)

r = requests.post(server);

if(r.status_code == 200):
print ('Status 200: OK');
print((r.text))
elif(r.status_code == 400):
print('Status 400: The requested Form isnt Ok, Please check it');
elif(r.status_code == 404):
print('Status 404: Course or Team are Wrong');
elif(r.status_code == 500):
print('Status 500: The gate assigment is broken');
elif(r.status_code == 503):
print('Status 503: Please try the request again');
if(retryCount < 100):
send_http_heartbeat(course,timestamp,challenge,latitude,longitude)


def send_http_docking(course,filename):
'''
POST
/docking/image/
course
teamCode
name = file
filename = 'test.jpg'
'''
'''
expected return value {"id":<imageID>}}
'''

print("--- Send image to AUVSI ---")

addr = '/docking/image/' + course +'/' + teamCode ;

header = {'Content-type':'multipart/form-data', 'Content-Length':7280} ;

server = url + addr ;

files = {'name' : open(filename,'rb') }

payload = {'filename': filename } ;

r = requests.post(server, data = payload, files=files) ;
imgId = '-1'
if(r.status_code == 100):
print ('Status 100: Server is ready to accept multipart chunk');
elif(r.status_code == 200):
print ('Status 200: OK');
print((r.text))
imgId = json.loads(r.text)
elif(r.status_code == 202):
print('Status 202: Upload successfully completed');
print((r.text))
imgId = json.loads(r.text)
elif(r.status_code == 400):
print('Status 400: The requested Form isnt Ok, Please check it');
elif(r.status_code == 404):
print('Status 404: Course or Team are Wrong');
elif(r.status_code == 500):
print('Status 500: The gate assigment is broken');
elif(r.status_code == 503):
print('Status 503: Please try the request again');
if(retryCount < 100):
send_http_heartbeat(course,timestamp,challenge,latitude,longitude)

return imgId

Loading

0 comments on commit 00bef40

Please sign in to comment.