[Tutor] Python Arduino Web Page

Emile van Sebille emile at fenx.com
Thu Aug 15 19:52:48 CEST 2013


The value of myvar is not passed in your
print"""... +parseInt(myvar);..."""
which results in the string characters myvar being interpreted by 
parseInt and resulting in NaN

Try print"""... +parseInt(%s);...""" % myvar

this causes python to swap in the value of myvar which then will be 
parseable with parseInt.

HTH,

Emile



On 8/9/2013 1:33 AM, Engineering wrote:
> 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>
>
> <h1>Real 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 at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>




More information about the Tutor mailing list