Re: Python and Cors

Donal McMullan <[email protected]> Sun, 27 Aug 2017 22:01:51 +0100
Newsgroups gmane.comp.python.twisted.web
Message-ID <CADf-aJFTt0mrFnBpecfqrO4iv_i0HGqKkzCXq261XUG2zLgdwQ@mail.gmail.com>
--===============3265218517916351513==
Content-Type: multipart/alternative; boundary="f403045c4268c46f390557c27cdc"

--f403045c4268c46f390557c27cdc
Content-Type: text/plain; charset="UTF-8"

No worries - glad I could help.

On 27 August 2017 at 21:11, Deve Krehbiel <[email protected]> wrote:

> WOW! That did it. I am amazed! Thank you so much! My next chore is to
> figure out how to make sliders for this so that I can move the servos in 1
> degree increments. On to that task! I am so appreciative! Thank you Donal!
>
> Deve
>
> On Sun, Aug 27, 2017 at 2:43 PM, Donal McMullan <[email protected]>
> wrote:
>
>> Ah sorry Deve -  I failed to paste the first like of the render_GET
>> method.
>>
>> # Import necessary files
>>
>> import serial
>>
>> from twisted.web.resource import Resource
>>
>> # Setup Arduino at correct speed
>>
>> try:
>>
>>     arduino = serial.Serial('/dev/ttyACM0', 9600)
>>
>> except:
>>
>>     arduino = serial.Serial('/dev/ttyACM1', 9600)
>>
>>
>>
>> class MoveServo(Resource):
>>
>>     isLeaf = True
>>
>>     permitted_origins = ('http://192.168.1.122:9000',)
>>
>>
>>
>>     def render_GET(self,request):
>>         origin = request.getHeader('Origin')
>>
>>         if origin in (self.permitted_origins):
>>
>>             request.setHeader('Access-Control-Allow-Origin', origin)
>>
>>         try:
>>
>>             # Send value over serial to the Arduino
>>
>>             arduino.write(request.args['value'][0])
>>
>>             return 'Success'
>>
>>         except:
>>
>>             return 'Failure'
>>
>>
>>
>> resource = MoveServo()
>>
>> On 27 August 2017 at 19:01, Deve Krehbiel <[email protected]> wrote:
>>
>>> This is what I get without your code:
>>> index1.html:1 XMLHttpRequest cannot load http://192.168.1.122:81/servos
>>> .rpy?value=70P. No 'Access-Control-Allow-Origin' header is present on
>>> the requested resource. Origin 'http://192.168.1.122:9000' is therefore
>>> not allowed access.
>>> jquery.min.js:4 XHR failed loading: GET "http://192.168.1.122:81/servo
>>> s.rpy?value=70P".
>>>
>>> This is what I get with it:
>>> jquery.min.js:4 GET http://192.168.1.122:81/servos.rpy?value=100P
>>> send @ jquery.min.js:4
>>> ajax @ jquery.min.js:4
>>> r.(anonymous function) @ jquery.min.js:4
>>> move @ index1.html:54
>>> onclick @ index1.html:17
>>> index1.html:1 XMLHttpRequest cannot load http://192.168.1.122:81/servos
>>> .rpy?value=100P. No 'Access-Control-Allow-Origin' header is present on
>>> the requested resource. Origin 'http://192.168.1.122:9000' is therefore
>>> not allowed access. *The response had HTTP status code 500.*
>>> jquery.min.js:4 XHR failed loading: GET "http://192.168.1.122:81/servo
>>> s.rpy?value=100P".
>>>
>>> I appreciate your efforts and if you have any other ideas... Thank You!
>>>
>>> Deve
>>>
>>> On Sun, Aug 27, 2017 at 12:48 PM, Deve Krehbiel <[email protected]>
>>> wrote:
>>>
>>>> Thank you for the response. In trying that code, it made it so the LAN
>>>> cannot move the buttons either. Here is the error list I got:
>>>>
>>>> *web.Server Traceback (most recent call last):*
>>>> exceptions.NameError: global name 'origin' is not defined
>>>> /usr/lib/python2.7/dist-packages/twisted/web/server.py:189 in process
>>>> 188                    self._encoder = encoder
>>>> 189            self.render(resrc)
>>>> 190        except:
>>>> /usr/lib/python2.7/dist-packages/twisted/web/server.py:238 in render
>>>> 237        try:
>>>> 238            body = resrc.render(self)
>>>> 239        except UnsupportedMethod as e:
>>>> /usr/lib/python2.7/dist-packages/twisted/web/resource.py:250 in render
>>>> 249            raise UnsupportedMethod(allowedMethods)
>>>> 250        return m(request)
>>>> 251
>>>> /usr/local/www/servos.rpy:15 in render_GET
>>>> 14    def render_GET(self,request):
>>>> 15        if origin in (self.permitted_origins):
>>>> 16            request.setHeader('Access-Control-Allow-Origin', origin)
>>>> exceptions.NameError: global name 'origin' is not defined
>>>>
>>>> Deve
>>>>
>>>> On Sun, Aug 27, 2017 at 12:03 PM, Donal McMullan <
>>>> [email protected]> wrote:
>>>>
>>>>> Perhaps you just need to set the 'Access-Control-Allow-Origin' header?
>>>>> Something like this might work:
>>>>>
>>>>>
>>>>> # Import necessary files
>>>>>
>>>>> import serial
>>>>>
>>>>> from twisted.web.resource import Resource
>>>>>
>>>>> # Setup Arduino at correct speed
>>>>>
>>>>> try:
>>>>>
>>>>>     arduino = serial.Serial('/dev/ttyACM0', 9600)
>>>>>
>>>>> except:
>>>>>
>>>>>     arduino = serial.Serial('/dev/ttyACM1', 9600)
>>>>>
>>>>>
>>>>>
>>>>> class MoveServo(Resource):
>>>>>
>>>>>     isLeaf = True
>>>>>
>>>>>     permitted_origins = ('http://192.168.1.122:9000',)
>>>>>
>>>>>
>>>>>
>>>>>     def render_GET(self,request):
>>>>>
>>>>>         if origin in (self.permitted_origins):
>>>>>
>>>>>             request.setHeader('Access-Control-Allow-Origin', origin)
>>>>>
>>>>>         try:
>>>>>
>>>>>             # Send value over serial to the Arduino
>>>>>
>>>>>             arduino.write(request.args['value'][0])
>>>>>
>>>>>             return 'Success'
>>>>>
>>>>>         except:
>>>>>
>>>>>             return 'Failure'
>>>>>
>>>>>
>>>>>
>>>>> resource = MoveServo()
>>>>>
>>>>> On 27 August 2017 at 17:10, Deve Krehbiel <[email protected]> wrote:
>>>>>
>>>>>> First post so forgive me if I am not explaining this right.
>>>>>>
>>>>>> I am trying to make a baby cam and then heavily document it for
>>>>>> everyone to have access to. I am using a Raspberry Pi with Rasbian. I am
>>>>>> using mjpg-streamer for the streaming with no problems.
>>>>>>
>>>>>> The problem is I am also using two servos for pan and tilt. To
>>>>>> accomplish this I am using an Arduino Uno. This is so I can add IR lighting
>>>>>> for night vision, etc later. I am not a programmer so this is getting
>>>>>> frustrating after a few weeks of failure.
>>>>>>
>>>>>> How is it failing you might ask..well, its working perfectly with
>>>>>> only ONE exception:
>>>>>> Every time I push the button for left/right/up/down I get this:
>>>>>>
>>>>>> XMLHttpRequest cannot load http://192.168.1.122:81/servos
>>>>>> .rpy?value=100P. No 'Access-Control-Allow-Origin' header is present
>>>>>> on the requested resource. Origin 'http://192.168.1.122:9000' is
>>>>>> therefore not allowed access.
>>>>>>
>>>>>> On the local area network, it still works, but taking it to the
>>>>>> internet it does not.
>>>>>>
>>>>>> Here are the two programs that make this happen. One is servos.rpy
>>>>>> and the other is the supporting HTML/Get script;
>>>>>> ****
>>>>>> servos.rpy
>>>>>> -----------------------------------
>>>>>> # Import necessary files
>>>>>> import serial
>>>>>> from twisted.web.resource import Resource
>>>>>> # Setup Arduino at correct speed
>>>>>> try:
>>>>>>         arduino = serial.Serial('/dev/ttyACM0', 9600)
>>>>>> except:
>>>>>>         arduino = serial.Serial('/dev/ttyACM1', 9600)
>>>>>>
>>>>>> class MoveServo(Resource):
>>>>>>         isLeaf = True
>>>>>>         def render_GET(self,request):
>>>>>>                 try:
>>>>>>                 # Send value over serial to the Arduino
>>>>>>                         arduino.write(request.args['value'][0])
>>>>>>                         return 'Success'
>>>>>>                 except:
>>>>>>                         return 'Failure'
>>>>>>
>>>>>> resource = MoveServo()
>>>>>> ***
>>>>>>
>>>>>> Now for the HTML/Get script:
>>>>>>
>>>>>> **
>>>>>> <!doctype html>
>>>>>> <html>
>>>>>> <head>
>>>>>> <title>Make Use Of DIY Security Camera</title>
>>>>>> <style type="text/css">
>>>>>> #container {
>>>>>> /* center the content */
>>>>>> margin: 0 auto;
>>>>>> text-align: center;
>>>>>> }
>>>>>> </style>
>>>>>> </head>
>>>>>> <body>
>>>>>> <div id="container">
>>>>>> <img src="/?action=stream" /><br>
>>>>>> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jque
>>>>>> ry.min.js"></script><br />
>>>>>> <button onclick="servos.move('P', 10)">Left</button>
>>>>>> <button onclick="servos.move('P', -10)">Right</button>
>>>>>> <button onclick="servos.move('T', -10)">Down</button>
>>>>>> <button onclick="servos.move('T', 10)">Up</button>
>>>>>> </div>
>>>>>> </body>
>>>>>> <script>
>>>>>> var servos;
>>>>>> $( document ).ready(function() {
>>>>>> servos = moveServos();
>>>>>> });
>>>>>> function moveServos() {
>>>>>> // Store some settings, adjust to suit
>>>>>> var panPos = 70,
>>>>>> tiltPos = 90,
>>>>>> tiltMax = 170,
>>>>>> tiltMin = 45,
>>>>>> panMax = 170,
>>>>>> panMin = 20;
>>>>>> return {
>>>>>> move:function(servo, adjustment) {
>>>>>> var value;
>>>>>> if(servo == 'P') {
>>>>>> if(!((panPos >= panMax && adjustment > 0) || (panPos <= panMin &&
>>>>>> adjustment < 0))) {
>>>>>> // Still within allowed range, "schedule" the movement
>>>>>> panPos += adjustment;
>>>>>> }
>>>>>> value = panPos + 'P';
>>>>>> }
>>>>>> else if(servo == 'T') {
>>>>>> if(!((tiltPos >= tiltMax && adjustment > 0) || (tiltPos <= tiltMin &&
>>>>>> adjustment < 0))) {
>>>>>> // Still within allowed range, "schedule" the movement
>>>>>> tiltPos += adjustment;
>>>>>> }
>>>>>> value = tiltPos + 'T';
>>>>>> }
>>>>>> // Use AJAX to actually move the servo
>>>>>> $.get('http://192.168.1.122:81/servos.rpy?value=' + value);
>>>>>> },
>>>>>> }
>>>>>> }
>>>>>> </script>
>>>>>> </html>
>>>>>>
>>>>>> *****
>>>>>> Twisted is started:  sudo twistd -n web -p 81 --path /usr/local/www/
>>>>>>
>>>>>> I would be forever grateful if someone could take a serious look at
>>>>>> this and tell me where I am going wrong. Once this is fixed, I can start
>>>>>> documenting the entire system for everyone. Thank you!
>>>>>>
>>>>>> Deve
>>>>>>
>>>>>> _______________________________________________
>>>>>> Twisted-web mailing list
>>>>>> [email protected]
>>>>>> https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
>>>>>>
>>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> Twisted-web mailing list
>>>>> [email protected]
>>>>> https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
>>>>>
>>>>>
>>>>
>>>
>>> _______________________________________________
>>> Twisted-web mailing list
>>> [email protected]
>>> https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
>>>
>>>
>>
>> _______________________________________________
>> Twisted-web mailing list
>> [email protected]
>> https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
>>
>>
>
> _______________________________________________
> Twisted-web mailing list
> [email protected]
> https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
>
>

