2016-04-15 6 views
0

Ich verwende ein Tool namens "Webiopi", um ein Wellness-Gerät über einen Raspberry Pi und eine Relaisplatine zu steuern. Dieses Tool verbindet Schaltflächen auf einer Webseite mit einem Python-Skript. Ich kann den Status (niedrig/hoch) von den GPIO-Pins auf den Tasten, die ich erstellt habe, lesen.Python-Interaktion mit Browser (Raspberry WebioPi)

Ich möchte Werte aus dem Skript im Browser anzeigen. (Wie 'temperature_measured' oder 'Calculated_time')

Gibt es eine Möglichkeit, die Ausgabe von dem Python-Skript zum Webbrowser anzuzeigen?

button = webiopi().createMacroButton("macro", "Normaal", "Prog1"); 
    $("#top").append(button) 

<div id="content" align="center"> 
<td>  
    </td> 
          {{print here output from script.py}} 
     <div id="top"></div> 

    </div> 
</div> 

Antwort

0

In diesem Forum [Wpio Forum] [1] https://groups.google.com/forum/#!topic/webiopi/DreW_74gm0o

gibt Pete Dudash die Antwort auf diese Frage, die ich

Ja hier kopieren, das möglich ist. Was Sie suchen, ist eine Rückrufroutine zu Ihrem Javascript hinzuzufügen. Zuerst führen Sie eine Aktion in Javascript aus (entweder durch Drücken einer Taste oder eines Timers) und rufen ein Python-Makro auf. Dieses Mal geben Sie beim Aufrufen des Makros eine Rückrufroutine an. Die Rückrufroutine empfängt Daten vom Makro und dann können Sie damit machen, was Sie wollen.

Javascript:

function getPythonResponse() { 
// "sendData" is the name of the macro you specify in your script.py 
// "[]" is an empty list. If you want to send data for the macro to use, you would include that here 
// "handlePythonResponse" is the name of the callback routine that will execute once the python macro is finished 
webiopi().callMacro("sendData", [], handlePythonResponse); 

}

var handlePythonResponse = function(macro, args, response) { 
// "response" is the variable that holds the data from script.py 
// Now we can apply those results to the webpage by assigning the value to the "pythonResult" id. This is the element in your HTML where you want to print the info. 
$("#pythonResult").text(response); 

}

Python:

@webiopi.macro 

def senddata():

HTML:

<div id="content" align="center"> 
<td></td> 

<span id="pythonResult">{{print here output from script.py}}</span> 

<div id="top"></div> 

0

Sie könnten PHP verwenden, um das Skript aufzurufen und die Ausgabe auf der Seite zu wiederholen. Sie müssen PHP installiert und aktiviert haben, und die Datei muss mit .php enden. Wenn Sie den Webserver kennen, den Sie verwenden, kann ich Ihnen zusätzliche Hilfe geben. Beachten Sie auch, dass das Skript alle gewünschten Informationen auf der Webseite in die Standardausgabe drucken soll.

button = webiopi().createMacroButton("macro", "Normaal", "Prog1"); 
    $("#top").append(button) 

<div id="content" align="center"> 
<td>  
    </td> 
     <?php exec("python myscript.py", $out); echo $out; ?> 
     <div id="top"></div> 

    </div> 
</div> 
+0

das, was ich will absolut nicht. Ich muss mich bereits mit Javascript und Python beschäftigen, die für mich völlig neu sind. Ich will kein PHP, das mir neu ist. Aber danke für Ihren Vorschlag – Richard

+0

Nun, falls Sie Perl nicht kennen, ist dies die einfachste Lösung. – randomdude999