You are on page 1of 35

La API REST incluido le permite hacer es el propietario del cliente, mediante llamadas

HTTP REST. Usted puede usarlo para lograr varias tareas:


Los errores devueltos por el WebAPI son comprensibles cuando la llamada HTTP no es
vlido:

400 Bad Request (ruta incompleta)

403 GPIO # No disponible

403 GPIO # discapacitados

404 [algo] no encontrado

Obtener funcin GPIO


Get GPIO function

HTTP GET /GPIO/(gpioNumber)/function


o

Example :
o

Returns "in" or "out"

To get GPIO 0 function : HTTP GET /GPIO/0/function

HTTP GET / / funcin GPIO / (gpioNumber)


o Devoluciones "en" o "fuera"

Ejemplo:
o Para obtener GPIO 0 Funcin: HTTP GET / GPIO / 0 / funcin
o

Set GPIO function

HTTP POST /GPIO/(gpioNumber)/function/("in" or "out" or "pwm")

Returns new setup : "in" or "out" or "pwm"

Examples:
o

To set GPIO 0 as input : HTTP POST /GPIO/0/function/in

To set GPIO 1 as output : HTTP POST /GPIO/1/function/out

Get GPIO value

HTTP GET /GPIO/(gpioNumber)/value


o

Returns 0 or 1

Example :
o

To get GPIO 0 value : HTTP GET /GPIO/0/value

Set GPIO value

HTTP POST /GPIO/(gpioNumber)/value/(0 or 1)


o

Returns new value : 0 or 1

Examples:
o

To raise GPIO 0 : HTTP POST /GPIO/0/value/1

To fall GPIO 1 : HTTP POST /GPIO/1/value/0

Output a single pulse

HTTP POST /GPIO/(gpioNumber)/pulse/


o

Returns last bit

Examples :
o

To output a single pulse on GPIO 0 : HTTP POST /GPIO/0/pulse/

Output bit sequence

HTTP POST /GPIO/(gpioNumber)/sequence/(delay),(sequence)


o

Returns last bit

Examples :
o

To output a pulse on GPIO 0 with a 10ms delay : HTTP POST


/GPIO/0/sequence/10,010

Output PWM with a duty cycle ratio

HTTP POST /GPIO/(gpioNumber)/pulseRatio/(ratio)


o

Returns value

Examples :
o

To output a PWM with a 50% ratio : HTTP POST /GPIO/0/pulseRatio/0.5

Output PWM with an angle for


servos

HTTP POST /GPIO/(gpioNumber)/pulseAngle/(angle)


o

Returns value

Examples :
o

To output a PWM for a 0 angle (neutral) : HTTP POST


/GPIO/0/pulseAngle/0

Call a macro on the server

HTTP POST /macros/(macro)/(args)


o

Returns the value returned by the macro

Get full GPIO state/configuration

HTTP GET /*
o

Returns full GPIO state in JSON :

{"UART0": 1, "I2C0": 0, "I2C1": 1, "SPI0": 0, "GPIO":{

"0": {"function": "IN", "value": 1},

"1": {"function": "IN", "value": 1},

"2": {"function": "ALT0", "value": 1},

"3": {"function": "ALT0", "value": 1},

"4": {"function": "IN", "value": 0},

"5": {"function": "ALT0", "value": 0},

"6": {"function": "OUT", "value": 1},

...

"53": {"function": "ALT3", "value": 1}


}}

"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 :

Default : Generic buttons

LOW : GPIO in low state

HIGH : GPIO in high state

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 :

.FunctionBasic : Used when GPIO is Input or Output

.FunctionSpecial : Used when GPIO is in ALTx (default is hidden)

Pin descriptions are made of HTML div, with id from name0 to name53, with a single
class :

.Description : Text on the left/right of each pin

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 "SWITCH" labeled button for GPIO 0


button = webiopi().createGPIOButton(0, "SWITCH");
content.append(button); // append button to content div

// create a "LED" labeled button for GPIO 7


button = webiopi().createGPIOButton(7, "LED");
content.append(button); // append button to content div

// create a button that output a single pulse


button = webiopi().createPulseButton("pulse", "Pulse", 7);
content.append(button); // append button to content div

// 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");

content.append(button); // append button to content div

// the previous button will always output the same sequence


// you can also create a simple button with your own function
button = webiopi().createButton("sos2", "S.O.S 2", outputSequence);
content.append(button); // append button to content div

// create a button which call myMacroWithoutArgs


button = webiopi().createMacroButton("macro", "Macro 1",
"myMacroWithoutArgs");
content.append(button); // append button to content div

// create a button which call myMacroWithArgs with "1,2,3" as argument


button = webiopi().createMacroButton("macro", "Macro 2",
"myMacroWithArgs", [1,2,3]);
content.append(button); // append button to content div

// 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 sequenceCallback(gpio, data) {


alert("sequence on " + gpio + " finished with " + data);
}

function callMacro() {
var args = [1,2,3] // or whatever you want
// call myMacroWithArgs(arg)
webiopi().callMacro("myMacroWithArgs", args, macroCallback);
}

function macroCallback(macro, args, data) {


alert(macro + " returned with " + data);
}

</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.

(function) callback : function to call

WebIOPi.setFunction(gpio, func[,
callback])
Set the function on the GPIO.

(int) gpio : GPIO number from 0 to 53

(string) func : "IN" or "OUT" or "PWM"

(function) callback (optional) : function called when result received from the server

WebIOPi.digitalWrite(gpio, value[,
callback])
Set the output value of a GPIO.

(int) gpio : GPIO number from 0 to 53

(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.

(int) gpio : GPIO number from 0 to 53

(function) callback (optional) : function called when result received from the server

WebIOPi.toggleValue(gpio)
Toggle value of a GPIO.

(int) gpio : GPIO number from 0 to 53

WebIOPi.callMacro(macro, [args[,
callback]])
Call a macro on the server.

(string) macro : name of the macro to call

(string) arg (optional) : array containing arguments

(function) callback (optional) : function called when result received from the server

WebIOPi.outputSequence(gpio, period,
sequence[, callback])
Output a bit sequence on a GPIO.

(int) gpio : GPIO number from 0 to 53

(int) period : time in ms between each bit

(string) sequence : bit sequence

(function) callback (optional) : function called when result received from the server

WebIOPi.pulse(gpio[, callback])
Output a single pulse on a GPIO.

(int) gpio : GPIO number from 0 to 53

(function) callback (optional) : function called when result received from the server

WebIOPi.pulseRatio(gpio, ratio[, callback])


Output a PWM duty cycle ratio on a GPIO.

(int) gpio : GPIO number from 0 to 53

(float) ratio : duty cycle from 0.0 to 1.0

(function) callback (optional) : function called when result received from the server

WebIOPi.pulseAngle(gpio, angle[,
callback])
Output a PWM angle on a GPIO.

(int) gpio : GPIO number from 0 to 53

(int) angle : angle in degree from -45 to +45

(function) callback (optional) : function called when result received from the server

WebIOPi.createButton(id, label[,
mousedown[, mouseup]])
Returns a simple button without predefined behavior.

(string) id : id of the button to create

(string) label : label of the button

(function) mousedown (optional) : function called on mousedown/click event

(function) mouseup (optional) : function called on mouseup event

WebIOPi.createFunctionButton(gpio)
Returns a button that change the function of a GPIO.

(int) gpio : GPIO number from 0 to 53

WebIOPi.createGPIOButton(gpio, label)
Returns a button that change the state of a GPIO at each click.

(int) gpio : GPIO number from 0 to 53

(string) label : label of the button

WebIOPi.createMacroButton(id, label,
macro, args)
Returns a button that call a macro on the server.

(string) id : id of the button to create

(string) label : label of the button

(string) macro : name of the macro to call

(string) args : string arguments

WebIOPi.createSequenceButton(id, label,
gpio, period, sequence)
Returns a button that output a bit sequence on a GPIO.

(string) id : id of the button to create

(string) label : label of the button

(int) gpio : GPIO number from 0 to 53

(int) period : time in ms between each bit

(string) sequence : bit sequence

WebIOPi.createRatioSlider(gpio, ratio)
Returns a slider that send its value as a PWM duty cycle ratio

(int) gpio : GPIO number from 0 to 53

(float) ratio : slider's init value

WebIOPi.createAngleSlider(gpio, angle)
Returns a slider that send its value as a PWM angle

(int) gpio : GPIO number from 0 to 53

(int) angle : slider's init value

WebIOPi.setLabel(id, label)
Change a label of given button.

(string) id : id of the button to change

(string) label : new label of the button

Digital package provides drivers for GPIO expanders.

GPIOPort
Summary
GPIOPort interface provides functions to use digital I/O.

Supported devices

DS2408 (1-Wire)

MCP230xx series (I2C): MCP23008, MCP23009, MCP23017, MCP23018

MCP23Sxx series (SPI): MCP23S08, MCP23S09, MCP23S17, MCP23S18

PCF8574 (I2C)

Methods list
digitalCount()
Returns the digital channel count.
REST API : GET /devices/name/count

name : device name from configuration file

digitalRead(channel)
Returns the value of the given digital channel.
REST API : GET /devices/name/channel/value

name (str) : device name from configuration file

channel (int) : digital channel number

digitalReadAll()
Returns a list containing all digital channels value.
REST API : GET /devices/name/*/value

name (str) : device name from configuration file

digitalWrite(channel, digit)
Write the value of the given digital channel.
REST API : POST /devices/name/channel/value/digit

name (str) : device name from configuration file

channel (int) : digital channel number

digit (int) : digital value (0 or 1)

portRead()
Returns an integer composed of all digital bits.
REST API : POST /devices/name/*/integer

name (str) : device name from configuration file

portWrite(value)
Write on all digital channels with an integer composed of all bits.
REST API : POST /devices/name/*/integer/value

name (str) : device name from configuration file

value (int) : integer value to write on the port.

getFunction(channel)
Returns the current fonction of the given digital channel.

channel (int) : digital channel number

REST API : Use getFunctionString instead.

getFunctionString(channel)
Returns the current fonction of the given digital channel.
REST API : GET /devices/name/channel/function

name (str) : device name from configuration file

channel (int) : digital channel number

setFunction(channel, func)
Setup the given digital channel with the given function

channel (int) : digital channel number

func (int) : GPIO.IN or GPIO.OUT

REST API : Use setFunctionString instead.

setFunctionString(channel, func)
Setup the given digital channel.
REST API : GET /devices/name/channel/function/func

name (str) : device name from configuration file

channel (int) : digital channel number

func (str) : "IN" or "OUT"

wildcard()
Returns a list containing the current value and function of all digital channels.
REST API : GET /devices/name/*

name (str) : device name from configuration file

Python example
form webiopi.devices.digital import MCP23008
mcp = MCP23008(...)

# setup a MCP23008 I2C GPIO expander

# or
from webiopi import deviceInstance
mcp = deviceInstance("mcp")
file

mcp.getFunction(0)

# retrieve device named "mcp" in configuration

# get current MCP digital channel 0 setup

mcp.setFunction(0, GPIO.OUT)

# setup MCP digital channel 0 as output

mcp.setFunction(1, GPIO.OUT)

# setup MCP digital channel 1 as output

mcp.setFunction(2, GPIO.OUT)

# setup MCP digital channel 2 as output

mcp.setFunction(3, GPIO.OUT)

# setup MCP digital channel 3 as output

mcp.digitalRead(4)

# read MCP digital channel 0

mcp.digitalWrite(4, GPIO.HIGH) # write MCP digital channel 4 as HIGH

mcp.portWrite(0x0F)

mcp.portRead()

# write channels 0-3 as HIGH

# read all MCP digital channels in a single integer

REST example
HTTP GET /devices/mcp/0/function
HTTP GET /devices/mcp/0/value

# retrieve "mcp" channel 0 setup


# retrieve "mcp" channel 0 digital value

HTTP POST /devices/mcp/0/function/out # set "mcp" channel 0 as output


HTTP POST /devices/mcp/0/value/1

# set "mcp" channel 0 as digital HIGH

Analog package provides drivers for analog converter and PWM drivers.

ADC (Analog-to-Digital Converter)


Summary
ADC interface provide analogRead functions to read analog inputs.

Supported devices

ADS1000 series (I2C): ADS1014, ADS1015, ADS1114, ADS1115

MCP3000 series (SPI): MCP3004, MCP3008, MCP3204, MCP3208

Methods list
analogCount()
Returns the analog channel count.
REST API : GET /devices/name/analog/count

name : device name from configuration file

analogResolution()
Returns the analog resolution (bit count).
REST API : GET /devices/name/analog/count

name : device name from configuration file

analogMaximum()
Returns the analog maximum integer value.
REST API : GET /devices/name/analog/maximum

name : device name from configuration file

analogReference()
Returns the Voltage reference for a full scale.
REST API : GET /devices/name/analog/vref

name : device name from configuration file

analogRead(channel)
Returns the integer value of the given analog channel.
REST API : GET /devices/name/analog/channel/integer

name (str) : device name from configuration file

channel (int) : analog channel number

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

name (str) : device name from configuration file

channel (int) : analog channel number

analogReadVolt(channel)
Returns the voltage value of the given analog channel.
REST API : GET /devices/name/analog/channel/volt

name (str) : device name from configuration file

channel (int) : analog channel number

analogReadAll()
Returns a list containing all analog channels integer value.
REST API : GET /devices/name/analog/*/integer

name (str) : device name from configuration file

analogReadAllFloat()
Returns a list containing all analog channels float value.
REST API : GET /devices/name/analog/*/float

name (str) : device name from configuration file

analogReadAllVolt()
Returns a list containing all analog channels voltage value.
REST API : GET /devices/name/analog/*/float

name (str) : device name from configuration file

Python example
from webiopi import deviceInstance
from webiopi.devices.analog import ADS1015, MCP3208
ads = ADS1015(...)

# setup a ADS1015 I2C ADC

# or
ads = deviceInstance("ads") # retrieve device named "ads" in configuration file
ads.analogCount()
ads.analogMaximum()
ads.analogRead(0)

# returns ADS1015 analog channel count


# returns ADS1015 maximum integer value
# returns ADS1015 analog channel 0 as integer

ads.analogReadFloat(0)

# returns ADS1015 analog channel 0 as float

ads.analogReadVolt(0)

# returns ADS1015 analog channel 0 as volt

mcp = MCP3208(...)

# setup a MCP3208 SPI ADC

mcp.analogCount()

# returns MCP3208 analog channel count

mcp.analogMaximum()
mcp.analogRead(0)

# returns MCP3208 maximum integer value


# returns MCP3208 analog channel 0 as integer

mcp.analogReadFloat(0)

# returns MCP3208 analog channel 0 as float

mcp.analogReadVolt(0)

# returns MCP3208 analog channel 0 as volt

REST example
HTTP GET /devices/ads/analog/0/integer # returns "ads" analog channel 0 as
integer
HTTP GET /devices/ads/analog/0/float

# returns "ads" analog channel 0 as float

HTTP GET /devices/ads/analog/0/volt

# returns "ads" analog channel 0 as volt

DAC (Digital-to-Analog Converter)


Summary
DAC interfaces extends ADC to add analogWrite functions.

Supported devices

MCP4725 (I2C)

MCP492x (SPI) : MCP4921, MCP4922

Methods list
analogWrite(channel, value)
Write an integer value to the given analog channel.
REST API : POST /devices/name/analog/channel/integer/value

name (str) : device name from configuration file

channel (int) : analog channel number

value (int) : integer value to output from 0 to analogMaximum

analogWriteFloat(channel, ratio)
Write a float ratio value to the given analog channel.
REST API : POST /devices/name/analog/channel/float/value

name (str) : device name from configuration file

channel (int) : analog channel number

value (float) : float ratio to output from 0.0 to 1.0

analogWriteVolt(channel, volts)
Write a voltage value to the given analog channel.
REST API : POST /devices/name/analog/channel/volt/value

name (str) : device name from configuration file

channel (int) : analog channel number

value (float) : voltage value to output from 0.0 to analogReference

Python example
from webiopi.devices.analog import MCP4725
mcp = MCP4725(...)
mcp.analogCount()

# setup a MCP4725 I2C DAC


# returns MCP4725 analog channel count

max = mcp.analogMaximum()
mcp.analogWrite(0, max)

# returns MCP4725 maximum integer value

# set 100% on MCP4725 analog channel 0

mcp.analogWriteFloat(0, 0.5) # set 50% on MCP4725 analog channel 0


mcp.analogWriteVolt(0, 0.0) # set 0V on MCP4725 analog channel 0
mcp.analogRead(0)

# returns MCP4725 analog channel 0 as integer

mcp.analogReadFloat(0)

# returns MCP4725 analog channel 0 as float

mcp.analogReadVolt(0)

# returns MCP4725 analog channel 0 as volt

REST example
HTTP POST /devices/mcp/analog/0/integer/0

# send 0 to "mcp" analog channel 0

HTTP POST /devices/mcp/analog/0/float/0.0

# send 0 to "mcp" analog channel 0

HTTP POST /devices/mcp/analog/0/volt/0.0

# send 0 to "mcp" analog channel 0

HTTP GET /devices/mcp/analog/0/integer


integer

# returns "mcp" analog channel 0 as

HTTP GET /devices/mcp/analog/0/float


float

# returns "mcp" analog channel 0 as

HTTP GET /devices/mcp/analog/0/volt


volt

# returns "mcp" analog channel 0 as

PWM (Pulse Width Modulation)


Summary
PWM interface provides pwmWrite functions to output duty-cycle ratio PWM.

Supported devices

PCA9685 (I2C)

Methods lists
pwmCount()
Returns the PWM channel count.
REST API : GET /devices/name/pwm/count

name (str) : device name from configuration file

pwmResolution()
Returns the PWM resolution (bit count).

REST API : GET /devices/name/pwm/resolution

name (str) : device name from configuration file

pwmMaximum()
Returns the PWM maximum integer value.
REST API : GET /devices/name/pwm/maximum

name (str) : device name from configuration file

pwmWrite(channel, value)
Write an integer value to the given PWM channel.
REST API : POST /devices/name/pwm/channel/integer/value

name (str) : device name from configuration file

channel (int) : analog channel number

value (int) : integer value to output from 0 to pwmMaximum

pwmWriteFloat(channel, ratio)
Write a float duty-cycle ratio value to the given PWM channel.
REST API : POST /devices/name/pwm/channel/float/value

name (str) : device name from configuration file

channel (int) : analog channel number

value (float) : float duty-cycle ratio value to output from 0 to 1.0

pwmWriteAngle(channel, angle)
Write a servo angle value to the given PWM channel.
REST API : POST /devices/name/pwm/channel/angle/value

name (str) : device name from configuration file

channel (int) : analog channel number

value (float) : angle value to output

pwmRead(channel)
Returns the integer value of the given PWM channel.
REST API : GET /devices/name/pwm/channel/integer

name (str) : device name from configuration file

channel (int) : analog channel number

pwmReadFloat(channel)
Returns the float duty-cycle ratio value of the given PWM channel.
REST API : GET /devices/name/pwm/channel/float

name (str) : device name from configuration file

channel (int) : analog channel number

pwmReadAngle(channel)
Returns the servo angle value of the given PWM channel.
REST API : GET /devices/name/pwm/channel/angle

name (str) : device name from configuration file

channel (int) : analog channel number

pwmReadAll()
Returns a list containing all PWM channels integer value.
REST API : GET /devices/name/pwm/*/integer

name (str) : device name from configuration file

channel (int) : analog channel number

pwmReadAllFloat()
Returns a list containing all PWM channels float duty-cycle ratio value.
REST API : GET /devices/name/pwm/*/float

name (str) : device name from configuration file

channel (int) : analog channel number

pwmReadAllAngle()
Returns a list containing all PWM channels servo angle value.
REST API : GET /devices/name/pwm/*/angle

name (str) : device name from configuration file

channel (int) : analog channel number

pwmWildcard()
Returns a list containing all PWM channels value.
REST API : GET /devices/name/pwm/*

name (str) : device name from configuration file

Python example
from webiopi import deviceInstance
from webiopi.devices.analog import PCA9685
pca = PCA9685(...)

# setup a PCA9685 I2C PWM

# or
pca = deviceInstance("pca") # retrieve device named "pca" in configuration file
pca.pwmCount()

# returns PCA9685 pwm channel count

max = pca.pwmMaximum()
pca.pwmWrite(0, max)

# returns PCA9685 maximum integer value


# set 100% on PCA9685 pwm channel 0 (integer value)

pca.pwmWriteFloat(0, 0.5) # set 50% on PCA9685 pwm channel 0 (float value)

pca.pwmWriteAngle(0, 0.0) # set 0 on PCA9685 pwm channel 0 (servo angle


value)
pca.pwmRead(0)
pca.pwmReadFloat(0)
pca.pwmReadAngle(0)

# returns PCA9685 pwm channel 0 as integer


# returns PCA9685 pwm channel 0 as float
# returns PCA9685 pwm channel 0 as angle

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

# returns "pca" pwm channel 0 as


# returns "pca" pwm channel 0 as float
# returns "pca" pwm channel 0 as servo

Sensor package provides drivers for various sensors.

Temperature
Summary
Temperature interface provides functions to read temperature.

Supported devices

DS18* (1-Wire)

TMPXXX (I2C) : TMP75, TMP102, TMP275

BMP085 (I2C)

Methods list
getKelvin()
Returns the temperature in kelvin.
REST API : GET /devices/name/sensor/temperature/k

name : device name from configuration file

getCelsius()
Returns the temperature in celsius.
REST API : GET /devices/name/sensor/temperature/c

name : device name from configuration file

getFahrenheit()
Returns the temperature in fahrenheit.

REST API : GET /devices/name/sensor/temperature/f

name : device name from configuration file

Python example
from webiopi.devices.analog import TMP102
tmp = TMP102(...)

# setup a TMP102 I2C Temperature sensor

# 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

name : device name from configuration file

getHectoPascal()
Returns the pressure in hecto pascal.
REST API : GET /devices/name/sensor/pressure/hpa

name : device name from configuration file

getPascalAtSea()
Returns the pressure at sea level in pascal.
REST API : GET /devices/name/sensor/pressure/sea/pa

name : device name from configuration file

getHectoPascalAtSea()
Returns the pressure at sea level in hecto pascal.
REST API : GET /devices/name/sensor/pressure/sea/hpa

name : device name from configuration file

Python example
from webiopi.devices.analog import BMP085
bmp = BMP085(...)
# or

# setup a BMP085 I2C Pressure sensor

from webiopi import deviceInstance


bmp = deviceInstance("bmp") # retrieve device named "bmp" in configuration file

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

name : device name from configuration file

Python example
from webiopi.devices.analog import TSL2561
tsl = TSL2561(...)

# setup a TSL2561 I2C Luminosity sensor

# 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

name : device name from configuration file

getCentimeter()
Returns the distance in millimeter.
REST API : GET /devices/name/sensor/distance/cm

name : device name from configuration file

getInch()
Returns the distance in millimeter.
REST API : GET /devices/name/sensor/distance/in

name : device name from configuration file

Python example
from webiopi.devices.analog import TSL2561
vcn = VCNL4000(...)

# setup a VCNL4000 I2C Luminosity sensor

# 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

You might also like