--f403045c4268c46f390557c27cdc
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">No worries - glad I could help.</div><div class=3D"gmail_e=
xtra"><br><div class=3D"gmail_quote">On 27 August 2017 at 21:11, Deve Krehb=
iel <span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" target=3D"=
_blank">[email protected]</a>&gt;</span> wrote:<br><blockquote class=3D"g=
mail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-l=
eft:1ex"><div dir=3D"ltr">WOW! That did it. I am amazed! Thank you so much!=
 My next chore is to figure out how to make sliders for this so that I can =
move the servos in 1 degree increments. On to that task! I am so appreciati=
ve! Thank you Donal!</div><div class=3D"gmail_extra"><span class=3D"HOEnZb"=
><font color=3D"#888888"><br clear=3D"all"><div><div class=3D"m_66620470676=
86693635gmail_signature" data-smartmail=3D"gmail_signature"><div dir=3D"ltr=
"><div><div dir=3D"ltr"><div>Deve</div></div></div></div></div></div></font=
></span><div><div class=3D"h5">
<br><div class=3D"gmail_quote">On Sun, Aug 27, 2017 at 2:43 PM, Donal McMul=
lan <span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" targe=
t=3D"_blank">[email protected]</a>&gt;</span> wrote:<br><blockquote =
class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid=
;padding-left:1ex"><div dir=3D"ltr">Ah sorry Deve - =C2=A0I failed to paste=
 the first like of the render_GET method.<span><br><br><div># Import necess=
