[Tutor] Python Arduino Web Page
Dave Angel
davea at davea.name
Thu Aug 15 23:45:09 CEST 2013
Engineering wrote:
<snip>
> <o:idmap v:ext="edit" data="1" />
> </o:shapelayout></xml><![endif]--></head><body lang=EN-IN link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>I have written the following code in Python for my Arduino<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>#!c:\Python27\Python.exe<o:p></o:p></p><p class=MsoNormal>import cgi, cgitb;<o:p></o:p></p><p class=MsoNormal>import sys, serial<o:p></o:p></p><p class=MsoNormal>cgitb.enable()<o:p></o:p></p><p class=MsoNormal>ser = serial.Serial('COM27', 9600)<o:p></o:p></p><p class=MsoNormal>myvar = ser.readline()<o:p></o:p></p><p class=MsoNormal>print "Content-type:text/html\n\n"<o:p></o:p></p><p class=MsoNormal>print """<o:p></o:p></p><p class=MsoNormal><html><o:p></o:p></p><p class=MsoNormal><head><o:p></o:p></p><p class=MsoNormal><title><o:p></o:p></p><p class=MsoNormal>Real Time Temperature<o:p></o:p></p><p class=MsoNormal></title><o:p></o:p></p><p class=MsoNormal> <script type="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="mine">Temperature=%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
More information about the Tutor
mailing list