[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 """







Real Time Temperature



  

window.onload = startInterval;

function startInterval()

{

setInterval("startTime();",1000);

}

 

function startTime(myvar)

{

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

 

}

  





Real Time Temperature:





"""

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


[Tutor] Python and Web

2013-08-11 Thread Engineering
Dear All

 

After a lot of struggling for weeks , I can read the serial port readings in
my web page. Below is the code

 

#!c:\Python27\Python.exe

import cgi, cgitb;

import sys, serial ,time

cgitb.enable()

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

numOfLines = 0

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

print """







Real Time Temperature



Real Time Temperature:

"""

while True:

response = ser.readline()

print """



var int=self.setInterval(function(){refer()},1000);

function refer()

{

document.getElementById('mine').innerHTML ="""+response+""";

}











"""

 

ser.close()

sys.exit(0)

 

BUT is this good programming ? I personally do not feel so. 

SECONDLY , during the whole execution process , the cursor is showing busy
and I am prevented to click anything else. Why is this so? How to avoid it.


 

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

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] . http.server -- stuck at binding [windows8]

2013-08-19 Thread Engineering
Since you are behind a router , ipconfig will only show the address of your
machine which has been given by the router. Ipconfig cannot see beyond the
router. 

If you work within your own LAN , the IP address of your machine is
sufficient for the socket. 

If you want to access from outside , there should be port forwarding enabled
on your router.

 

One of my personal interest . I have done an HTTP server on Python using
twisted and autobahn to control my arduino micro controller. But , I want to
stream media using it for my OpenCV to access it. 

 

How are you streaming  videos?

 

 

 

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