Stay tuned for hot stuffs !
Raspberry Pi Networking Cookbook is a new book from Packt Publishing. It aims to give a complete set of instructions to use your Pi as personal server.
The first chapter covers the usual Raspberry Pi presentation with requirements and instructions to boot the Pi for the first time and make basic configuration. Most people who already own and use a Raspberry Pi can skip this chapter. But a quick read is a good thing to remind few facts about the Pi and its possibilities.
In the second chapter, the reader learns how to connect to Pi using SSH. It’s nice to see examples from both Windows and Unix systems. It even covers the case of Raspberry reinstallation, when SSH does not recognize previous Raspberry SSH key. The chapter three then gives many basic Debian-based system (like Raspbian) tips to maintain the system, install and update packages.
Storage is completely covered in the chapter four. From adding USB or network storage, to making network sharing, this chapter give precise a concise instructions. This is very welcome for people who don’t Linux well because the Pi can definitely lacks of storage space. Then, with it’s low power consumption, the Pi is a good choice for a low cost file server. This allows to easy share between devices of your home network, very useful today with all those connecting things we can have at home : computers, tablet, phones, media players, tv… The only bad point is that only SAMBA network sharing is presented. FTP and and AFP (Apple/Mac) are both requirements on my side and for many users.
Finally, the fifth and last chapter explains few advanced setup and configuration :
- Firewall setup and configuration, to protect your Pi from unauthorized access
- RDP and VNC configuration, to remote graphically access your Pi Desktop
- HTTP server with Apache, lighttpd, nginx
- MediaWiki setup
- Wireless Access Point
With all the features covered in this book, it’s a very good choice for people who don’t know where to start to use their Raspberry as a server. This is basically a set of commons Linux/Debian tasks, compiled into a single book.
There is one thing which disturbed me, a screen is required for the first steps of this book. In my mind, using a Pi as a server means never plug it to a display. On my side, I NEVER plugged any display to my Raspberry Pis since I’ve got one. First, SSH access is enabled by default on Raspbian since a while. Secondly, we can found the Raspberry network address using one of many network scanner. I really like Fing, which is freely available on Windows, Mac, Linux, iOS and Android. This two tips are enough to use the Pi from the setup without any display plugged in.
Then, I think two setup are missing : DHCP and DNS server, with DNSmasq for example. Most of home routers do not provide a decent DHCP server or local DNS and the Pi is a perfect candidate to do that, thanks of its low power consumption. This is a really advanced features, and most people can afford with their existing setup.
I really liked all links and sources to the software used in the book. With all clear instructions and informations given, anyone should be able to build the perfect server for their need using a Raspberry Pi, low cost and low energy.
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.
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 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
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
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.
Raspberry Pi Home Automation with Arduino is a book written by Andrew K. Dennis, and edited by Packt. With this book, the reader learns how to achieve automation tasks using a Raspberry Pi coupled with an Arduino.
After the classical Raspberry / Linux setup and requirements, the book covers several commons task in home automation :
- Thermometer, to retrieve temperatures from several sensors
- Thermostat, to control an heating system by switching relays based on Thermometer project
- Data Storage, to log temperatures
- Curtain Automation, based on an ambiant sensor and motor control
Finally, the book give few tips to help prototyping with Raspberry Pi.
All the book relies on the Cooking-Hacks RPi-to-Arduino bridge shield. All hardware stuff use the Arduino instead of directly use GPIO. As you will notice with upcoming WebIOPi 0.6, we can use GPIO to make many things, quite easily. We can connect sensors and also control motors without using many devices.
The RPi-to-Arduino bridge and so the book also require the arduPi firmware for the Arduino. In my opinion, the book is more about learning the bridge and arduPi firmware than learning all Raspberry Pi possibilities.
When the reader knows that, I have to admit the book is well written, with good explanations and code snippets. Moreover, using an Arduino with a Raspberry Pi is one of the best combo and a must have for any hobbyist geek and prototype builder. I say that to my friends and co-workers since the Raspberry Pi has been released. It gives the Pi missing hardware PWM output and Analog input with a single extension.
With passing time, I now rather think that the Raspberry Pi should be directly used for many common things, only using a cheap ADC like Microchip MCP3000 series or TI ADS1000 ones. It simplifies the circuit, consumes less, and allow to learn more on electronic components and industrial uses. Arduino should come only to help the Pi in several time critical task. For instance, measuring a PWM signal or using a wheel encoder.
The book is well enough written to reuse explanations in other contexts, and replacing the Arduino with something else should be easy as we can found many explanation on Internet. The Raspberry Pi forum and the Mag Pi are good starts, there is also many hobbyist blogs. But reading components data sheets is more interesting, exciting and provides more precise information. Combining stuff from the book and Internet will providing a powerful set of stuff to unleash the Raspberry Pi power in your electronic projects.
Advanced hobbyist who are already familiar with data sheet reading and implementation should pass away this book.
Intermediate skilled people should get this book to frame their knowledge and lead them further.
Beginners and people who already have both Arduino and Raspberry, but still don’t know how to connect them together must purchase it with the Cooking-Hack bridge. It will ensure a success in your Home Automation projects and learn you many things.
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.
Few month ago, I’ve been asked to help writing a book as a technical reviewer about using the Raspberry Pi as a Media Center. The book is written by Sam Nazarko, the Raspbmc creator, and edited by PacktPub. With this, you will be able to use all the Pi power to make it a great Media Center by covering all features :
- Installation, configuration of Raspbmc
- Stream video, music, and photos
- Play content from a computer or USB drive
- Watch and record TV via satellite, cable, or terrestrial
- Build a library
- Much more
Last week, I made few bench with Raspberry Pi at work. I wanted to compare hard float and soft float, technologies available, and quickly compare to few other hardware.
With sudoku solving and matrix multiplication code available at http://attractivechaos.github.com/plb/, I made a little modification in the code which is available here. I then tried GCC, Oracle JVM, OpenJDK 7 ZeroVM and JamVM, then Python on these platforms :
- Raspberry Pi – Single Core ARM 700Mhz – 512Mb
- Debian wheezy (soft-float) with JDK7 for Oracle JVM
- Raspbian wheezy (hard-float) with JDK8 for Oracle JVM
- Phone – Wiko Cink Slim – Dual Core ARM 1Ghz – 512Mb
- Android 4.0
- Laptop – Dell E6400 – Dual Core X86 2.26Ghz – 2Gb
- Ubuntu 12.10
Here we can see that GCC optimized code is faster on Raspberry as expected. Surprising, Oracle JVM is really fast, with the same time as GCC without optimization. Python explodes times. On the laptop, the order is the same but the time increase with Python is not so important. On the laptop, Python is 30x slower than GCC, whereas it’s 60x slower on the Raspberry Pi. Is there a Raspberry issue with Python or is it a generally ARM issue ? I was not able to try Python on the phone to get an idea. Phone results are not useful here.
With float computation, the orders does not change, except on soft Debian, where the Oracle JVM is faster than GCC. Congrats to Oracle !
Times given here are the same as before, but grouped by technology to compare each platforms. As we can see, Oracle JVM has the same performance on both hard and soft float Pi.
With pure integer computation, we can see on GCC that time reduction on ARM platforms is proportional to frequency increase. Core count does not matter in this test. But with float computation, the Rasperry Pi can be faster than the phone, thanks to hardware float support, even with a slower frequency. On the same Raspberry, hard float support increases performance by 2 !
We can also see the difference between x86 and ARM architecture. The laptop CPU has a frequency multiplied by 2.26 compared to phone’s one, but the execution is 20 times faster.
OpenSLL speed test
Please take note I have set the graph maximum value to 2000 operations per second, but Verifying with RSA 1024 or 2048 exceed this maximum. As we can see, OpenSSL is two time faster on a hard-float Pi than a soft-float Pi.
First, I have to say that even if Python is a great language and technology, as the syntax is quite simple and it allows various programming paradigm: sequential, functional, object-oriented. But the ARM port is really slow. As Oracle JVM is now available, even on Raspbian with the JDK8 Early Access, and regarding the result, I think Java is the best choice to get best programming ease/performance ratio. Then, the problem is that Raspberry Pi is not enough powered to run a Java IDE like Eclipse. Another computer, a network sharing and a SSH connection on the Pi will help developing in Java for the Pi.
Comparing ARM platforms shown that hard float support is a great thing as the performance increase is really significative and float computation is used almost everywhere, in data compression for instance.
Finally, comparing ARM to x86 architecture is a real proof that frequency does not always matter. I may try with my old 400Mhz Pentium 2, I’m pretty sure the result will be the same as the Raspberry Pi. As no one should use a Pentium 2 to do intensive web surfing and desktop tasks, you may understand why it’s a bad idea to use the Raspberry as a desktop computer replacement.
On my side, I decided to port WebIOPi to Java before the 1.0 final release.
External links :
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.
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.