Mar 31

RPIDOM et WebIOPi : 1-Wire

Il y a quelques temps, j’ai reçu une carte RPIDOM fabriquée par les français de YADOM. Cette carte apporte 2 éléments manquant au Raspberry Pi, à savoir un contrôleur 1-Wire et une horloge RTC. Par ailleurs, elle dispose de deux entrée de type TéléInfo, qui permet de se brancher à un compteur EDF pour la relève de la consommation instantanée.

Aujourd’hui, je vais vous présenter l’utilisation du contrôleur 1-Wire et comment s’en servir directement avec WebIOPi sans installation supplémentaire. La notice du RPIDOM nous recommande d’installer OWFS mais l’opération, bien que facile, peut encore être simplifiée. En effet, il est possible d’utiliser le contrôleur directement sans passer par OWFS, simplement en chargeant les modules adéquats sans installation supplémentaire.

$ sudo modprobe wire          # chargement du module 1-Wire principal
$ sudo modprobe w1_therm      # chargement du module capteur de température
$ sudo modprobe i2c_bcm2708   # chargement du module I2C principal
$ sudo modprobe ds2482        # chargement du module permettant d'utiliser le contrôleur

# enfin, on enregistre le pont sur l'interface I2C
# pour les Raspberry révision 1, il faut remplacer i2c-1 par i2c-0
$ echo ds2482 0x18 | sudo tee /sys/bus/i2c/devices/i2c-1/new_device

# si un capteur 1-Wire est branché, il devrait alors être detecté
$ cat /sys/bus/w1/devices/w1_bus_master1/w1_master_slaves
28-0000049c7a8d

# on peut alors lire la temperature
$ cat /sys/bus/w1/devices/28-0000049c7a8d/w1_slave
76 01 4b 46 7f ff 0a 10 79 : crc=79 YES
76 01 4b 46 7f ff 0a 10 79 t=23375

Il est tout a fait possible d’utiliser WebIOPi 0.6 pour lire la température en enregistrant le capteur dans le fichier de configuration /etc/webiopi/config :

...
[DEVICES]
...
rpidom-temp = DS18B20 slave:28-0000049c7a8d
...

Après redémarrage de WebIOPi, on peut voir la température dans le Devices Monitor, plutôt simple non ?

Libre à vous d’utiliser alors l’une des nombreuses API et bibliothèque de WebIOPi pour utiliser les composants branchés à l’interface 1-Wire. Tous les capteurs de température 1-Wire (DS18*) ainsi que le switch DS2408 sont déjà supportés par WebIOPi.

Il est possible de charger les modules au démarrage, via le fichier /etc/modules. Mais il faut pour l’instant enregister le pont sur le bus I2C à la main. Je vais regarder pour simplifier toute la démarche en l’intégrant directement dans WebIOPi.

Dans des prochains billets je parlerai de l’horloge RTC fournie, puis de la relève TéléInfo.

Mar 27

WebIOPi 0.6 brings the Pi to IoT

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.

Mar 04

WebIOPi in the MagPi : Cambot tutorial

For people who follow the MagPi, you certainly see my WebIOPi article in the two last issues. Unfortunately, my article has been cut in two parts, and the second part has just been published in the march issue.

In the article, I explain how to control a L293 H-Bridge connected to GPIOs using WebIOPi and few macros. Then, I give instructions to add a webcam stream inside the webpage. You will also find few tricks to use a Pi on a battery using a voltage regulator.

Assembling these stuff together allow to build a web remote controlled camera robot, a rover if you prefer.

You can find another article that uses WebIOPi with a Raspberry and an Arduino to build another rover. You can see the result in video :

Jan 08

WebIOPi 0.5.3 release

WebI0Pi 0.6 has been released, click here for details.

Happy new year every one, and Happy new WebIOPi version !

Here is the changelog for 0.5.3 :

  • Added board revision REST URI (submitted by Andreas Riegg)
  • Added encrypted passwd file to store credentials used for HTTP authentication
  • Added webiopi-passwd command-line program to generate passwd file
  • Moved demo to examples/custom folder, added examples/basic
  • Changed /dev/mem access to allow webiopi import without root privileges when not using GPIOs
  • Disabled update checker to avoid “Update available” link
  • Improved GPIO error handling
  • Fixed encoding issue with python 2.x giving a blank page
  • Fixed setup script

