Javascript Python与浏览器的交互(Raspberry WebioPi)

Javascript Python与浏览器的交互(Raspberry WebioPi),javascript,python,html,raspberry-pi,webiopi,Javascript,Python,Html,Raspberry Pi,Webiopi,我使用一个叫做“webiopi”的工具,通过一个树莓pi和一个中继板来控制一个健康设备。此工具使用Python脚本连接网页上的按钮。 我可以从我创建的按钮上的GPIO引脚读取状态(低/高) 我想要的是在浏览器中显示脚本中的值。 (如“测量温度”或“计算时间”) 有没有一种方法可以将python脚本的输出显示给webbrowser button = webiopi().createMacroButton("macro", "Normaal", "Prog1"); $("#top")

我使用一个叫做“webiopi”的工具,通过一个树莓pi和一个中继板来控制一个健康设备。此工具使用Python脚本连接网页上的按钮。 我可以从我创建的按钮上的GPIO引脚读取状态(低/高)

我想要的是在浏览器中显示脚本中的值。 (如“测量温度”或“计算时间”)

有没有一种方法可以将python脚本的输出显示给webbrowser

    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>
button=webiopi().createMacroButton(“宏”、“标准”、“程序1”);
$(“#顶部”)。追加(按钮)
{{print here output from script.py}}

您可以使用PHP调用脚本并将输出回显到页面。您需要安装并启用PHP,文件必须以
.PHP
结尾。如果你知道你正在使用的Web服务器,我可以给你一些额外的帮助。还要注意的是,脚本应该将它希望在web页面上显示的所有信息打印到标准输出中

    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>
button=webiopi().createMacroButton(“宏”、“标准”、“程序1”);
$(“#顶部”)。追加(按钮)

在本论坛[Wpio论坛][1]

给Pete Dudash这个问题的答案,我复制到这里

是的,这是可能的。您要做的是在javascript中添加一个回调例程。首先,在javascript中执行一些操作(通过按下按钮或定时器)并调用python宏。这一次,在调用宏时指定回调例程。回调例程从宏接收数据,然后您可以使用它执行任何操作

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);
}

}

Python:

@webiopi.macro
def sendData():

HTML:


{{print here output from script.py}}

这是我绝对不想要的。我已经必须处理Javascript和Python,这对我来说是全新的。我不想要对我来说也是新的PHP。不过,感谢您的建议。如果您不懂Perl,这是最简单的解决方案。
@webiopi.macro
<div id="content" align="center">
<td></td>

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

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