ary files =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2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A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0</div><div>=C2=A0 =C2=A0 isLeaf =3D True =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0=
</div><div>=C2=A0 =C2=A0 permitted_origins =3D (&#39;<a href=3D"http://192.=
168.1.122:9000" target=3D"_blank">http://192.168.1.122:9000</a>&#39;,) =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0=C2=A0</div><div>=C2=A0 =C2=A0 def render_GET(self,request): =C2=
=A0 =C2=A0 =C2=A0</div></span><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 origin =3D r=
equest.getHeader(&#39;Origin&#39;) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0</div><span><div>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 if origin in (self.permitted_origins): =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 request.s=
etHeader(&#39;Access-Cont<wbr>rol-Allow-Origin&#39;, origin) =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 try: =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 # Send va=
lue over serial to the Arduino =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0</div><div>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 arduino.write(request.args[&#39;va<w=
br>lue&#39;][0]) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0</div><div>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =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>resource =3D MoveServo()=C2=A0</di=
v></span></div><div class=3D"m_6662047067686693635HOEnZb"><div class=3D"m_6=
662047067686693635h5"><div class=3D"gmail_extra"><br><div class=3D"gmail_qu=
ote">On 27 August 2017 at 19:01, Deve Krehbiel <span dir=3D"ltr">&lt;<a hre=
f=3D"mailto:[email protected]" target=3D"_blank">[email protected]</a>&=
gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 =
0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>T=
his is what I get without your code:</div><div>index1.html:1 XMLHttpRequest=
 cannot load <a href=3D"http://192.168.1.122:81/servos.rpy?value=3D70P" tar=
get=3D"_blank">http://192.168.1.122:81/servos<wbr>.rpy?value=3D70P</a>. No =
&#39;Access-Control-Allow-Origin&#39; header is present on the requested re=
source. Origin &#39;<a href=3D"http://192.168.1.122:9000" target=3D"_blank"=
>http://192.168.1.122:9000</a>&#39; is therefore not allowed access.</div><=
div>jquery.min.js:4 XHR failed loading: GET &quot;<a href=3D"http://192.168=
.1.122:81/servos.rpy?value=3D70P" target=3D"_blank">http://192.168.1.122:81=
/servo<wbr>s.rpy?value=3D70P</a>&quot;.</div><div><br></div><div>This is wh=
at I get with it:</div><div><div>jquery.min.js:4 GET <a href=3D"http://192.=
168.1.122:81/servos.rpy?value=3D100P" target=3D"_blank">http://192.168.1.12=
2:81/servos<wbr>.rpy?value=3D100P</a>=C2=A0</div><div>send @ jquery.min.js:=
4</div><div>ajax @ jquery.min.js:4</div><div>r.(anonymous function) @ jquer=
y.min.js:4</div><div>move @ index1.html:54</div><div>onclick @ index1.html:=
17</div><div>index1.html:1 XMLHttpRequest cannot load <a href=3D"http://192=
.168.1.122:81/servos.rpy?value=3D100P" target=3D"_blank">http://192.168.1.1=
22:81/servos<wbr>.rpy?value=3D100P</a>. No &#39;Access-Control-Allow-Origin=
&#39; header is present on the requested resource. Origin &#39;<a href=3D"h=
ttp://192.168.1.122:9000" target=3D"_blank">http://192.168.1.122:9000</a>&#=
39; is therefore not allowed access. <b>The response had HTTP status code 5=
00.</b></div><div>jquery.min.js:4 XHR failed loading: GET &quot;<a href=3D"=
http://192.168.1.122:81/servos.rpy?value=3D100P" target=3D"_blank">http://1=
92.168.1.122:81/servo<wbr>s.rpy?value=3D100P</a>&quot;.</div></div><div><br=
></div><div>I appreciate your efforts and if you have any other ideas... Th=
ank You!</div></div><div class=3D"gmail_extra"><span class=3D"m_66620470676=
86693635m_-5483403120246404331HOEnZb"><font color=3D"#888888"><br clear=3D"=
all"><div><div class=3D"m_6662047067686693635m_-5483403120246404331m_811710=
1615705453869gmail_signature" data-smartmail=3D"gmail_signature"><div dir=
=3D"ltr"><div><div dir=3D"ltr"><div>Deve</div></div></div></div></div></div=
></font></span><div><div class=3D"m_6662047067686693635m_-54834031202464043=
31h5">
<br><div class=3D"gmail_quote">On Sun, Aug 27, 2017 at 12:48 PM, Deve Krehb=
iel <span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" target=3D"=
_blank">[email protected]</a>&gt;</span> wrote:<br><blockquote class=3D"g=
mail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-l=
eft:1ex"><div dir=3D"ltr">Thank you for the response. In trying that code, =
it made it so the LAN cannot move the buttons either. Here is the error lis=
t I got:<div><br></div><div><b style=3D"color:rgb(0,0,0);font-family:&quot;=
Times New Roman&quot;;font-size:medium">web.Server Traceback (most recent c=
all last):</b><span style=3D"color:rgb(0,0,0);font-family:&quot;Times New R=
oman&quot;;font-size:medium"></span><div style=3D"font-family:Verdana,Arial=
,helvetica,sans-serif;color:rgb(0,0,0);font-size:medium"><div class=3D"m_66=
62047067686693635m_-5483403120246404331m_8117101615705453869m_8371283913762=
161110error" style=3D"color:red;font-weight:bold">exceptions.NameError:=C2=
=A0global name &#39;origin&#39; is not defined</div><div class=3D"m_6662047=
067686693635m_-5483403120246404331m_8117101615705453869m_837128391376216111=
0gmail-stackTrace"><div class=3D"m_6662047067686693635m_-548340312024640433=
1m_8117101615705453869m_8371283913762161110gmail-frame" style=3D"padding:1e=
m;background-image:initial;background-position:initial;background-size:init=
ial;background-repeat:initial;background-origin:initial;background-clip:ini=
tial;border-bottom:thin dashed black;border-top:thin dashed black"><div cla=
ss=3D"m_6662047067686693635m_-5483403120246404331m_8117101615705453869m_837=
1283913762161110gmail-location">/usr/lib/python2.7/dist-packag<wbr>es/twist=
ed/web/server.py:189=C2=A0i<wbr>n=C2=A0<span class=3D"m_6662047067686693635=
m_-5483403120246404331m_8117101615705453869m_8371283913762161110gmail-funct=
ion" style=3D"font-weight:bold;font-family:&quot;Courier New&quot;,courier,=
monospace">process</span></div><div class=3D"m_6662047067686693635m_-548340=
3120246404331m_8117101615705453869m_8371283913762161110gmail-snippet" style=
=3D"margin-bottom:0.5em;margin-left:1em;background:rgb(255,255,221)"><div c=
lass=3D"m_6662047067686693635m_-5483403120246404331m_8117101615705453869m_8=
371283913762161110gmail-snippetLine"><span class=3D"m_6662047067686693635m_=
-5483403120246404331m_8117101615705453869m_8371283913762161110gmail-lineno"=
>188</span>=C2=A0<code class=3D"m_6662047067686693635m_-5483403120246404331=
m_8117101615705453869m_8371283913762161110gmail-code">=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._encoder =3D encoder</=
code></div><div class=3D"m_6662047067686693635m_-5483403120246404331m_81171=
01615705453869m_8371283913762161110gmail-snippetHighlightLine" style=3D"col=
or:red"><span class=3D"m_6662047067686693635m_-5483403120246404331m_8117101=
615705453869m_8371283913762161110gmail-lineno">189</span>=C2=A0<code class=
=3D"m_6662047067686693635m_-5483403120246404331m_8117101615705453869m_83712=
83913762161110gmail-code">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.ren=
der(resrc)</code></div><div class=3D"m_6662047067686693635m_-54834031202464=
04331m_8117101615705453869m_8371283913762161110gmail-snippetLine"><span cla=
ss=3D"m_6662047067686693635m_-5483403120246404331m_8117101615705453869m_837=
1283913762161110gmail-lineno">190</span>=C2=A0<code class=3D"m_666204706768=
6693635m_-5483403120246404331m_8117101615705453869m_8371283913762161110gmai=
l-code">=C2=A0 =C2=A0 =C2=A0 =C2=A0except:</code></div></div></div><div cla=
ss=3D"m_6662047067686693635m_-5483403120246404331m_8117101615705453869m_837=
1283913762161110gmail-frame" style=3D"padding:1em;background-image:initial;=
background-position:initial;background-size:initial;background-repeat:initi=
al;background-origin:initial;background-clip:initial;border-bottom:thin das=
hed black"><div class=3D"m_6662047067686693635m_-5483403120246404331m_81171=
01615705453869m_8371283913762161110gmail-location">/usr/lib/python2.7/dist-=
packag<wbr>es/twisted/web/server.py:238=C2=A0i<wbr>n=C2=A0<span class=3D"m_=
6662047067686693635m_-5483403120246404331m_8117101615705453869m_83712839137=
62161110gmail-function" style=3D"font-weight:bold;font-family:&quot;Courier=
 New&quot;,courier,monospace">render</span></div><div class=3D"m_6662047067=
686693635m_-5483403120246404331m_8117101615705453869m_8371283913762161110gm=
ail-snippet" style=3D"margin-bottom:0.5em;margin-left:1em;background:rgb(25=
5,255,221)"><div class=3D"m_6662047067686693635m_-5483403120246404331m_8117=
101615705453869m_8371283913762161110gmail-snippetLine"><span class=3D"m_666=
2047067686693635m_-5483403120246404331m_8117101615705453869m_83712839137621=
61110gmail-lineno">237</span>=C2=A0<code class=3D"m_6662047067686693635m_-5=
483403120246404331m_8117101615705453869m_8371283913762161110gmail-code">=C2=
=A0 =C2=A0 =C2=A0 =C2=A0try:</code></div><div class=3D"m_666204706768669363=
5m_-5483403120246404331m_8117101615705453869m_8371283913762161110gmail-snip=
petHighlightLine" style=3D"color:red"><span class=3D"m_6662047067686693635m=
_-5483403120246404331m_8117101615705453869m_8371283913762161110gmail-lineno=
">238</span>=C2=A0<code class=3D"m_6662047067686693635m_-548340312024640433=
1m_8117101615705453869m_8371283913762161110gmail-code">=C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0body =3D resrc.render(self)</code></div><div class=3D"=
m_6662047067686693635m_-5483403120246404331m_8117101615705453869m_837128391=
3762161110gmail-snippetLine"><span class=3D"m_6662047067686693635m_-5483403=
120246404331m_8117101615705453869m_8371283913762161110gmail-lineno">239</sp=
an>=C2=A0<code class=3D"m_6662047067686693635m_-5483403120246404331m_811710=
1615705453869m_8371283913762161110gmail-code">=C2=A0 =C2=A0 =C2=A0 =C2=A0ex=
cept UnsupportedMethod as e:</code></div></div></div><div class=3D"m_666204=
7067686693635m_-5483403120246404331m_8117101615705453869m_83712839137621611=
10gmail-frame" style=3D"padding:1em;background-image:initial;background-pos=
ition:initial;background-size:initial;background-repeat:initial;background-=
origin:initial;background-clip:initial;border-bottom:thin dashed black"><di=
v class=3D"m_6662047067686693635m_-5483403120246404331m_8117101615705453869=
m_8371283913762161110gmail-location">/usr/lib/python2.7/dist-packag<wbr>es/=
twisted/web/resource.py:250<wbr>=C2=A0in=C2=A0<span class=3D"m_666204706768=
6693635m_-5483403120246404331m_8117101615705453869m_8371283913762161110gmai=
l-function" style=3D"font-weight:bold;font-family:&quot;Courier New&quot;,c=
ourier,monospace">render</span></div><div class=3D"m_6662047067686693635m_-=
5483403120246404331m_8117101615705453869m_8371283913762161110gmail-snippet"=
 style=3D"margin-bottom:0.5em;margin-left:1em;background:rgb(255,255,221)">=
<div class=3D"m_6662047067686693635m_-5483403120246404331m_8117101615705453=
869m_8371283913762161110gmail-snippetLine"><span class=3D"m_666204706768669=
3635m_-5483403120246404331m_8117101615705453869m_8371283913762161110gmail-l=
ineno">249</span>=C2=A0<code class=3D"m_6662047067686693635m_-5483403120246=
404331m_8117101615705453869m_8371283913762161110gmail-code">=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0raise UnsupportedMethod(allowedMetho<wbr>ds)</co=
de></div><div class=3D"m_6662047067686693635m_-5483403120246404331m_8117101=
615705453869m_8371283913762161110gmail-snippetHighlightLine" style=3D"color=
:red"><span class=3D"m_6662047067686693635m_-5483403120246404331m_811710161=
5705453869m_8371283913762161110gmail-lineno">250</span>=C2=A0<code class=3D=
"m_6662047067686693635m_-5483403120246404331m_8117101615705453869m_83712839=
13762161110gmail-code">=C2=A0 =C2=A0 =C2=A0 =C2=A0return m(request)</code><=
/div><div class=3D"m_6662047067686693635m_-5483403120246404331m_81171016157=
05453869m_8371283913762161110gmail-snippetLine"><span class=3D"m_6662047067=
686693635m_-5483403120246404331m_8117101615705453869m_8371283913762161110gm=
ail-lineno">251</span><code class=3D"m_6662047067686693635m_-54834031202464=
04331m_8117101615705453869m_8371283913762161110gmail-code"></code></div></d=
iv></div><div class=3D"m_6662047067686693635m_-5483403120246404331m_8117101=
615705453869m_8371283913762161110gmail-frame" style=3D"padding:1em;backgrou=
nd-image:initial;background-position:initial;background-size:initial;backgr=
ound-repeat:initial;background-origin:initial;background-clip:initial;borde=
r-bottom:thin dashed black"><div class=3D"m_6662047067686693635m_-548340312=
0246404331m_8117101615705453869m_8371283913762161110gmail-location">/usr/lo=
cal/www/servos.rpy:15=C2=A0i<wbr>n=C2=A0<span class=3D"m_666204706768669363=
5m_-5483403120246404331m_8117101615705453869m_8371283913762161110gmail-func=
tion" style=3D"font-weight:bold;font-family:&quot;Courier New&quot;,courier=
,monospace">render_GET</span></div><div class=3D"m_6662047067686693635m_-54=
83403120246404331m_8117101615705453869m_8371283913762161110gmail-snippet" s=
tyle=3D"margin-bottom:0.5em;margin-left:1em;background:rgb(255,255,221)"><d=
iv class=3D"m_6662047067686693635m_-5483403120246404331m_811710161570545386=
9m_8371283913762161110gmail-snippetLine"><span class=3D"m_66620470676866936=
35m_-5483403120246404331m_8117101615705453869m_8371283913762161110gmail-lin=
eno">14</span>=C2=A0<code class=3D"m_6662047067686693635m_-5483403120246404=
331m_8117101615705453869m_8371283913762161110gmail-code">=C2=A0 =C2=A0def r=
ender_GET(self,request):</code></div><div class=3D"m_6662047067686693635m_-=
5483403120246404331m_8117101615705453869m_8371283913762161110gmail-snippetH=
ighlightLine" style=3D"color:red"><span class=3D"m_6662047067686693635m_-54=
83403120246404331m_8117101615705453869m_8371283913762161110gmail-lineno">15=
</span>=C2=A0<code class=3D"m_6662047067686693635m_-5483403120246404331m_81=
17101615705453869m_8371283913762161110gmail-code">=C2=A0 =C2=A0 =C2=A0 =C2=
=A0if origin in (self.permitted_origins):</code></div><div class=3D"m_66620=
47067686693635m_-5483403120246404331m_8117101615705453869m_8371283913762161=
110gmail-snippetLine"><span class=3D"m_6662047067686693635m_-54834031202464=
04331m_8117101615705453869m_8371283913762161110gmail-lineno">16</span>=C2=
=A0<code class=3D"m_6662047067686693635m_-5483403120246404331m_811710161570=
5453869m_8371283913762161110gmail-code">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0request.setHeader(&#39;Access-Con<wbr>trol-Allow-Origin&#39;, origin)=
</code></div></div></div></div><div class=3D"m_6662047067686693635m_-548340=
3120246404331m_8117101615705453869m_8371283913762161110error" style=3D"colo=
r:red;font-weight:bold">exceptions.NameError:=C2=A0global name &#39;origin&=
#39; is not defined</div></div></div></div><div class=3D"gmail_extra"><span=
 class=3D"m_6662047067686693635m_-5483403120246404331m_8117101615705453869H=
OEnZb"><font color=3D"#888888"><br clear=3D"all"><div><div class=3D"m_66620=
47067686693635m_-5483403120246404331m_8117101615705453869m_8371283913762161=
110gmail_signature" data-smartmail=3D"gmail_signature"><div dir=3D"ltr"><di=
v><div dir=3D"ltr"><div>Deve</div></div></div></div></div></div></font></sp=
an><div><div class=3D"m_6662047067686693635m_-5483403120246404331m_81171016=
15705453869h5">
<br><div class=3D"gmail_quote">On Sun, Aug 27, 2017 at 12:03 PM, Donal McMu=
llan <span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" targ=
et=3D"_blank">[email protected]</a>&gt;</span> wrote:<br><blockquote=
 class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc soli=
d;padding-left:1ex"><div dir=3D"ltr"><div>Perhaps you just need to set the =
&#39;Access-Control-Allow-Origin&#39; header? Something like this might wor=
k:</div><span><div><br></div><div><br></div><div># Import necessary files =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0</div><div>import serial =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0=C2=A0</div><div>from twisted.web.resource import Resource =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0</div><div># Setu=
p Arduino at correct speed =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0</div><div>try: =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C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0</div><div>class MoveServo(Resource): =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0</div><div>=C2=A0 =C2=A0 isLeaf =3D True =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0</div></sp=
an><div>=C2=A0 =C2=A0 permitted_origins =3D (&#39;<a href=3D"http://192.168=
.1.122:9000" target=3D"_blank">http://192.168.1.122:9000</a>&#39;,) =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0=C2=A0</div><div>=C2=A0 =C2=A0 def render_GET(self,request): =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0=C2=A0</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 if origin in (self.permi=
tted_origins): =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0</div><div>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 request.setHeader(&#39;Access-Cont<w=
br>rol-Allow-Origin&#39;, origin) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
</div><span><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 try: =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0</div><di=
v>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 # Send value over serial to the=
 Arduino =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 arduino.write(request.args[&#39;va<wbr>lue&#39;][0]) =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0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
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0</div><div>resource =3D MoveServo()=C2=A0</div></span></div><div clas=
s=3D"gmail_extra"><br><div class=3D"gmail_quote"><div><div class=3D"m_66620=
47067686693635m_-5483403120246404331m_8117101615705453869m_8371283913762161=
110h5">On 27 August 2017 at 17:10, Deve Krehbiel <span dir=3D"ltr">&lt;<a h=
ref=3D"mailto:[email protected]" target=3D"_blank">[email protected]</a=
>&gt;</span> wrote:<br></div></div><blockquote class=3D"gmail_quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><di=
v class=3D"m_6662047067686693635m_-5483403120246404331m_8117101615705453869=
m_8371283913762161110h5"><div dir=3D"ltr">First post so forgive me if I am =
not explaining this right.=C2=A0<div><br></div><div>I am trying to make a b=
aby cam and then heavily document it for everyone to have access to. I am u=
sing a Raspberry Pi with Rasbian. I am using mjpg-streamer for the streamin=
g with no problems.=C2=A0</div><div><br></div><div>The problem is I am also=
 using two servos for pan and tilt. To accomplish this I am using an Arduin=
o Uno. This is so I can add IR lighting for night vision, etc later. I am n=
ot a programmer so this is getting frustrating after a few weeks of failure=
.</div><div><br></div><div>How is it failing you might ask..well, its worki=
ng perfectly with only ONE exception:</div><div>Every time I push the butto=
n for left/right/up/down I get this:</div><div><br></div><div>XMLHttpReques=
t cannot load <a href=3D"http://192.168.1.122:81/servos.rpy?value=3D100P" t=
arget=3D"_blank">http://192.168.1.122:81/servos<wbr>.rpy?value=3D100P</a>. =
No &#39;Access-Control-Allow-Origin&#39; header is present on the requested=
 resource. Origin &#39;<a href=3D"http://192.168.1.122:9000" target=3D"_bla=
nk">http://192.168.1.122:9000</a>&#39; is therefore not allowed access.</di=
v><div><br></div><div>On the local area network, it still works, but taking=
 it to the internet it does not.</div><div><br></div><div>Here are the two =
programs that make this happen. One is servos.rpy and the other is the supp=
orting HTML/Get script;</div><div>****</div><div>servos.rpy</div><div>-----=
-------------------------<wbr>-----</div><div><div># Import necessary files=
</div><div>import serial</div><div>from twisted.web.resource import Resourc=
e</div><div># Setup Arduino at correct speed</div><div>try:</div><div>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 arduino =3D serial.Serial(&#39;/dev/ttyACM0&#39;, =
9600)</div><div>except:</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 arduino =3D s=
erial.Serial(&#39;/dev/ttyACM1&#39;, 9600)</div><div><br></div><div>class M=
oveServo(Resource):</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 isLeaf =3D True</=
div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 def render_GET(self,request):</div><di=
v>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 try:</div><div>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <span style=3D"whit=
e-space:pre-wrap">		</span># Send value over serial to the Arduino</div><di=
v>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 arduino.write(request.args[&#39;va<wbr>lue&#39;][0])</div><div>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 return &#39;Success&#39;</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 except:</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return &#39;Failure=
&#39;</div><div><br></div><div>resource =3D MoveServo()</div></div><div>***=
</div><div><br></div><div>Now for the HTML/Get script:</div><div><br></div>=
<div>**</div><div><div>&lt;!doctype html&gt;</div><div>&lt;html&gt;</div><d=
iv><span style=3D"white-space:pre-wrap">	</span>&lt;head&gt;</div><div><spa=
n style=3D"white-space:pre-wrap">		</span>&lt;title&gt;Make Use Of DIY Secu=
rity Camera&lt;/title&gt;</div><div><span style=3D"white-space:pre-wrap">		=
</span>&lt;style type=3D&quot;text/css&quot;&gt;</div><div><span style=3D"w=
hite-space:pre-wrap">			</span>#container {</div><div><span style=3D"white-=
space:pre-wrap">				</span>/* center the content */</div><div><span style=
=3D"white-space:pre-wrap">				</span>margin: 0 auto;<span style=3D"white-sp=
ace:pre-wrap">	</span></div><div><span style=3D"white-space:pre-wrap">				<=
/span>text-align: center;</div><div><span style=3D"white-space:pre-wrap">		=
	</span>}</div><div><span style=3D"white-space:pre-wrap">		</span>&lt;/styl=
e&gt;</div><div><span style=3D"white-space:pre-wrap">	</span>&lt;/head&gt;<=
/div><div><span style=3D"white-space:pre-wrap">	</span>&lt;body&gt;</div><d=
iv><span style=3D"white-space:pre-wrap">		</span>&lt;div id=3D&quot;contain=
er&quot;&gt;</div><div><span style=3D"white-space:pre-wrap">			</span>&lt;i=
mg src=3D&quot;/?action=3Dstream&quot; /&gt;&lt;br&gt;</div><div><span styl=
e=3D"white-space:pre-wrap">			</span>&lt;script src=3D&quot;<a href=3D"http=
s://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js" target=3D"_bl=
ank">https://ajax.googleapis.c<wbr>om/ajax/libs/jquery/3.1.0/jque<wbr>ry.mi=
n.js</a>&quot;&gt;&lt;/script&gt;&lt;br /&gt;</div><div><span style=3D"whit=
e-space:pre-wrap">			</span>&lt;button onclick=3D&quot;servos.move(&#39;P&#=
39;, 10)&quot;&gt;Left&lt;/button&gt;</div><div><span style=3D"white-space:=
pre-wrap">			</span>&lt;button onclick=3D&quot;servos.move(&#39;P&#39;, -10=
)&quot;&gt;Right&lt;/button&gt;</div><div><span style=3D"white-space:pre-wr=
ap">			</span>&lt;button onclick=3D&quot;servos.move(&#39;T&#39;, -10)&quot=
;&gt;Down&lt;/button&gt;</div><div><span style=3D"white-space:pre-wrap">			=
</span>&lt;button onclick=3D&quot;servos.move(&#39;T&#39;, 10)&quot;&gt;Up&=
lt;/button&gt;</div><div><span style=3D"white-space:pre-wrap">		</span>&lt;=
/div&gt;</div><div><span style=3D"white-space:pre-wrap">	</span>&lt;/body&g=
t;</div><div><span style=3D"white-space:pre-wrap">	</span>&lt;script&gt;</d=
iv><div><span style=3D"white-space:pre-wrap">		</span>var servos;</div><div=
><span style=3D"white-space:pre-wrap">		</span>$( document ).ready(function=
() {</div><div><span style=3D"white-space:pre-wrap">			</span>servos =3D mo=
veServos();</div><div><span style=3D"white-space:pre-wrap">		</span>});</di=
v><div><span style=3D"white-space:pre-wrap">		</span>function moveServos() =
{</div><div><span style=3D"white-space:pre-wrap">			</span>// Store some se=
ttings, adjust to suit</div><div><span style=3D"white-space:pre-wrap">			</=
span>var panPos =3D 70,=C2=A0</div><div><span style=3D"white-space:pre-wrap=
">				</span>tiltPos =3D 90,=C2=A0</div><div><span style=3D"white-space:pre=
-wrap">				</span>tiltMax =3D 170,=C2=A0</div><div><span style=3D"white-spa=
ce:pre-wrap">				</span>tiltMin =3D 45,=C2=A0</div><div><span style=3D"whit=
e-space:pre-wrap">				</span>panMax =3D 170,=C2=A0</div><div><span style=3D=
"white-space:pre-wrap">				</span>panMin =3D 20;</div><div><span style=3D"w=
hite-space:pre-wrap">			</span>return {</div><div><span style=3D"white-spac=
e:pre-wrap">				</span>move:function(servo, adjustment) {</div><div><span s=
tyle=3D"white-space:pre-wrap">					</span>var value;</div><div><span style=
=3D"white-space:pre-wrap">					</span>if(servo =3D=3D &#39;P&#39;) {</div><=
div><span style=3D"white-space:pre-wrap">						</span>if(!((panPos &gt;=3D =
panMax &amp;&amp; adjustment &gt; 0) || (panPos &lt;=3D panMin &amp;&amp; a=
djustment &lt; 0))) {</div><div><span style=3D"white-space:pre-wrap">						=
	</span>// Still within allowed range, &quot;schedule&quot; the movement</d=
iv><div><span style=3D"white-space:pre-wrap">							</span>panPos +=3D adju=
stment;</div><div><span style=3D"white-space:pre-wrap">						</span>}</div>=
<div><span style=3D"white-space:pre-wrap">						</span>value =3D panPos + &=
#39;P&#39;;</div><div><span style=3D"white-space:pre-wrap">					</span>}</d=
iv><div><span style=3D"white-space:pre-wrap">					</span>else if(servo =3D=
=3D &#39;T&#39;) {</div><div><span style=3D"white-space:pre-wrap">						</s=
pan>if(!((tiltPos &gt;=3D tiltMax &amp;&amp; adjustment &gt; 0) || (tiltPos=
 &lt;=3D tiltMin &amp;&amp; adjustment &lt; 0))) {</div><div><span style=3D=
"white-space:pre-wrap">							</span>// Still within allowed range, &quot;s=
chedule&quot; the movement</div><div><span style=3D"white-space:pre-wrap">	=
						</span>tiltPos +=3D adjustment;</div><div><span style=3D"white-space:=
pre-wrap">						</span>}</div><div><span style=3D"white-space:pre-wrap">			=
			</span>value =3D tiltPos + &#39;T&#39;;</div><div><span style=3D"white-s=
pace:pre-wrap">					</span>}</div><div><span style=3D"white-space:pre-wrap"=
>					</span>// Use AJAX to actually move the servo</div><div><span style=
=3D"white-space:pre-wrap">					</span>$.get(&#39;<a href=3D"http://192.168.=
1.122:81/servos.rpy?value=3D" target=3D"_blank">http://192.168.1.122:81<wbr=
>/servos.rpy?value=3D</a>&#39; + value);</div><div><span style=3D"white-spa=
ce:pre-wrap">				</span>},</div><div><span style=3D"white-space:pre-wrap">	=
		</span>}</div><div><span style=3D"white-space:pre-wrap">		</span>}</div><=
div><span style=3D"white-space:pre-wrap">	</span>&lt;/script&gt;</div><div>=
&lt;/html&gt;</div></div><div><br></div><div>*****</div><div>Twisted is sta=
rted: =C2=A0sudo twistd -n web -p 81 --path /usr/local/www/</div><div><br><=
/div><div>I would be forever grateful if someone could take a serious look =
at this and tell me where I am going wrong. Once this is fixed, I can start=
 documenting the entire system for everyone. Thank you!</div><span class=3D=
"m_6662047067686693635m_-5483403120246404331m_8117101615705453869m_83712839=
13762161110m_-4865426837896638325HOEnZb"><font color=3D"#888888"><div><br c=
lear=3D"all"><div><div class=3D"m_6662047067686693635m_-5483403120246404331=
m_8117101615705453869m_8371283913762161110m_-4865426837896638325m_-24873974=
93353888386gmail_signature"><div dir=3D"ltr"><div><div dir=3D"ltr"><div>Dev=
e</div></div></div></div></div></div>
</div></font></span></div>
<br></div></div>______________________________<wbr>_________________<br>
Twisted-web mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">Twisted-=
[email protected]</a><br>
<a href=3D"https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web" =
rel=3D"noreferrer" target=3D"_blank">https://twistedmatrix.com/cgi-<wbr>bin=
/mailman/listinfo/twisted-w<wbr>eb</a><br>
<br></blockquote></div><br></div>
<br>______________________________<wbr>_________________<br>
Twisted-web mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">Twisted-=
[email protected]</a><br>
<a href=3D"https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web" =
rel=3D"noreferrer" target=3D"_blank">https://twistedmatrix.com/cgi-<wbr>bin=
/mailman/listinfo/twisted-w<wbr>eb</a><br>
<br></blockquote></div><br></div></div></div>
</blockquote></div><br></div></div></div>
<br>______________________________<wbr>_________________<br>
Twisted-web mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">Twisted-=
[email protected]</a><br>
<a href=3D"https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web" =
rel=3D"noreferrer" target=3D"_blank">https://twistedmatrix.com/cgi-<wbr>bin=
/mailman/listinfo/twisted-w<wbr>eb</a><br>
<br></blockquote></div><br></div>
</div></div><br>______________________________<wbr>_________________<br>
Twisted-web mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">Twisted-=
[email protected]</a><br>
<a href=3D"https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web" =
rel=3D"noreferrer" target=3D"_blank">https://twistedmatrix.com/cgi-<wbr>bin=
/mailman/listinfo/twisted-w<wbr>eb</a><br>
<br></blockquote></div><br></div></div></div>
<br>______________________________<wbr>_________________<br>
Twisted-web mailing list<br>
<a href=3D"mailto:[email protected]">Twisted-web@twistedmatrix.=
com</a><br>
<a href=3D"https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web" =
rel=3D"noreferrer" target=3D"_blank">https://twistedmatrix.com/cgi-<wbr>bin=
/mailman/listinfo/twisted-<wbr>web</a><br>
<br></blockquote></div><br></div>

--f403045c4268c46f390557c27cdc--

--===============3265218517916351513==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline

X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KVHdpc3RlZC13
ZWIgbWFpbGluZyBsaXN0ClR3aXN0ZWQtd2ViQHR3aXN0ZWRtYXRyaXguY29tCmh0dHBzOi8vdHdp
c3RlZG1hdHJpeC5jb20vY2dpLWJpbi9tYWlsbWFuL2xpc3RpbmZvL3R3aXN0ZWQtd2ViCg==

--===============3265218517916351513==--