After 2 months of hard work on my free time, I’m glad to release WebIOPi 0.6, with new exciting features. Taking grade of Internet of Thing framework, it becomes the perfect swiss-knife to make connected things with the Raspberry Pi by providing consistent libraries and API. From Arduino-like scripts to a full UART/I2C/SPI support and CoAP transport, discover new functionalities :
Python script loading facility & Arduino-like GPIO library
The new Server configuration file allows to load customs Python scripts for advanced configuration or computation. You can write your scripts with an Arduino sketch-like format using setup/loop/destroy functions. Macro registering to the REST API has been simplified as it only requires to add @macro before each macro definition.
The included GPIO native library has been modified to allow Arduino-like syntax using digitalRead and digitalWrite functions. There is also a readPort and writePort to get or set all I/O with a single integer. You can also use setup/input/output functions for an RPi.GPIO-like syntax.
import webiopi
GPIO = webiopi.GPIO
LED = 25
# Called by WebIOPi at script loading
def setup():
GPIO.setFunction(LED, GPIO.OUT)
# Looped by WebIOPi
def loop():
value = not GPIO.digitalRead(LED)
GPIO.digitalWrite(LED, value)
webiopi.sleep(5)
# Called by WebIOPi at server shutdown
def destroy():
GPIO.setFunction(LED, GPIO.IN)
# A macro which says hello
@macro
def Hello(first, last):
return "Hello %s %s !" % (first, last)
Anyone should be able to use the included library without changing their habits and extend WebIOPi without worrying about the Server. As usual, make a POST to /macros/Hello/Eric,PTAK to call the macro !
UART, SPI, I2C and 1-Wire support
WebIOPi now supports all buses available on the Pi, using full Python custom lightweight drivers, compatible with both Python 2.7 and Python 3.2, including I2C, with no dependency ! You can use WebIOPi Python library in your scripts to use all buses with a generic bus abstraction written for the Pi. It gives a consistent way to use UART, I2C and SPI with same readByte, writeByte and other clear functions. WebIOPi also supports more than 30 devices natively, including most used DAC, ADC, GPIO expander and sensors. Based on a common device abstraction layer and REST mapping, it gives a consistent way to access electronic components wired to the Pi. You will found for instance, analogRead, analogWrite, pwmRead, pwmWrite, and many other clear functions.
# Analog package contains ADC, DAC, PWM drivers
from webiopi.devices.analog import MCP3008, ADS1015, MCP4922, MCP4725
# Digital package contains GPIO expanders
from webiopi.devices.digital import MCP23017
# Sensor package contains several Temperature, Luminosity and Pressure sensors
from webiopi.devices.sensor import BMP085, DS18B20
# Setup SPI analog components
adc0 = MCP3008(chip=0) # MCP CS wired to Pi CE0
dac0 = MCP4922(chip=1) # MCP CS wired to Pi CE1
# Setup I2C analog components
adc1 = ADS1015(slave=0x40)
dac1 = MCP4725(slave=0x62)
# Setup I2C GPIO expander
gpio1 = MCP23017(slave=0x20)
# Setup sensors
tmp = DS18B20()
bmp = BMP085()
# Output HIGH on GPIO expander channel 0
gpio1.setFunction(0, GPIO.OUT)
gpio1.digitalWrite(0, GPIO.HIGH)
# Read ADC
print adc0.analogRead(0) # Channel 0 as integer
print adc0.analogReadFloat(1) # Channel 1 as float (0.0 to 1.0)
print adc0.analogReadVolt(2) # Channel 2 as volt
# Write on DAC
dac0.analogWrite(0, 1023) # Output 100% on Channel 0
dac0.analogWriteFloat(0, 0.5) # Output 50% on Channel 0
dac0.analogWriteVolt(0, 3.3) # Output 3.3V on Channel 0
# Retrieve sensor data
print tmp.getCelsius()
print bmp.getCelsius()
print bmp.getHectoPascal()
You can use the webiopi devices library in your own Python script or register devices in the WebIOPi Server configuration file then access them through the REST API.
HTTP GET /devices/adc0/analog/0/float
HTTP POST /devices/dac0/analog/0/float/1.0
HTTP GET /devices/gpio0/0/value
HTTP GET /devices/gpio0/0/function
HTTP POST /devices/gpio0/0/value/1
HTTP GET /devices/tmp/sensor/temperature/c
HTTP GET /devices/bmp/sensor/temperature/f
HTTP GET /devices/bmp/sensor/pressure/hpa
The project wiki will be updated soon with all new functions and REST bindings.
CoAP support
CoAP is an ongoing IETF lightweight protocol build on top of UDP to use REST services with constrained devices. It can decrease webiopi requests latency by 3 and allows multicasting. With HTTP, controling several devices requires to make a request to each devices. With UDP multicasting you can control many devices with a single request in a single frame sent from a Client. Depending on network topology, it even allows to synchronize outputs. Adding this in WebIOPi gives Internet of Things and Machine-to-Machine capabilities to the Raspberry Pi. I’ve added a CoAP Client Python library, which is near HttpClient in use :
from webiopi.protocols.coap import *
client = COAPClient()
client.sendRequest(COAPPost("coap://raspberrypi/GPIO/25/function/out"))
client.sendRequest(COAPPost("coap://raspberrypi/GPIO/25/value/1"))
client.sendRequest(COAPGet("coap://raspberrypi/devices/tmp/sensor/temperature/c"))
I’ve also open sourced a Java CoAP client, you can found on Google Code. Instead of using any HTTP or CoAP client, I suggest to use one of the following webiopi client libraries.
Python and Java WebIOPi Client libraries
Using WebIOPi from the browser is easy, but using it from an application is now easy as well. Just like the Javascript library, you can use the Python and Java Client libraries to make anything-to-Pi or Pi-to-Pi communication. Python and Java libraries provide both HTTP and CoAP WebIOPi Clients, and also a Mixed one, which uses CoAP with a HTTP fallback.
from webiopi.clients import *
from time import sleep
# Create a WebIOPi client
client = PiHttpClient("raspberrypi")
#client = PiMixedClient("raspberrypi")
#client = PiCoapClient("raspberrypi")
#client = PiMulticastClient()
client.setCredentials("webiopi", "raspberry")
# RPi native GPIO
gpio = NativeGPIO(client)
gpio.setFunction(25, "out")
state = True
# DAC named "dac1"
dac = DAC(client, "dac1")
# ADC named "adc1"
adc = ADC(client, "adc1")
value = 0.0
# Temperature sensor named "temp0"
temp = Temperature(client, "temp0")
while True:
# toggle digital state
state = not state
gpio.digitalWrite(25, state)
# increase analog value
value += 0.01
if value > 1.0:
value = 0.0
dac.writeFloat(0, value)
# DAC output 0 is wired to ADC input 1
val = adc.readFloat(1)
print("Analog = %.2f" % val)
# Retrieve temperature
t = temp.getCelsius()
print("Temperature = %.2f Celsius" % t)
sleep(1)
Python is perfect for custom Pi-to-Pi communication, when Java will suit Android needs.
Serial Monitor Web App
The Serial bus can be directly mapped to the REST API allowing raw use of any UART (native or USB) through the REST API. I’ve added a Serial Monitor Web App to quickly debug any UART device from a browser.

Devices Monitor Web App
All devices supported by WebIOPi inherit from generic classes, providing a full mapping from the Python native library to the clients library through the REST API. With the Devices Monitor you can quickly try them with a browser.

Others changes and upcoming work
There is also several bug fix and improvements, you can check the changelog for the complete list of changes. Also check the project page for more documentation and downloads.
I would like to thanks the community from the WebIOPi Group, particularly Andreas for his feedbacks and for writing few sensor drivers.
Next developments will focus on real-time features with interrupt handling and server push. I also plan to add more devices on the support list, including several expansion boards, Pi-Face and RPIDOM first.
If you like what has be done, don’t forget I do it on my free time. Feel free to support me if you want something even better.
Eric / trouch.