-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start of basic robot-controlling http server
- Loading branch information
Showing
9 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import errors | ||
import web | ||
|
||
class drive: | ||
def GET(self): | ||
print "VROOOOM!" | ||
raise errors.NotSupportedError | ||
return "This should return a 405 - Not Supported Error" | ||
|
||
#POST excepts a single command in plain teext. | ||
#Current supported commands: forward', 'reverse', 'left', or 'right' | ||
def POST(self): | ||
print ("web.data: %s" % web.data()) #'forward', 'reverse', 'left', or 'right' | ||
direction = web.data() | ||
if direction not in ['forward', 'reverse', 'left', 'right']: | ||
raise errors.BadRequestError | ||
|
||
#Set robot direction here... | ||
|
||
return "Updated direction" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import web | ||
|
||
#405 error when incorrect action is used on a resource | ||
class NotSupportedError(web.HTTPError): | ||
def __init__(self): | ||
status = '405 Method Not Alloweds' | ||
headers = {'Content-Type': 'text/html'} | ||
data = 'That method is not valid for this action.' | ||
web.HTTPError.__init__(self, status, headers, data) | ||
|
||
#400 error when invalid data is sent to a resource | ||
class BadRequestError(web.HTTPError): | ||
def __init__(self): | ||
status = '400' | ||
headers = {'Content-Type': 'text/html'} | ||
data = 'Invalid data supplied in request.' | ||
web.HTTPError.__init__(self, status, headers, data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import web | ||
from drive import drive | ||
|
||
urls = ( | ||
'/', 'index', | ||
'/drive', 'drive', | ||
) | ||
app = web.application(urls, globals()) | ||
|
||
#index raises a 301 error pointing to the index.html page | ||
class index: | ||
def GET(self): | ||
raise web.seeother('/static/index.html') | ||
|
||
#405 error when incorrect action is used on a resource | ||
class NotSupportedError(web.HTTPError): | ||
def __init__(self): | ||
status = '405 Method Not Alloweds' | ||
headers = {'Content-Type': 'text/html'} | ||
data = 'That method is not valid for this action.' | ||
web.HTTPError.__init__(self, status, headers, data) | ||
|
||
#400 error when invalid data is sent to a resource | ||
class BadRequestError(web.HTTPError): | ||
def __init__(self): | ||
status = '400' | ||
headers = {'Content-Type': 'text/html'} | ||
data = 'Invalid data supplied in request.' | ||
web.HTTPError.__init__(self, status, headers, data) | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
app.run() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<html> | ||
<head> | ||
<script type='text/javascript'> | ||
anchorclick = function(dir){ | ||
console.log("Anchor click"); | ||
postMoveDirection(dir) | ||
return false; | ||
} | ||
|
||
postMoveDirection = function(dir){ | ||
console.log('Derp') | ||
var request = new XMLHttpRequest(); | ||
request.open('POST', '/drive'); | ||
request.setRequestHeader('Content-Type', 'text'); | ||
|
||
request.onload = function(){ | ||
if(this.status >= 200 && this.status < 400){ | ||
resp = this.response; | ||
console.log("Sent POST request, got back ", resp); | ||
} else { | ||
|
||
console.log("Error sending POST request: ", this.response); | ||
} | ||
|
||
} | ||
request.send(dir) | ||
return false //Cancels event | ||
} | ||
</script> | ||
</head> | ||
|
||
<body> | ||
<h1 align=center >Project Battleaxe Controls</h1> | ||
|
||
<br> | ||
|
||
<table> | ||
<tr> | ||
<td></td> | ||
<td><a href="#" onclick="postMoveDirection('forward')"><img src='/static/forward.png'/></a></td> | ||
<td></td> | ||
</tr> | ||
<tr> | ||
<td><a href="#" onclick="postMoveDirection('left')"><img src='/static/left.png'/></a></td> | ||
<td align="center"><font size="18"><a href="#" onclick="postMoveDirection('notvalidyet')"><b>A</b></a></font></td> | ||
<td><a href="#" onclick="postMoveDirection('right')"><img src='/static/right.png'/></a></td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td><a href="#" onclick="postMoveDirection('reverse')"><img src='/static/reverse.png'/></a></td> | ||
<td></td> | ||
</tr> | ||
</table> | ||
|
||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.