One of the pages on my Coop Control web page controls the door

Below is the HTML code for the division controlling the door. The numbers at the bottom of the
screen are preset locations to aim the pan/tilt camera.

<div id=”view3″>
&nbsp;
<div style=”font: font-family: ‘Lucida Calligraphy’; font-size: x-large; font-weight: bold; color: #cc0000; font-family: ‘Lucida Calligraphy’;”>Chicken Coop door</div>
<table>
<tbody>
<tr>
<td><center>
<a href=”http://192.168.0.150/www/open_coop.py” target=”didit”>Open Door</a><img src=”images/greenbuttonmed.png” alt=”green” />&nbsp;
</center></td>
<td rowspan=”2″><a href=”http://192.168.0.150/www/coophome.py” target=”didit”>
<img id=”coopdoor” style=”border: thick outset Green;” src=”http://192.168.0.164/videostream.cgi?user=admin&amp;pwd=iamat1face” alt=”” width=”100%” /></a></td>
<td><center>
<a href=”http://192.168.0.150/www/stop_coop_door.py/stop_coop_door” target=”didit”>Stop Opening</a><img src=”images/redbuttonmed.png” alt=”red” />&nbsp;
</center></td>
</tr>
<tr>
<td><center>
<a href=”http://192.168.0.150/www/close_coop.py” target=”didit”>Close Door</a><img src=”images/greenbuttonmed.png” alt=”green” />&nbsp;
</center></td>
<td><center>
<a href=”/www/stop_coop_door.py/stop_coop_door” target=”didit”>Stop Closing</a><img src=”images/redbuttonmed.png” alt=”red” />&nbsp;
</center></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td><a href=”http://192.168.0.164/decoder_control.cgi?command=31&amp;user=admin&amp;pwd=iamat1face” target=”didit”><img src=”/images/glass_numbers_1.png” alt=”” /></a></td>
<td><a href=”http://192.168.0.164/decoder_control.cgi?command=33&amp;user=admin&amp;pwd=iamat1face” target=”didit”><img src=”/images/glass_numbers_2.png” alt=”” /></a></td>
<td><a href=”http://192.168.0.164/decoder_control.cgi?command=35&amp;user=admin&amp;pwd=iamat1face” target=”didit”><img src=”/images/glass_numbers_3.png” alt=”” /></a></td>
<td><a href=”http://192.168.0.164/decoder_control.cgi?command=37&amp;user=admin&amp;pwd=iamat1face” target=”didit”><img src=”/images/glass_numbers_4.png” alt=”” /></a></td>
<td><a href=”http://192.168.0.164/decoder_control.cgi?command=39&amp;user=admin&amp;pwd=iamat1face” target=”didit”><img src=”/images/glass_numbers_5.png” alt=”” /></a></td>
<td><a href=”http://192.168.0.164/decoder_control.cgi?command=41&amp;user=admin&amp;pwd=iamat1face” target=”didit”><img src=”/images/glass_numbers_6.png” alt=”” /></a></td>
<td><a href=”http://192.168.0.164/decoder_control.cgi?command=43&amp;user=admin&amp;pwd=iamat1face” target=”didit”><img src=”/images/glass_numbers_7.png” alt=”” /></a></td>
<td><a href=”http://192.168.0.164/decoder_control.cgi?command=45&amp;user=admin&amp;pwd=iamat1face” target=”didit”><img src=”/images/glass_numbers_8.png” alt=”” /></a></td>
</tr>
</tbody>
</table>
<iframe style=”width: 100%;” name=”didit” width=”300″ height=”150″ frameborder=”0″ align=”middle”></iframe>
</div>

in Essence, clicking on a button calls a python program on the coop server
which returns the result to a frame on the calling page.
This is because most browsers disallow commands to servers other than the one
serving the page but do allow requests for an HTML document or image.
<a href=”http://192.168.0.150/www/open_coop.py” target=”didit”>Open Door</a>
above is the href called when the open button is pressed
Below is the python code called:
import httplib2
def index(req):
h = httplib2.Http()
resp_headers, content = h.request("http://192.168.0.150/x201on3.py", "PUT")
print(content.decode("utf-8"))
return(content.decode("utf-8"))
if __name__ == '__main__':
index('open_coop')

As you can see, it becomes even more convoluted as the python code calls another
python program to operate the relays.  That code (below) checks the state of other
relays and sets the two relays controlling the door to provide positive to the
proper side of the motor for a timed period. It also updates the database with a
timestamp of the action and the action.

