Professional Documents
Culture Documents
Example :
o
Ejemplo:
o Para obtener GPIO 0 Funcin: HTTP GET / GPIO / 0 / funcin
o
Examples:
o
Returns 0 or 1
Example :
o
Examples:
o
Examples :
o
Examples :
o
Returns value
Examples :
o
Returns value
Examples :
o
HTTP GET /*
o
...
"UART0": 1, "I2C0": 0, "I2C1": 1, "SPI0": 0 mean that both UART0 and I2C1
are enabled, whereas both I2C0 and SPI0 are disabled. So GPIOs used by
UART0 (14 and 15) and I2C1 (2 and 3) are disabled and unusable.
CSS styling
Once you wrote your HTML file with your Javascript code, you may want to add some CSS
rules, in order change colors, size, positioning... It's very simple as you follow the naming
convention to write your CSS file.
Pin state buttons (LOW/HIGH) are HTML <button>, and inherit the button CSS style.
Their id are from gpio0 to gpio53. There is also two classes for both low and high states,
and also somes for non GPIO pins :
GND : Ground
V33 : 3.3V
V50 : 5.0V
UART0
SPI0
I2C0
I2C1
With the included RPi header and expert webapps, you can also customize function button
and descriptions :
Pin function buttons (IN/OUT/...) are also HTML <button>, with id
from function0 to function53. Two classes are also used :
Pin descriptions are made of HTML div, with id from name0 to name53, with a single
class :
You can use the included Javascript library to build your own interface.
Example
This example displays big buttons arranged in a column. It also changes the background
color of the GPIO 7 for both low and high states.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content = "height = device-height, width = 420, userscalable = no" />
<title>WebIOPi | Demo</title>
<script type="text/javascript" src="/webiopi.js"></script>
<script type="text/javascript">
webiopi().ready(function() {
var content, button;
content = $("#content");
// create a button which output a bit sequence on GPIO 7 with a 100ms period
button = webiopi().createSequenceButton("sos", "S.O.S 1", 7, 100,
"01010100110011001100101010");
// the previous button will always call myMacroWithArgs with the same "1,2,3"
argument
// you can also create a simple button with your own function
button = webiopi().createButton("macro2", "Macro 3", callMacro);
content.append(button); // append button to content div
// you can also create a button which calls a different function for mouse down
and up events
button = webiopi().createButton("hold", "Hold", mousedown, mouseup);
content.append(button);
// Only for Chrome and Safari, create a slider that pulse out a 0-100% duty
cycle ratio on GPIO 8
button = webiopi().createRatioSlider(8);
content.append(button);
// Only for Chrome and Safari, create a slider that pulse out a -45 to +45
angle on GPIO 9
button = webiopi().createAngleSlider(9);
content.append(button);
});
function mousedown() {
webiopi().digitalWrite(7, 1);
}
function mouseup() {
webiopi().digitalWrite(7, 0);
}
function outputSequence() {
var sequence = "01010100110011001100101010" // S.O.S. morse code or
whatever you want
// output sequence on gpio 7 with a 100ms period
webiopi().outputSequence(7, 100, sequence, sequenceCallback);
}
function callMacro() {
var args = [1,2,3] // or whatever you want
// call myMacroWithArgs(arg)
webiopi().callMacro("myMacroWithArgs", args, macroCallback);
}
</script>
<style type="text/css">
button {
display: block;
margin: 5px 5px 5px 5px;
width: 160px;
height: 45px;
font-size: 24pt;
font-weight: bold;
color: black;
}
input[type="range"] {
display: block;
width: 160px;
height: 45px;
}
#gpio7.LOW {
background-color: White;
}
#gpio7.HIGH {
background-color: Red;
}
</style>
</head>
<body>
<div id="content" align="center"></div>
</body>
</html>
Function details
webiopi()
Returns the WebIOPi object instance.
WebIOPi.ready(callback)
Register the function to call when WebIOPi is ready.
WebIOPi.setFunction(gpio, func[,
callback])
Set the function on the GPIO.
(function) callback (optional) : function called when result received from the server
WebIOPi.digitalWrite(gpio, value[,
callback])
Set the output value of a GPIO.
(int) value : 0 or 1
(function) callback (optional) : function called when result received from the server
WebIOPi.digitalRead(gpio[, callback])
Read the value of a GPIO.
(function) callback (optional) : function called when result received from the server
WebIOPi.toggleValue(gpio)
Toggle value of a GPIO.
WebIOPi.callMacro(macro, [args[,
callback]])
Call a macro on the server.
(function) callback (optional) : function called when result received from the server
WebIOPi.outputSequence(gpio, period,
sequence[, callback])
Output a bit sequence on a GPIO.
(function) callback (optional) : function called when result received from the server
WebIOPi.pulse(gpio[, callback])
Output a single pulse on a GPIO.
(function) callback (optional) : function called when result received from the server
(function) callback (optional) : function called when result received from the server
WebIOPi.pulseAngle(gpio, angle[,
callback])
Output a PWM angle on a GPIO.
(function) callback (optional) : function called when result received from the server
WebIOPi.createButton(id, label[,
mousedown[, mouseup]])
Returns a simple button without predefined behavior.
WebIOPi.createFunctionButton(gpio)
Returns a button that change the function of a GPIO.
WebIOPi.createGPIOButton(gpio, label)
Returns a button that change the state of a GPIO at each click.
WebIOPi.createMacroButton(id, label,
macro, args)
Returns a button that call a macro on the server.
WebIOPi.createSequenceButton(id, label,
gpio, period, sequence)
Returns a button that output a bit sequence on a GPIO.
WebIOPi.createRatioSlider(gpio, ratio)
Returns a slider that send its value as a PWM duty cycle ratio
WebIOPi.createAngleSlider(gpio, angle)
Returns a slider that send its value as a PWM angle
WebIOPi.setLabel(id, label)
Change a label of given button.
GPIOPort
Summary
GPIOPort interface provides functions to use digital I/O.
Supported devices
DS2408 (1-Wire)
PCF8574 (I2C)
Methods list
digitalCount()
Returns the digital channel count.
REST API : GET /devices/name/count
digitalRead(channel)
Returns the value of the given digital channel.
REST API : GET /devices/name/channel/value
digitalReadAll()
Returns a list containing all digital channels value.
REST API : GET /devices/name/*/value
digitalWrite(channel, digit)
Write the value of the given digital channel.
REST API : POST /devices/name/channel/value/digit
portRead()
Returns an integer composed of all digital bits.
REST API : POST /devices/name/*/integer
portWrite(value)
Write on all digital channels with an integer composed of all bits.
REST API : POST /devices/name/*/integer/value
getFunction(channel)
Returns the current fonction of the given digital channel.
getFunctionString(channel)
Returns the current fonction of the given digital channel.
REST API : GET /devices/name/channel/function
setFunction(channel, func)
Setup the given digital channel with the given function
setFunctionString(channel, func)
Setup the given digital channel.
REST API : GET /devices/name/channel/function/func
wildcard()
Returns a list containing the current value and function of all digital channels.
REST API : GET /devices/name/*
Python example
form webiopi.devices.digital import MCP23008
mcp = MCP23008(...)
# or
from webiopi import deviceInstance
mcp = deviceInstance("mcp")
file
mcp.getFunction(0)
mcp.setFunction(0, GPIO.OUT)
mcp.setFunction(1, GPIO.OUT)
mcp.setFunction(2, GPIO.OUT)
mcp.setFunction(3, GPIO.OUT)
mcp.digitalRead(4)
mcp.portWrite(0x0F)
mcp.portRead()
REST example
HTTP GET /devices/mcp/0/function
HTTP GET /devices/mcp/0/value
Analog package provides drivers for analog converter and PWM drivers.
Supported devices
Methods list
analogCount()
Returns the analog channel count.
REST API : GET /devices/name/analog/count
analogResolution()
Returns the analog resolution (bit count).
REST API : GET /devices/name/analog/count
analogMaximum()
Returns the analog maximum integer value.
REST API : GET /devices/name/analog/maximum
analogReference()
Returns the Voltage reference for a full scale.
REST API : GET /devices/name/analog/vref
analogRead(channel)
Returns the integer value of the given analog channel.
REST API : GET /devices/name/analog/channel/integer
analogReadFloat(channel)
Returns the float value of the given analog channel, from 0.0 to 1.0.
REST API : GET /devices/name/analog/channel/float
analogReadVolt(channel)
Returns the voltage value of the given analog channel.
REST API : GET /devices/name/analog/channel/volt
analogReadAll()
Returns a list containing all analog channels integer value.
REST API : GET /devices/name/analog/*/integer
analogReadAllFloat()
Returns a list containing all analog channels float value.
REST API : GET /devices/name/analog/*/float
analogReadAllVolt()
Returns a list containing all analog channels voltage value.
REST API : GET /devices/name/analog/*/float
Python example
from webiopi import deviceInstance
from webiopi.devices.analog import ADS1015, MCP3208
ads = ADS1015(...)
# or
ads = deviceInstance("ads") # retrieve device named "ads" in configuration file
ads.analogCount()
ads.analogMaximum()
ads.analogRead(0)
ads.analogReadFloat(0)
ads.analogReadVolt(0)
mcp = MCP3208(...)
mcp.analogCount()
mcp.analogMaximum()
mcp.analogRead(0)
mcp.analogReadFloat(0)
mcp.analogReadVolt(0)
REST example
HTTP GET /devices/ads/analog/0/integer # returns "ads" analog channel 0 as
integer
HTTP GET /devices/ads/analog/0/float
Supported devices
MCP4725 (I2C)
Methods list
analogWrite(channel, value)
Write an integer value to the given analog channel.
REST API : POST /devices/name/analog/channel/integer/value
analogWriteFloat(channel, ratio)
Write a float ratio value to the given analog channel.
REST API : POST /devices/name/analog/channel/float/value
analogWriteVolt(channel, volts)
Write a voltage value to the given analog channel.
REST API : POST /devices/name/analog/channel/volt/value
Python example
from webiopi.devices.analog import MCP4725
mcp = MCP4725(...)
mcp.analogCount()
max = mcp.analogMaximum()
mcp.analogWrite(0, max)
mcp.analogReadFloat(0)
mcp.analogReadVolt(0)
REST example
HTTP POST /devices/mcp/analog/0/integer/0
Supported devices
PCA9685 (I2C)
Methods lists
pwmCount()
Returns the PWM channel count.
REST API : GET /devices/name/pwm/count
pwmResolution()
Returns the PWM resolution (bit count).
pwmMaximum()
Returns the PWM maximum integer value.
REST API : GET /devices/name/pwm/maximum
pwmWrite(channel, value)
Write an integer value to the given PWM channel.
REST API : POST /devices/name/pwm/channel/integer/value
pwmWriteFloat(channel, ratio)
Write a float duty-cycle ratio value to the given PWM channel.
REST API : POST /devices/name/pwm/channel/float/value
pwmWriteAngle(channel, angle)
Write a servo angle value to the given PWM channel.
REST API : POST /devices/name/pwm/channel/angle/value
pwmRead(channel)
Returns the integer value of the given PWM channel.
REST API : GET /devices/name/pwm/channel/integer
pwmReadFloat(channel)
Returns the float duty-cycle ratio value of the given PWM channel.
REST API : GET /devices/name/pwm/channel/float
pwmReadAngle(channel)
Returns the servo angle value of the given PWM channel.
REST API : GET /devices/name/pwm/channel/angle
pwmReadAll()
Returns a list containing all PWM channels integer value.
REST API : GET /devices/name/pwm/*/integer
pwmReadAllFloat()
Returns a list containing all PWM channels float duty-cycle ratio value.
REST API : GET /devices/name/pwm/*/float
pwmReadAllAngle()
Returns a list containing all PWM channels servo angle value.
REST API : GET /devices/name/pwm/*/angle
pwmWildcard()
Returns a list containing all PWM channels value.
REST API : GET /devices/name/pwm/*
Python example
from webiopi import deviceInstance
from webiopi.devices.analog import PCA9685
pca = PCA9685(...)
# or
pca = deviceInstance("pca") # retrieve device named "pca" in configuration file
pca.pwmCount()
max = pca.pwmMaximum()
pca.pwmWrite(0, max)
REST example
HTTP POST /devices/pca/pwm/0/integer/0 # set 0% on "pca" pwm channel 0
(integer value)
HTTP POST /devices/pca/pwm/0/float/0.0 # set 0% on "pca" pwm channel 0 (float
value)
HTTP POST /devices/pca/pwm/0/angle/0.0 # set 0 on "pca" pwm channel 0 (servo
angle value)
HTTP GET /devices/pca/pwm/0/integer
integer
HTTP GET /devices/pca/pwm/0/float
HTTP GET /devices/pca/pwm/0/angle
angle
Temperature
Summary
Temperature interface provides functions to read temperature.
Supported devices
DS18* (1-Wire)
BMP085 (I2C)
Methods list
getKelvin()
Returns the temperature in kelvin.
REST API : GET /devices/name/sensor/temperature/k
getCelsius()
Returns the temperature in celsius.
REST API : GET /devices/name/sensor/temperature/c
getFahrenheit()
Returns the temperature in fahrenheit.
Python example
from webiopi.devices.analog import TMP102
tmp = TMP102(...)
# or
from webiopi import deviceInstance
tmp = deviceInstance("tmp") # retrieve device named "tmp" in configuration file
tmp.getKelvin()
tmp.getCelsius()
tmp.getFahrenheit()
REST example
HTTP GET /devices/tmp/sensor/temperature/k
HTTP GET /devices/tmp/sensor/temperature/c
HTTP GET /devices/tmp/sensor/temperature/f
Pressure
Summary
Pressure interface provides functions to read atmospheric pressure.
Supported devices
BMP085 (I2C)
Methods list
getPascal()
Returns the pressure in pascal.
REST API : GET /devices/name/sensor/pressure/pa
getHectoPascal()
Returns the pressure in hecto pascal.
REST API : GET /devices/name/sensor/pressure/hpa
getPascalAtSea()
Returns the pressure at sea level in pascal.
REST API : GET /devices/name/sensor/pressure/sea/pa
getHectoPascalAtSea()
Returns the pressure at sea level in hecto pascal.
REST API : GET /devices/name/sensor/pressure/sea/hpa
Python example
from webiopi.devices.analog import BMP085
bmp = BMP085(...)
# or
bmp.getHectoPascal()
bmp.getHectoPascalAtSea()
REST example
HTTP GET /devices/bmp/sensor/pressure/hpa
HTTP GET /devices/bmp/sensor/pressure/sea/hpa
Luminosity
Summary
Luminosity interface provides functions to measure light.
Supported devices
TSL2561 (I2C)
TSL4531 (I2C)
VCNL4000 (I2C)
Methods list
getLux()
Returns the luminosity in lux.
REST API : GET /devices/name/sensor/luminosity/lx
Python example
from webiopi.devices.analog import TSL2561
tsl = TSL2561(...)
# or
from webiopi import deviceInstance
tsl = deviceInstance("tsl") # retrieve device named "tsl" in configuration file
tsl.getLux()
REST example
HTTP GET /devices/tmp/sensor/luminosity/lx
Distance
Summary
Distance interface provides functions to measure distances.
Supported devices
VCNL4000 (I2C)
Methods list
getMillimeter()
Returns the distance in millimeter.
REST API : GET /devices/name/sensor/distance/mm
getCentimeter()
Returns the distance in millimeter.
REST API : GET /devices/name/sensor/distance/cm
getInch()
Returns the distance in millimeter.
REST API : GET /devices/name/sensor/distance/in
Python example
from webiopi.devices.analog import TSL2561
vcn = VCNL4000(...)
# or
from webiopi import deviceInstance
vcn = deviceInstance("vcn") # retrieve device named "vcn" in configuration file
vcn.getMillimeter()
REST example
HTTP GET /devices/tmp/sensor/distance/mm