Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-104
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2022-104
2022-104
Commits
435bcf06
Commit
435bcf06
authored
Oct 10, 2022
by
P.M.P.C Bandara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Http control
parent
5f800a4b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
156 additions
and
0 deletions
+156
-0
httpcontrol_2.py
httpcontrol_2.py
+156
-0
No files found.
httpcontrol_2.py
0 → 100644
View file @
435bcf06
#!/usr/bin/env python3
import
RPi.GPIO
as
GPIO
import
os
import
time
from
http.server
import
BaseHTTPRequestHandler
,
HTTPServer
host_name
=
'192.168.8.104'
# IP Address of Raspberry Pi
host_port
=
8000
def
setupGPIO
():
#GPIO.setmode(GPIO.BCM)
#GPIO.setwarnings(False)
#GPIO.setup(18, GPIO.OUT)
GPIO
.
setmode
(
GPIO
.
BCM
)
GPIO
.
setup
(
17
,
GPIO
.
OUT
)
GPIO
.
setup
(
22
,
GPIO
.
OUT
)
GPIO
.
setup
(
23
,
GPIO
.
OUT
)
GPIO
.
setup
(
24
,
GPIO
.
OUT
)
def
forward
(
sec
):
setupGPIO
()
GPIO
.
output
(
17
,
True
)
GPIO
.
output
(
22
,
False
)
GPIO
.
output
(
23
,
True
)
GPIO
.
output
(
24
,
False
)
time
.
sleep
(
sec
)
GPIO
.
cleanup
()
def
reverse
(
sec
):
setupGPIO
()
GPIO
.
output
(
17
,
False
)
GPIO
.
output
(
22
,
True
)
GPIO
.
output
(
23
,
False
)
GPIO
.
output
(
24
,
True
)
time
.
sleep
(
sec
)
GPIO
.
cleanup
()
def
right
(
sec
):
setupGPIO
()
GPIO
.
output
(
23
,
True
)
GPIO
.
output
(
24
,
False
)
time
.
sleep
(
sec
)
GPIO
.
cleanup
()
def
left
(
sec
):
setupGPIO
()
GPIO
.
output
(
23
,
False
)
GPIO
.
output
(
24
,
True
)
time
.
sleep
(
sec
)
GPIO
.
cleanup
()
def
getTemperature
():
temp
=
os
.
popen
(
"/opt/vc/bin/vcgencmd measure_temp"
)
.
read
()
return
temp
class
MyServer
(
BaseHTTPRequestHandler
):
def
do_HEAD
(
self
):
self
.
send_response
(
200
)
self
.
send_header
(
'Content-type'
,
'text/html'
)
self
.
end_headers
()
def
_redirect
(
self
,
path
):
self
.
send_response
(
303
)
self
.
send_header
(
'Content-type'
,
'text/html'
)
self
.
send_header
(
'Location'
,
path
)
self
.
end_headers
()
def
do_GET
(
self
):
html
=
'''
<html>
<body
style="width:960px; margin: 20px auto;">
<h1>Robot Navigator</h1>
<p>Current GPU temperature is {}</p>
<form action="/" method="POST">
<table>
<tr>
<td style="vertical-align: center;;text-align: center;"> <input type="submit" name="submit" value="Plant 1-1"><img src="https://www.clipartkey.com/mpngs/m/33-330352_transparent-soil-png-little-plant-transparent-background.png" style="width:40
%
"/></td>
<td style="vertical-align: center;;text-align: center;"> <input type="submit" name="submit" value="Plant 1-2"><img src="https://www.clipartkey.com/mpngs/m/33-330352_transparent-soil-png-little-plant-transparent-background.png" style="width:40
%
"/></td>
<td style="vertical-align: center;;text-align: center;"> <input type="submit" name="submit" value="Plant 1-3"><img src="https://www.clipartkey.com/mpngs/m/33-330352_transparent-soil-png-little-plant-transparent-background.png" style="width:40
%
"/></td>
</tr>
<td style="vertical-align: center;;text-align: center;"> <input type="submit" name="submit" value="Plant 2-1"><img src="https://www.clipartkey.com/mpngs/m/33-330352_transparent-soil-png-little-plant-transparent-background.png" style="width:40
%
"/></td>
<td style="vertical-align: center;;text-align: center;"> <input type="submit" name="submit" value="Plant 2-2"><img src="https://www.clipartkey.com/mpngs/m/33-330352_transparent-soil-png-little-plant-transparent-background.png" style="width:40
%
"/></td>
<td style="vertical-align: center;;text-align: center;"> <input type="submit" name="submit" value="Plant 2-3"><img src="https://www.clipartkey.com/mpngs/m/33-330352_transparent-soil-png-little-plant-transparent-background.png" style="width:40
%
"/></td>
</tr>
<td style="vertical-align: center;;text-align: center;"> <input type="submit" name="submit" value="Plant 3-1"><img src="https://www.clipartkey.com/mpngs/m/33-330352_transparent-soil-png-little-plant-transparent-background.png" style="width:40
%
"/></td>
<td style="vertical-align: center;;text-align: center;"> <input type="submit" name="submit" value="Plant 3-2"><img src="https://www.clipartkey.com/mpngs/m/33-330352_transparent-soil-png-little-plant-transparent-background.png" style="width:40
%
"/></td>
<td style="vertical-align: center;;text-align: center;"> <input type="submit" name="submit" value="Plant 3-3"><img src="https://www.clipartkey.com/mpngs/m/33-330352_transparent-soil-png-little-plant-transparent-background.png" style="width:40
%
"/></td>
</tr>
</table>
</form>
<br/><br/>
<h4>View dashboard information</h4>
<iframe src="dashboard (2).xlsx"></iframe>
</body>
</html>
'''
temp
=
getTemperature
()
self
.
do_HEAD
()
self
.
wfile
.
write
(
html
.
format
(
temp
[
5
:])
.
encode
(
"utf-8"
))
def
do_POST
(
self
):
content_length
=
int
(
self
.
headers
[
'Content-Length'
])
post_data
=
self
.
rfile
.
read
(
content_length
)
.
decode
(
"utf-8"
)
post_data
=
post_data
.
split
(
"="
)[
1
]
if
post_data
==
'Plant 1-1'
:
forward
(
1
)
elif
post_data
==
'Plant 1-2'
:
forward
(
2
)
elif
post_data
==
'Plant 1-3'
:
forward
(
3
)
elif
post_data
==
'Plant 2-1'
:
forward
(
1
)
elif
post_data
==
'Plant 2-2'
:
forward
(
2
)
elif
post_data
==
'Plant 2-3'
:
forward
(
3
)
elif
post_data
==
'Plant 3-1'
:
forward
(
1
)
elif
post_data
==
'Plant 3-2'
:
forward
(
2
)
elif
post_data
==
'Plant 3-3'
:
forward
(
3
)
else
:
forward
(
2
)
exec
(
open
(
'distance.py'
)
.
read
())
print
(
"Plant no is {}"
.
format
(
post_data
))
self
.
_redirect
(
'/'
)
# Redirect back to the root url
# # # # # Main # # # # #
if
__name__
==
'__main__'
:
http_server
=
HTTPServer
((
host_name
,
host_port
),
MyServer
)
print
(
"Server Starts -
%
s:
%
s"
%
(
host_name
,
host_port
))
try
:
http_server
.
serve_forever
()
except
KeyboardInterrupt
:
http_server
.
server_close
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment