Richard Richard - 1 year ago 492
HTML Question

Python interaction with browser (Raspberry WebioPi)

I use a tool called "webiopi" to control a wellness device via a Raspberry pi and a relay board. This tool connect buttons on a webpage with a Python script.
I can read the state (low/high) from the GPIO pins on the buttons i've created.

What i want is to show values from the script in the browser.
(Like ' temperature_measured' or. 'Calculated_time')

Is there a way i can show output from the python script to the webbrowser?

button = webiopi().createMacroButton("macro", "Normaal", "Prog1");

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


Answer Source

In a this forum [Wpio forum][1]!topic/webiopi/DreW_74gm0o

gives Pete Dudash the answer to this question, which i copy here

Yes, this is possible. What you’re looking to do is add a callback routine to your javascript. First you execute some action in javascript (either from a button press or a timer) and call a python macro. This time, you specify a call back routine when calling the macro. The call back routine receives data from the macro and then you can do whatever you want with it.


function getPythonResponse() {
// "sendData" is the name of the macro you specify in your
// "[]" 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
// 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.




def sendData():


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

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download