2013-05-22 6 views
0

나는 USB를 통해 내 노트북에 연결된 우두노 우노 있어요. Windows 7에서 WAMP 웹 서버를 실행하고 있습니다. 파이썬 2.7 및 py 직렬이 설치되어 있습니다. 버튼을 클릭하면 led1.py (python 스크립트)가 호출되는 HTML을 작성했습니다. 파이썬 스크립트는 arduino와 통신하여 LED를 켠 다음 사용자가 Led를 퍼팅하기 위해 다른 버튼을 누를 것입니다. 파이썬 스크립트를 호출하는 누르면 버튼은 LED가지고 있지만, 다음 HTML 페이지 오류주고있다 : 내가 잘못 가고파이썬과 arduino 시리얼 통신

Internal Server Error;
The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log.

를? 다음과 같이 HTML 코드는 다음과 같습니다

<html> 
    <head> 
     <title>Sample Web Form</title> 
    </head> 
<body> 

<h1>Fill Out This Form</h1> 

<form action="/cgi-bin/led.py" method="POST"> 
    <input type="submit" name='action' value="LEFT"> 
    <input type="submit" style="background-color:yellow" name='action' value="LEFT"/><br><br><br> 
    <input type="submit" style="background-color:yellow" name='action' value="BACK"/> 

</form> 

</body> 
</html> 
다음과 같이

파이썬 코드는 다음과 같습니다

#!python 
import serial 
import time 
keyword =form.getvalue('action') 
arduino = serial.Serial('COM4', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=1) 
arduino.open() 
arduino.isOpen() 
time.sleep(5) # waiting the initialization... 
print("initialising") 
while True: 
    if keyword == 'LEFT': 
     arduino.write("H\n") # turns LED ON 
     break 
    elif keyword == 'BACK': 
     arduino.write('L\n') # turns LED OFF 
     break 
    elif break 
arduino.close() #say goodbye to Arduino 

와 아두 이노 코드는 매우 간단합니다 :

int redpin =13; 
int incomingbyte; 

void setup() 
{ 
    Serial.begin(115200); 
    pinMode(redpin,OUTPUT); 
    pinMode(greenpin,OUTPUT); 
    pinMode(fanpin,OUTPUT); 
    } 

void loop() 
{ 
    if(Serial.available()>0) 
    { 
    incomingbyte=Serial.read(); 
    } 
    if(incomingbyte == 'H') 
    { 
    digitalWrite(redpin,HIGH); 
    } 
    if(incomingbyte == 'L') 
    { 
    digitalWrite(redpin,LOW); 
    } 
} 

당신이 날 곳을 알려주세요 수 나는 틀린거야 ?? 나는 Python을 처음 사용한다. 또한 python을 사용하여 동일한 HTML 페이지에서 arduino의 센서 데이터를 표시하려고합니다. 어떻게 그럴 수 있습니다. 이를 위해 HTML과 파이썬 모두의 완벽한 작은 프로그램을 사용할 수 있습니까? 파이썬 스크립트의 내용이 cgi-bin/led.py의 내용 인 경우

+0

"완전한 소형 프로그램을 만들 수 있습니까?"즉, 누군가가이 프로그램을 작성하기를 원하십니까? 요청시 무료로 소프트웨어를 작성합니까? 나는 몇 가지 문제를 지적 할 것이다. 'form'은 정의되지 않았습니다. 'elif break'는'else break'이어야합니다. ' '세 개 중 두 개는 서버가 관련된 한 동일합니다. –

+0

양식을 정의하는 방법은 무엇입니까? 이미 하나의 입력 문을 제거했습니다. 여전히 오류가 있습니다 –

답변

1

, 그것은 다음과 같이한다 :

7 print "Content-type: text/html" 
    8 print 
    9 
    10 print """ 
    11 <html> 
    12 
    13 <head><title>Sample CGI Script</title></head> 
    14 
    15 <body> 
    16 
    17 <h3> Sample CGI Script </h3> 
    18 """ 

당신은 파이썬 스크립트의 헤더를 누락

http://wiki.python.org/moin/CgiScripts에서.

+0

제출 단추를 클릭하면 파이썬 스크립트가 작동하지만 컨트롤이 HTML로 돌아 오지 않습니다. –

+0

그래서 파이썬 스크립트의 내용은'cgi-bin/led.py'의 내용입니까? – User