Here is the Python code to open, close and stop the door. This code is run on the coop computer only.

Code to Open Door

#!/usr/bin/python

#
-*- coding: utf-8 -*-

from time import sleep

import pifacecommon.mcp23s17

import httplib2

h =  httplib2.Http()

mcp = pifacecommon.mcp23s17.MCP23S17()

opstr =  “”

clstr = “”

resp,
content  = h.request(
“http://192.168.0.159/wd-db.php? sqlcmd=UPDATE%20WD_Master%20SET%20Char_Value%20=%20’Do%20Open%20Door’,Last_Active%20=%20NOW()%20,LastCheck%20=%20NOW()%20WHERE%20Equipment=%20’Coop_RPI’%20and%20System%20%20=%20’Coop_Door'”,
“GET”)

try:

mcp.gpioa.value = mcp.gpioa.value
& 252

mcp.gpioa.value =
(mcp.gpioa.value | 2)

opstr = mcp.gpioa.value

sleep(25)

mcp.gpioa.value = mcp.gpioa.value
& 252

clstr = mcp.gpioa.value

finally:

print(“””<!DOCTYPE html PUBLIC ‘-//W3C//DTD XHTML 1.0 Transitional//EN’ ‘http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd‘>


<html xmlns=’http://www.w3.org/1999/xhtml’ >


<head>


<title>Door Opened</title>


</head>


<body style=’font-family:
Arial; font-size: xx-large; border-style: groove; width: 100%’
bgcolor=’Black’ text=’Yellow’>


<center>Door Opened<br />


“””

+
str(opstr)
+


+
str(clstr)
+
“””


</center>


<    /body>


</html>”””
)

Code to close the door:

#
-*- coding: utf-8 -*-

from
time
import
sleep

import
pifacecommon.mcp23s17

import
httplib2

mcp
= pifacecommon.mcp23s17.MCP23S17()

h
=
httplib2.Http()

opstr
=

clstr
=

try:

(resp, content) = \

h.request(“http://192.168.0.159/wd-db.php?sqlcmd=UPDATE%20WD_Master%20SET%20Char_Value%20=%20’Do%20Close%20Door’,Last_Inactive%20=%20NOW()%20,LastCheck%20=%20NOW()%20WHERE%                    20Equipment=%20’Coop_RPI’%20and%20System%20%20=%20’Coop_Door'”

)

finally:

try:

mcp.gpioa.value = mcp.gpioa.value
& 252

mcp.gpioa.value = mcp.gpioa.value
| 1

opstr = mcp.gpioa.value

sleep(15)

mcp.gpioa.value = mcp.gpioa.value
& 252

clstr = mcp.gpioa.value

finally:

print
(
“””<!DOCTYPE
html PUBLIC ‘-//W3C//DTD XHTML 1.0 Transitional//EN’
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd‘>


<html
xmlns=’http://www.w3.org/1999/xhtml’ >


<head>


<title>Closed
Door</title>


</head>


<body
style=’font-family: Arial; font-size: xx-large; border-style: groove;
width: 100%’ bgcolor=’Black’ text=’Yellow’>


<center>Closed
Door<br />


“””

\

+
str(opstr)
+


+
str(clstr)
\

+
“””)


</center>

Code to stop the door action:

import pifacecommon.mcp23s17

import httplib2

mcp = pifacecommon.mcp23s17.MCP23S17()

h = httplib2.Http()

try:

(resp, content) = h.request(“http://192.168.0.159/wd-db.php?sqlcmd=UPDATE%20WD_Master%20SET%20Char_Value%20=%20’Stopped%20Door’,LastCheck%20=%20NOW()%20WHERE%20Equipment=%20’Coop_RPI’%20and%20System%20%20=%20’Coop_Door'”,
“GET”)

finally:

try:

mcp.gpioa.value = mcp.gpioa.value & 252

finally:

print(“<!DOCTYPE
html PUBLIC ‘-//W3C//DTD XHTML 1.0 Transitional//EN’
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd’><html
xmlns=’http://www.w3.org/1999/xhtml’ ><head>
<title>Stopped Door</title></head><body
style=’font-family: Arial; font-size: xx-large; border-style: groove;
width: 100%’ bgcolor=’Black’ text=’Yellow’><center>Stopped
Door</center></body></html>”
)

 

 

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *