doc webiopi

35
7/21/2019 Doc Webiopi http://slidepdf.com/reader/full/doc-webiopi 1/35 La API RESTincluido le permite hacer es el propietario del cliente, mediante llamadas HTTPREST. Ustedpuede usarlo para lograr varias tareas: Los errores devueltos por el WebAPI soncomprensibles cuandola llamada HTTPnoes válido: 400 BadRequest (ruta incompleta) 403GPIO# No disponible 403 GPIO# discapacitados 404 [algo] noencontrado Obtener función GPIO Get GPIOfunction HTTPGET/GPIO/(gpioNumber)/function o Returns "in" or "out" Example : o To get GPIO0 function: HTTPGET/GPIO/0/function HTTP GET / / función GPIO / (gpioNumber) o Devoluciones "en" o "fuera" Eemplo! o Para obener GPIO # $unción! HTTP GET / GPIO / # / función o Set GPIOfunction HTTPPOST/GPIO/(gpioNumber)/function/("in" or "out" or "pwm")

Upload: encor

Post on 05-Mar-2016

79 views

Category:

Documents


2 download

DESCRIPTION

Manual de configuracion webiopi

TRANSCRIPT

Page 1: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 1/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

válido:

• 400 Bad Request (ruta incompleta)

• 403 GPIO # No disponible

• 403 GPIO # discapacitados

404[algo] no encontrado

Obtener función GPIO

Get GPIO function

• HTTP GET /GPIO/(gpioNumber)/function

o Returns "in" or "out"

• Example :

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

• HTTP GET / / función GPIO / (gpioNumber)

o Devoluciones "en" o "fuera"

• Eemplo!

o Para obener GPIO # $unción! HTTP GET / GPIO / # / función

o

Set GPIO function

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

Page 2: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 2/35

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

• Examples:

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

o 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

o 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

Page 3: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 3/35

• 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

Page 4: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 4/35

• HTTP GET /*

o Returns full GPIO state in JSON :

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

o "0": {"function": "I", "!alu": 1#,

o "1": {"function": "I", "!alu": 1#,

o "2": {"function": "A$T0", "!alu": 1#,

o "%": {"function": "A$T0", "!alu": 1#,

o "&": {"function": "I", "!alu": 0#,

o "'": {"function": "A$T0", "!alu": 0#,

o "(": {"function": "OUT", "!alu": 1#,

o )))

o "'%": {"function": "A$T%", "!alu": 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.

Page 5: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 5/35

CSS stylingOnce 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.

Pinstate buttons (LOW/HIGH) are HTML+utton, and inherit thebutton CSS style.

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

Pinfunction buttons (IN/OUT/...) are also HTML+utton, withid

fromfunction0 tofunction53. Two classes are also used :

• .FunctionBasic : Used when GPIO is Input or Output

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

Pindescriptions are made of HTML div, withid fromname0 toname53, with a single

class :

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

Page 6: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 6/35

You can use the included Javascript library to build your own interface.

ExampleThis 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 Trat#al//E$""htt%&//'''.'3.#r(/T)/html4/l##*.+t+",

-t.l

-a/

  .ta -ttui!3"ContntT4" contnt3"t5t6-t.l7 c-a89t3UT;"

  .ta na.3"!i<o8t" contnt 3 "-ig-t 3 /!ic-ig-t, <i/t- 3 &20, u989cala+l 3 no" 6 

titl=+IOPi > ?.o6titl

  9c8it t43"t5t6@a!a9c8it" 98c3"6<+ioi)@9"69c8it

  9c8it t43"t5t6@a!a9c8it"

  <+ioiB)8a/4t#B {

  ar contnt, +utton7

  contnt 3 "Dcontnt"B7

   // create a "SWITCH" labeled button for GPIO 0

  +utton 3 <+ioiB)c8atGPIOEutton0, "S=ITCF"B7

  contnt)an/+uttonB7 // append button to content div 

   // create a "LED" labeled button for GPIO

  +utton 3 <+ioiB)c8atGPIOEutton, "$H?"B7

  contnt)an/+uttonB7 // append button to content div 

   // create a button t!at output a in#le pule

  +utton 3 <+ioiB)c8atPul9Eutton"ul9", "Pul9", B7

  contnt)an/+uttonB7 // append button to content div 

   // create a button $!ic! output a bit e%uence on GPIO $it! a &00' period

+utton 3 <+ioiB)c8atSuncEutton"9o9", "S)O)S 1", , 100,

"01010100110011001100101010"B7

Page 7: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 7/35

  contnt)an/+uttonB7 // append button to content div 

   // t!e previou button $ill al$a( output t!e a'e e%uence

   // (ou can alo create a i'ple button $it! (our o$n function

+utton 3 <+ioiB)c8atEutton"9o92", "S)O)S 2", oututSuncB7

  contnt)an/+uttonB7 // append button to content div 

   // create a button $!ic! call '()acroWit!out*r#

  +utton 3 <+ioiB)c8atac8oEutton".ac8o", "ac8o 1",".4ac8o=it-outA8g9"B7

  contnt)an/+uttonB7 // append button to content div 

   // create a button $!ic! call '()acroWit!*r# $it! "&+,+-" a ar#u'ent 

  +utton 3 <+ioiB)c8atac8oEutton".ac8o", "ac8o 2",".4ac8o=it-A8g9", [1,2,%]B7

  contnt)an/+uttonB7 // append button to content div 

   // t!e previou button $ill al$a( call '()acroWit!*r# $it! t!e a'e "&+,+-"ar#u'ent 

   // (ou can alo create a i'ple button $it! (our o$n function

+utton 3 <+ioiB)c8atEutton".ac8o2", "ac8o %", callac8oB7

  contnt)an/+uttonB7 // append button to content div 

   // (ou can alo create a button $!ic! call a di.erent function for 'oue do$nand up event

  +utton 3 <+ioiB)c8atEutton"-ol/", "Fol/", .ou9/o<n, .ou9uB7

  contnt)an/+uttonB7

   // Onl( for C!ro'e and Safari+ create a lider t!at pule out a 0&00 dut(c(cle ratio on GPIO 1

  +utton 3 <+ioiB)c8atRatioSli/8;B7

  contnt)an/+uttonB7

   // Onl( for C!ro'e and Safari+ create a lider t!at pule out a 23 to 4235an#le on GPIO 6

  +utton 3 <+ioiB)c8atAnglSli/8JB7

  contnt)an/+uttonB7

  #B7

Page 8: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 8/35

  t# m#*+#'B {

  <+ioiB)/igital=8it, 1B7

  #

  t# m#*%B {

  <+ioiB)/igital=8it, 0B7

  #

  t# #t%t*2**B {

  ar 9unc 3 "01010100110011001100101010"  // S7O7S7 'ore code or$!atever (ou $ant 

   // output e%uence on #pio $it! a &00' period

  <+ioiB)oututSunc, 100, 9unc, 9uncCall+acKB7

  #

  t# *2**Calla gio, /ataB {

  al8t"9unc on " L gio L " Mni9-/ <it- " L /ataB7

  #

  t# allMar#B {

  ar a8g9 3 [1,2,%] // or $!atever (ou $ant 

   // call '()acroWit!*r#8ar#9

  <+ioiB)callac8o".4ac8o=it-A8g9", a8g9, .ac8oCall+acKB7

  #

  t# mar#Calla .ac8o, a8g9, /ataB {

  al8t.ac8o L " 8tu8n/ <it- " L /ataB7

  #

  69c8it

  9t4l t43"t5t6c99"

  +utton {

  /i9la4: +locK7

  .a8gin: '5 '5 '5 '57

  <i/t-: 1(057

Page 9: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 9/35

  -ig-t: &'57

  font9iN: 2&t7

  font<ig-t: +ol/7

  colo8: +lacK7

  #

  inut[t43"8ang"] {

  /i9la4: +locK7

  <i/t-: 1(057

  -ig-t: &'57

  #

  5(%#6)$O= {

  +acKg8oun/colo8: =-it7

  #

  5(%#6)FIGF {

  +acKg8oun/colo8: R/7

  #

  69t4l

6-a/

+o/4

  /i! i/3"contnt" align3"cnt8"6/i!

6+o/4

6-t.l

Page 10: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 10/35

Function detailswebiopi()

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.

Page 11: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 11/35

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

Page 12: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 12/35

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

Page 13: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 13/35

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

Page 14: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 14/35

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

Page 15: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 15/35

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

Page 16: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 16/35

Digital package provides drivers for GPIO expanders.

GPIOPortSummary

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

Page 17: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 17/35

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.

Page 18: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 18/35

• 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

Page 19: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 19/35

Python example

fo8. <+ioi)/!ic9)/igital i.o8t CP2%00;

.c 3 CP2%00;...B : etup a )CP,-001 I,C GPIO e;pander 

: or 

f8o. <+ioi i.o8t /!icIn9tanc

.c 3 /!icIn9tanc".c"B : retrieve device na'ed "'cp" in con<#uration<le

.c)gtunction0B : #et current )CP di#ital c!annel 0 etup

.c)9tunction0, GPIO)OUTB : etup )CP di#ital c!annel 0 a output 

.c)9tunction1, GPIO)OUTB : etup )CP di#ital c!annel & a output 

.c)9tunction2, GPIO)OUTB : etup )CP di#ital c!annel , a output 

.c)9tunction%, GPIO)OUTB : etup )CP di#ital c!annel - a output 

.c)/igitalRa/&B : read )CP di#ital c!annel 0

.c)/igital=8it&, GPIO)FIGFB : $rite )CP di#ital c!annel 2 a HIGH

.c)o8t=8it050B : $rite c!annel 0- a HIGH

.c)o8tRa/B : read all )CP di#ital c!annel in a in#le inte#er 

REST example

FTTP GHT 6/!ic96.c606function D 8t8i! ".c" c-annl 0 9tu

FTTP GHT 6/!ic96.c606!alu D 8t8i! ".c" c-annl 0 /igital !alu

FTTP POST 6/!ic96.c606function6out D 9t ".c" c-annl 0 a outut

FTTP POST 6/!ic96.c606!alu61  D 9t ".c" c-annl 0 a /igital FIGF

Page 20: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 20/35

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

Page 21: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 21/35

• 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

Page 22: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 22/35

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

f8o. <+ioi i.o8t /!icIn9tanc

f8o. <+ioi)/!ic9)analog i.o8t A?S101', CP%20;

a/9 3 A?S101'...B : etup a *DS&0&3 I,C *DC

: or 

a/9 3 /!icIn9tanc"a/9"B : retrieve device na'ed "ad" in con<#uration <le

a/9)analogCountB : return *DS&0&3 analo# c!annel count 

a/9)analoga5i.u.B : return *DS&0&3 'a;i'u' inte#er value

a/9)analogRa/0B : return *DS&0&3 analo# c!annel 0 a inte#er 

a/9)analogRa/loat0B : return *DS&0&3 analo# c!annel 0 a =oat 

a/9)analogRa/olt0B : return *DS&0&3 analo# c!annel 0 a volt 

.c 3 CP%20;...B : etup a )CP-,01 SPI *DC

.c)analogCountB : return )CP-,01 analo# c!annel count 

Page 23: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 23/35

.c)analoga5i.u.B : return )CP-,01 'a;i'u' inte#er value

.c)analogRa/0B : return )CP-,01 analo# c!annel 0 a inte#er 

.c)analogRa/loat0B : return )CP-,01 analo# c!annel 0 a =oat 

.c)analogRa/olt0B : return )CP-,01 analo# c!annel 0 a volt 

REST example

FTTP GHT 6/!ic96a/96analog606intg8 D 8tu8n9 "a/9" analog c-annl 0 a intg8

FTTP GHT 6/!ic96a/96analog606oat D 8tu8n9 "a/9" analog c-annl 0 a oat

FTTP GHT 6/!ic96a/96analog606!olt D 8tu8n9 "a/9" analog c-annl 0 a !olt

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

Page 24: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 24/35

• 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

f8o. <+ioi)/!ic9)analog i.o8t CP&2'

.c 3 CP&2'...B : etup a )CP2,3 I,C D*C

.c)analogCountB : return )CP2,3 analo# c!annel count 

.a5 3 .c)analoga5i.u.B : return )CP2,3 'a;i'u' inte#er value

.c)analog=8it0, .a5B : et &00 on )CP2,3 analo# c!annel 0

.c)analog=8itloat0, 0)'B : et 30 on )CP2,3 analo# c!annel 0

.c)analog=8itolt0, 0)0B : et 0> on )CP2,3 analo# c!annel 0

.c)analogRa/0B : return )CP2,3 analo# c!annel 0 a inte#er 

.c)analogRa/loat0B : return )CP2,3 analo# c!annel 0 a =oat 

.c)analogRa/olt0B : return )CP2,3 analo# c!annel 0 a volt 

Page 25: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 25/35

REST example

FTTP POST 6/!ic96.c6analog606intg860  D 9n/ 0 to ".c" analog c-annl 0

FTTP POST 6/!ic96.c6analog606oat60)0  D 9n/ 0 to ".c" analog c-annl 0

FTTP POST 6/!ic96.c6analog606!olt60)0  D 9n/ 0 to ".c" analog c-annl 0

FTTP GHT 6/!ic96.c6analog606intg8 D 8tu8n9 ".c" analog c-annl 0 a intg8

FTTP GHT 6/!ic96.c6analog606oat D 8tu8n9 ".c" analog c-annl 0 a oat

FTTP GHT 6/!ic96.c6analog606!olt D 8tu8n9 ".c" analog c-annl 0 a !olt

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

Page 26: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 26/35

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

Page 27: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 27/35

• 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

Page 28: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 28/35

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

f8o. <+ioi i.o8t /!icIn9tanc

f8o. <+ioi)/!ic9)analog i.o8t PCAJ(;'

ca 3 PCAJ(;'...B : etup a PC*6?13 I,C PW)

: or 

ca 3 /!icIn9tanc"ca"B : retrieve device na'ed "pca" in con<#uration <le

ca)<.CountB : return PC*6?13 p$' c!annel count 

.a5 3 ca)<.a5i.u.B : return PC*6?13 'a;i'u' inte#er value

ca)<.=8it0, .a5B : et &00 on PC*6?13 p$' c!annel 0 8inte#er value9

ca)<.=8itloat0, 0)'B : et 30 on PC*6?13 p$' c!annel 0 8=oat value9

Page 29: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 29/35

ca)<.=8itAngl0, 0)0B : et 05 on PC*6?13 p$' c!annel 0 8ervo an#levalue9

ca)<.Ra/0B : return PC*6?13 p$' c!annel 0 a inte#er 

ca)<.Ra/loat0B : return PC*6?13 p$' c!annel 0 a =oat 

ca)<.Ra/Angl0B : return PC*6?13 p$' c!annel 0 a an#le

REST example

FTTP POST 6/!ic96ca6<.606intg860 D *t 0Q # "ca" <. c-annl 0 intg8 al*B

FTTP POST 6/!ic96ca6<.606oat60)0  D *t 0Q # "ca" <. c-annl 0 oat al*B

FTTP POST 6/!ic96ca6<.606angl60)0  D *t 0 # "ca" <. c-annl 0 98!oangl al*B

FTTP 7ET  6/!ic96ca6<.606intg8  D r*tr "ca" <. c-annl 0 a intg8

FTTP 7ET  6/!ic96ca6<.606oat  D r*tr "ca" <. c-annl 0 a oat

FTTP 7ET  6/!ic96ca6<.606angl D r*tr "ca" <. c-annl 0 a 98!oangl

Page 30: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 30/35

Sensor package provides drivers for various sensors.

TemperatureSummary

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.

Page 31: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 31/35

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

• name : device name from configuration file

Python examplef8o. <+ioi)/!ic9)analog i.o8t TP102

t. 3 TP102...B : etup a T)P&0, I,C Te'perature enor 

: or 

f8o. <+ioi i.o8t /!icIn9tanc

t. 3 /!icIn9tanc"t."B : retrieve device na'ed "t'p" in con<#uration <le

t.)gtl!inB

t.)gtCl9iu9B

t.)gta-8n-itB

REST example

FTTP GHT 6/!ic96t.69n9o86t.8atu86K

FTTP GHT 6/!ic96t.69n9o86t.8atu86c

FTTP GHT 6/!ic96t.69n9o86t.8atu86f 

Pressure

Summary

Pressure interface provides functions to read atmospheric pressure.

Supported devices

• BMP085 (I2C)

Page 32: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 32/35

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

f8o. <+ioi)/!ic9)analog i.o8t EP0;'

+. 3 EP0;'...B : etup a @)P013 I,C Preure enor 

: or 

Page 33: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 33/35

f8o. <+ioi i.o8t /!icIn9tanc

+. 3 /!icIn9tanc"+."B : retrieve device na'ed "b'p" in con<#uration <le

+.)gtFctoPa9calB

+.)gtFctoPa9calAtSaB

REST example

FTTP GHT 6/!ic96+.69n9o86899u86-a

FTTP GHT 6/!ic96+.69n9o86899u869a6-a

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

Page 34: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 34/35

Python example

f8o. <+ioi)/!ic9)analog i.o8t TS$2'(1

t9l 3 TS$2'(1...B : etup a TSL,3?& I,C Lu'inoit( enor 

: or 

f8o. <+ioi i.o8t /!icIn9tanc

t9l 3 /!icIn9tanc"t9l"B : retrieve device na'ed "tl" in con<#uration <le

t9l)gt$u5B

REST exampleFTTP GHT 6/!ic96t.69n9o86lu.ino9it46l5

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

Page 35: Doc Webiopi

7/21/2019 Doc Webiopi

http://slidepdf.com/reader/full/doc-webiopi 35/35

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

f8o. <+ioi)/!ic9)analog i.o8t TS$2'(1

!cn 3 C$&000...B : etup a >CAL2000 I,C Lu'inoit( enor 

: or 

f8o. <+ioi i.o8t /!icIn9tanc

!cn 3 /!icIn9tanc"!cn"B : retrieve device na'ed "vcn" in con<#uration <le

!cn)gtilli.t8B

REST example

FTTP GHT 6/!ic96t.69n9o86/i9tanc6..