REST API
This document defines the REST API. By and large, this follows the WebIOpi REST interface:
https://code.google.com/p/webiopi/wiki/INSTALL?tm=6
There are a few notable differences, mostly to account for being on more than just the Rapsberry Pi. For instance, the pcDuino has different voltage and bit resolutions for some of its ADC and PWM channels, so the API to access that data must specify a pin.
Specific differences are noted as "COMPATIBILITY NOTE" below.
Status Codes
Just a few of the HTTP status codes you might expect to hit.
400 Bad Request (path incomplete) 403 GPIO # Not Available 403 GPIO # Disabled 404 [something] Not Found
BASIC
GET /map
Returns a JSON list, with each entry corresponding to a pin on the physical header. Each entry can be:
Some number (corresponding to a GPIO number)
"V33" (3.3 volt power)
"V50" (5.0 volt power)
"GND" (ground)
Example:
["V33", "V50", 2, "V50", 3, "GND", 4, 14, "GND", 15, 17, 18, 27, "GND", 22, 23, "V33", 24, 10, "GND", 9, 25, 11, 8, "GND", 7]
GET /*
Returns a JSON of available interfaces. Keys:
UART [bool]
SPI [bool]
I2C [bool]
ONEWIRE [bool]
GPIO [object]
GPIO's keys are numbers mapping to each GPIO pin. The values are objects containing:
function ["IN", "OUT", "ALTn" (where n is some number)]
value [bool]
Example:
{
"UART": 1,
"SPI": 0,
"I2C": 0,
"ONEWIRE": 0,
"GPIO": {
"0": {"function": "IN", "value": 1},
"1": {"function": "IN", "value": 1},
"2": {"function": "IN", "value": 1},
"3": {"function": "IN", "value": 1},
"4": {"function": "IN", "value": 1},
"5": {"function": "IN", "value": 1},
"6": {"function": "IN", "value": 1},
"7": {"function": "ALT0", "value": 1},
"8": {"function": "ALT0", "value": 1},
"9": {"function": "ALT0", "value": 0},
"10": {"function": "ALT0", "value": 0}, "11": {"function": "ALT0", "value": 0}, "12": {"function": "IN", "value": 0}, "13": {"function": "IN", "value": 0}, "14": {"function": "ALT0", "value": 1}, "15": {"function": "ALT0", "value": 1}, "16": {"function": "IN", "value": 0}, "17": {"function": "IN", "value": 0}, "18": {"function": "IN", "value": 0}, "19": {"function": "IN", "value": 0}, "20": {"function": "IN", "value": 0}, "21": {"function": "IN", "value": 0}, "22": {"function": "IN", "value": 0}, "23": {"function": "IN", "value": 0}, "24": {"function": "IN", "value": 0}, "25": {"function": "IN", "value": 0}, "26": {"function": "IN", "value": 0}, "27": {"function": "IN", "value": 0}, "28": {"function": "IN", "value": 1}, "29": {"function": "IN", "value": 1}, "30": {"function": "IN", "value": 0}, "31": {"function": "OUT", "value": 1}, "32": {"function": "OUT", "value": 0}, "33": {"function": "IN", "value": 0}, "34": {"function": "IN", "value": 1}, "35": {"function": "IN", "value": 1}, "36": {"function": "IN", "value": 1}, "37": {"function": "IN", "value": 0}, "38": {"function": "OUT", "value": 0}, "39": {"function": "IN", "value": 0}, "40": {"function": "ALT0", "value": 0}, "41": {"function": "OUT", "value": 0}, "42": {"function": "IN", "value": 0}, "43": {"function": "IN", "value": 0}, "44": {"function": "ALT0", "value": 1}, "45": {"function": "ALT0", "value": 0}, "46": {"function": "IN", "value": 1}, "47": {"function": "OUT", "value": 0}, "48": {"function": "ALT3", "value": 1}, "49": {"function": "ALT3", "value": 1}, "50": {"function": "ALT3", "value": 1}, "51": {"function": "ALT3", "value": 1}, "52": {"function": "ALT3", "value": 1}, "53": {"function": "ALT3", "value": 1}}}
GPIO
GET /devices/[name]/count
Returns the digital channel count
GET /devices/[name]/[channel]/value
Returns the value of the given digital channel
GET /devices/[name]/*/value
Returns a list of values of all digital channels
(Return as CSV list?)
(COMPATIBILITY NOTE: This is in the WebIOpi docs as POST)
POST /devices/[name]/[channel]/value/[digit]
Sets the value of the digital channel
GET /devices/[name]/*/integer
Return an integer of all digital bits
POST /devices/[name]/*/integer/[value]
Write an integer for all digital bits
GET /devices/[name]/[channel]/function
Returns the current function of the given channel ("IN" or "OUT"(?))
POST /devices/[name]/[channel]/function/[func]
Sets the function of the given digital channel.
setFunctionString()
(COMPATIBILITY NOTE: This is in the WebIOpi docs as GET)
GET /devices/[name]/*
Returns a list containing the value and function of all digital channels.
(Return as CSV list?)
ADC (Analog-to-Digital Converter)
GET /devices/[name]/analog/count
(NOTE: Redundant listings in WebIOpi docs for analogCount and analogResolution)
GET /devices/[name]/analog/maximum
DEPRECATED. Return the maximum integer value of channel 0.
This is retained for compatibility with the original WebIOPi. Since different pins can have different values, you should use the version that specifies a pin instead.
GET /devices/[name]/analog/[channel]/maximum
Return the maximum integer value of the given channel.
analogMaximum()
GET /devices/[name]/analog/integer/vref
DEPRECATED. Return the voltage reference of channel 0.
This is retained for compatibility with the original WebIOPi. Since different pins can have different values, you should use the version that specifies a pin instead.
GET /devices/[name]/analog/[channel]/integer/vref
Return the voltage reference of the given channel.
analogReference()
GET /devices/[name]/analog/[channel]/integer
GET /devices/[name]/analog/[channel]/float
GET /devices/[name]/analog/[channel]/volt
GET /devices/[name]/analog/*/integer
analogReadAll()
(list returned as CSV?)
GET /devices/[name]/analog/*/float
(list returned as CSV?)
DAC (Digital-to-Analog Converter)
Extends ADC interface
POST /devices/[name]/analog/[channel]/integer/[value]
POST /devices/[name]/analog/[channel]/float/[value]
POST /devices/[name]/analog/[channel]/volt/[value]
PWM (Pulse Width Modulation)
GET /devices/[name]/pwm/count
GET /devices/[name]/pwm/resolution
DEPRECATED. Return the PWM resolution of channel 0.
This is retained for compatibility with the original WebIOPi. Since different pins can have different values, you should use the version that specifies a pin instead.
GET /devices/[name]/pwm/[channel]/resolution
Return the PWM resolution of the given channel.
pwmResolution()
GET /devices/[name]/pwm/maximum
DEPRECATED. Return the PWM maximum integer value of channel 0.
This is retained for compatibility with the original WebIOPi. Since different pins can have different values, you should use the version that specifies a pin instead.
GET /devices/[name]/pwm/[channel]/maximum
Return the PWM maximum integer value of the given channel.
pwmMaximum()
(COMPATIBILITY NOTE: WebIOpi does not use channel argument)
POST /devices/[name]/pwm/[channel]/integer/[value]
POST /devices/[name]/pwm/[channel]/float/[value]
POST /devices/[name]/pwm/[channel]/angle/[value]
GET /devices/[name]/pwm/[channel]/integer
GET /devices/[name]/pwm/[channel]/float
GET /devices/[name]/pwm/[channel]/angle
GET /devices/[name]/pwm/*/integer
GET /devices/[name]/pwm/*/float
GET /devices/[name]/pwm/*/angle
GET /devices/[name]/pwm/*
VideoStream
COMPATIBILITY NOTE: This is an extension which is not currently implemented in WebIOPi
GET /devices/[name]/video/count
Returns the number of video streams that are available.
GET /devices/[name]/video/[channel]/resolution
Returns the width and height separated by an x list, followed by a p, followed the fps. Example:
640x480p60
POST /devices/[name]/video/[channel]/resolution/[width]/[height]/[fps]
Sets the resolution and frame rate of the given channel.
If the channel refuses to set the given resolution, HTTP status code 403 will be sent.
GET /devices/[name]/video/[channel]/kbps
Get the current bitrate, as an integer in kb per second.
POST /devices/[name]/video/[channel]/kbps/[value]
Set the current bitrate. [value]
is an integer in kb per second.
GET /devices/[name]/video/[channel]/allowed-content-types
Get list of allowed MIME content types. Allowed types will be sent as a MIME string, with one on each line.
GET /devices/[name]/video/[channel]/stream/[content-type1]/[content-type2]
Get the video stream with the desired content type.
NOTE: [content-type1]/[content-type2] is really just a straight MIME type, like "text/video". It's split up this way for the sake of popular server-side web libraries.
SPI
I2C
OneWire
Pressure
Luminosity
Distance
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 321:
'=end' without a target?