1.python函数:
(1)基础:
import webiopi
GPIO = webiopi.GPIO
GPIO.setFunction(LIGHT, GPIO.OUT)
GPIO.digitalWrite(LIGHT, GPIO.HIGH)
GPIO.digitalRead(LIGHT)
webiopi.sleep(1)
(2)python宏:
import webiopi
@webiopi.macro
def getLightHours():
return "%d;%d" % (HOUR_ON, HOUR_OFF)
@webiopi.macro
def setLightHours(on, off):
global HOUR_ON, HOUR_OFF
HOUR_ON = int(on)
HOUR_OFF = int(off)
return getLightHours()
2.JS函数
(1)基础:
<script type="text/javascript" src="/webiopi.js"></script>
var button = webiopi().createGPIOButton(17, "Light");
webiopi().refreshGPIO(true);
(2)js中使用宏
webiopi().callMacro("getLightHours", [], updateLightHours);</span>
var sendButton = webiopi().createButton("sendButton", "Send", function() {
// Arguments sent to the macro
var hours = [$("#inputOn").val(), $("#inputOff").val()];
// Call the macro
webiopi().callMacro("setLightHours", hours, updateLightHours);
});