This version is available on both Google Code and PiStore. The WIKI will be updated in next days to explain few of new features.

Dec 22

WebIOPi on the PiStore !

Following the PiStore announcement, I submitted WebIOPi so you can now install it in one single click from the store. This is a new version (0.5.2), that includes few changes and fixes :

  • Fixed blank page and file handling when server start at boot
  • Improved macros handling to allow zero, one, or more args
  • Added server loop helper
  • Improved setup.sh for the PiStore
  • Added play.sh for the PiStore to open the browser

You can find it on the PiStore WebIOPi page, but you need to use the PiStore on the Pi to install it.

I’m working on the next 0.5.3 version which will be released on both Google Code and PiStore. For people who need the 0.5.2 release but think they cannot use the PiStore without a display, you can install tightvncserver on the Pi and VNC Viewer on your computer.

Nov 16

WebIOPi 0.5.1 release

Post update : 0.5 release has been updated by 0.5.1 to fix a setup issue.

Around 2000 downloads after the first WebIOPi release, I’m glad to present you the 0.5.1 release. It includes many internal changes to offer you a powerful and simplified tool :

  • New Features
    • REV 2 boards support
    • Added setup script to ease WebIOPi install
    • Use WebIOPi in your own Python scripts
    • Login/Password protection
    • Software PWM
    • Binary sequence output
  • Python Server & REST API
    • Usable as a library
    • Added Python 3 support
    • Removed RPi.GPIO library dependency
    • Improved security
    • Improved file serving
    • Improved REST API
    • Added ability to use custom REST macro
    • Added ability to output a single pulse
    • Added ability to output a binary sequence
    • Added software PWM
  • Javascript Library
    • Improved and simplified
    • Added ability to create custom buttons with one or two callbacks (mousedown and mouseup)
    • Added helpers for new REST functions (macro, pulse, sequence, PWM, …)
  • Other changes
    • PHP Server discontinued

Check the project page and the wiki to download it and get install instructions. Please use the official topic on the RaspberryPi forum to report issues.

Christmas wish list

Everything is done on my free-time, I have many ideas but I miss some things to go further. This is my wish list :

In order to make new cool things for WebIOPi, like SPI, I2C, Serial, Gertboard support

To build and distribute some cool, free, no-ad Android apps for your Raspberry

To distribute some cool, free, no-ad iOS apps for your Raspberry

If you like what I do, and want more free stuff, please encourage and help me with donations. Each Euro count, and all donations will be very much appreciated and be used for the RPi and Open community.




Oct 08

Development status and plans

WebIOPi and I are still alive ! I’m a little busy outside of Raspberry community, but still working on some cool stuffs to enhance your Pi experience ;)

I was waiting for the 0.4 release of the Python GPIO library to release a new WebIOPi version, but I’m facing new problems as I go further. For instance, with the development version of WebIOPi, you can write you’re own Python script and use all the WebIOPi features in one single line. It’s cool, but the possibilities given are limited by the GPIO library. So I decided to rewrite a part of the core in C. I will skip the 0.4 release to give you a powerful tool in November.

Right now, I’m working on two mobile applications, both on Android and iOS. I’m sure you will enjoy it, and I hope to submit them to Google and Apple at the end of October.

 

Aug 27

WebIOPi 0.3 release

Less than a week later, second release of WebIOPi !

No real visible changes, but many internal improvements, required to go further. UART, SPI, I2C support are not ready yet, but I will be able to do it more easily now. With PHP I’m still facing security issues and difficulties to make a great UART/SPI/I2C support. The easy way to achieve it with PHP requires another process in the background. As the Python version is already running background and standalonne, I decided to stop PHP version development with the next version. I will be fully focused on one single server to get new features quicker. Moreover, the Python version is more than 50% faster than the PHP one.

  • Fixed security issue in the Python server
  • Python server general improvements
  • Python server displays real IP
  • Allow PHP5 < 5.4 (Works on Debian wheezy)
  • Added update tracking
  • Refactored Javascript code to be used as a library
  • Changed IDs and CSS naming
  • Added expert app

Go to the project page to download it. I will go on vacation on my side ;)
Don’t forget the dedicated topic on the RaspberryPi Forum.