Re: [Tutor] Python Arduino Web Page

2013-08-15 Thread Dave Angel
Engineering wrote:

   snip

 o:idmap v:ext=edit data=1 /
 /o:shapelayout/xml![endif]--/headbody lang=EN-IN link=blue 
 vlink=purplediv class=WordSection1p class=MsoNormalI have written the 
 following code in Python for my Arduinoo:p/o:p/pp 
 class=MsoNormalo:pnbsp;/o:p/pp 
 class=MsoNormal#!c:\Python27\Python.exeo:p/o:p/pp 
 class=MsoNormalimport cgi, cgitb;o:p/o:p/pp class=MsoNormalimport 
 sys, serialo:p/o:p/pp class=MsoNormalcgitb.enable()o:p/o:p/pp 
 class=MsoNormalser = serial.Serial('COM27', 9600)o:p/o:p/pp 
 class=MsoNormalmyvar = ser.readline()o:p/o:p/pp class=MsoNormalprint 
 quot;Content-type:text/html\n\nquot;o:p/o:p/pp class=MsoNormalprint 
 quot;quot;quot;o:p/o:p/pp 
 class=MsoNormallt;htmlgt;o:p/o:p/pp 
 class=MsoNormallt;headgt;o:p/o:p/pp 
 class=MsoNormallt;titlegt;o:p/o:p/pp class=MsoNormalReal Time 
 Temperatureo:p/o:p/pp class=MsoNormallt;/titlegt;o:p/o:p/pp 
 class=MsoNormalnbsp; lt;script type=quot
 ;text/j

It's pretty hard to interpret that html message.  Please post using text
messages, as it's both more compact and less likely to be misinterpreted
by  the (text) mailing list mechanisms.

You fetch a value from the serial port in Python called myvar.  However,
 the javascript code cannot see that value unless you stuff it into the
generated script.  The easiest place to stuff it would be on the line:

div id=mine/div

by doing something like

div id=mineTemperature=%d/div

and at the end of the code, changing the final triple quote to:

 % myvar

That way the generated html has the string already substituted.

If this is just a (somewhat) simplified version of something that
*needs* javascript, then consider stuffing an assignment statement in
the startinterval() function. However, I can't see as you actually
pass it to startTime() anyway, so the javascript ought to be blowing up
with a missing argument.

Clearly I don't know enough javascript to get out of the mud, so if your
real code is more complex, somebody else will have to help you figure
where to change it.

As for seeing the javascript code separately, one approach is to use
your browser to view the source html.  Another is to use wget to just
fetch the page.

-- 
DaveA


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Arduino

2013-08-12 Thread Engineering
Dear All

 

I have designed a small program to control an arduino through python socket
server. The front end is the Javaquery. My HTML code is given below

 

$(function() {

$( #slider ).slider({

  min: 0,

  max: 180,

  step: 10,

  slide: function( event, ui ) {

$( #amount ).val( $ + ui.value );

  }

});

$( #amount ).val( $ + $( #slider ).slider( value ) );

  });

 

My python websocket code is given below

from twisted.internet import reactor

print Using Twisted reactor, reactor.__class__

print

 

from twisted.python import usage, log

from twisted.protocols.basic import LineReceiver

from twisted.internet.serialport import SerialPort

from twisted.web.server import Site

from twisted.web.static import File

 

from autobahn.websocket import listenWS

from autobahn.wamp import WampServerFactory, WampServerProtocol, exportRpc

 

 

class Serial2WsOptions(usage.Options):

   optParameters = [

  ['baudrate', 'b', 9600, 'Serial baudrate'],

  ['port', 'p', 26, 'Serial port to use'],

  ['webport', 'w', 8080, 'Web port to use for embedded Web server'],

  ['wsurl', 's', ws://localhost:9000, 'WebSocket port to use for
embedded WebSocket server']

   ]

 

Can you please help me with the python code . I want the server to write
string which will be sent to the arduino digital pin to control the servo. 

The arduino can have the following in its code

 

if(!Serial.available())

  {

// convert String to int. 

int recievedVal = stringToInt();



//analogWrite(servoPin,recievedVal);

recievedVal = map(recievedVal,0,179,0,179);

webcam.write(recievedVal);

delay(15);

pwmComplete = false;

  }

 

Python side coding help is required

 

CLEANTECH SOLUTION

www.cleantechsolution.in

 

SAVE PAPER , SAVE EARTH

 

 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Arduino Web Page

2013-08-11 Thread Engineering
I have written the following code in Python for my Arduino

 

#!c:\Python27\Python.exe

import cgi, cgitb;

import sys, serial

cgitb.enable()

ser = serial.Serial('COM27', 9600)

myvar = ser.readline()

print Content-type:text/html\n\n

print 

html

head

title

Real Time Temperature

/title

  script type=text/javascript

window.onload = startInterval;

function startInterval()

{

setInterval(startTime();,1000);

}

 

function startTime(myvar)

{

document.getElementById('mine').innerHTML =Temperature
+parseInt(myvar);

 

}

  /script

/head

body

h1Real Time Temperature:/h1

div id=mine/div

/body/html



I have Apache Web Server 

But on running this  my localhost , I am getting the following output
TemperatureNaN . Why is NaN being showed. Why cant I get the number as
read by se.readline()?

Is there a way to separate the Python code and the Javascript on different
files. If so can you please give a example.?

I am not really interested to do with bottle or other web framework as I
will be controlling my arduino with python from the web and also do video
image processing with openCV. Open CV have a support for Python and not for
Javascript.

 

Thanks

Subhendu Sinha Chaudhuri

 

CLEANTECH SOLUTION

www.cleantechsolution.in

 

SAVE PAPER , SAVE EARTH

 

 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor