Aug 21

WebIOPi : control your Pi’s GPIO with a browser !

WebI0Pi 0.6 has been released, click here for details.

I’m proud to present my new project, WebIOPi.

This is a web application which allows you to control your Raspberry Pi’s GPIO. Just install it on your Pi, and use any browser from your network.

It’s useful to start enjoying GPIOs and also to debug some circuits without writing any line of code.

It also allows to control your Pi’s GPIOs over Internet, so it’s a good starting point for home remote control.

You can even fully customize the included UI with few CSS modifications or use the REST API to build your own WebApp.

Under Apache License, full doc, code, packages and examples are available on the Google Code project page.

Features

  • Supports binary GPIOs, in both input and output.
  • HTML / Javascript / CSS client side
  • Easily customize UI
  • REST/JSON Web API
  • Server side available in several technologies
    • PHP/Apache
    • PHP/lighttpd
    • Python
  • Smartphone compatible
  • Auto-refresh
Check the roadmap for upcoming features

 

 

Aug 20

AirPi – AirPlay audio sur Raspberry (FR)

mise à jour

J’ai toujours voulu utiliser mon baladeur pour diffuser de la musique dans ma maison en utilisant le réseau. Quand AirPlay est sorti, j’était tout fou, mais le prix de la borne AirPort (99€) ou d’un AppleTV m’a un peu refroidi, même si j’adore mon iPhone et mon MacBook. Heureusement que Free a rapidement intégré shairport dans sa freebox revolution. Mais je ne me vois pas mettre la freebox dans la salle de bain ;)

Avec le RaspberryPi, la fondation m’a apporté une solution low cost, pour environ 30€ en recyclant quelques périphériques optionnels. Comme pour la freebox, on va utiliser shairport, et on va installer le tout sans brancher de clavier, de souris ou d’écran au Raspberry.

Si on a besoin de la vidéo, le plus simple est d’utiliser RaspBMC. Mais si c’est juste pour un player audio, la suite de ce billet est pour vous.

Installer Raspbian “wheezy”
Le plus simple est de suivre les instructions officielles. Une fois que la carte SD est prête, insérez la dans votre Raspberry, brancher un cable ethernet et l’alimentation.

Premier démarrage and login
Pour se logger sur le Pi avec SSH, on a besoin de connaître son adresse IP.
Avec un bon routeur, il est possible que le Pi se soit auto-enregistré sur le DNS local. Le plus simple est donc de commencer par un ping raspberrypi depuis la ligne de commande

Si le DNS ne trouve rien, essayez de vous connecter à l’interface d’administration de votre routeur pour consulter les allocations DHCP.
Vous pouvez aussi essayez toute les IPs de votre réseaux.
Il est aussi possible d’utiliser un scanner comme Fing sur iPhone ou Scapy en Python.

 

Une fois que vous avez l’IP de votre PI, connectez vous avec SSH :
Sur Windows, il faut installer Putty.
Sur Linux/MacOS, il suffit d’ouvrir un terminal : ssh pi@raspberrypi (ou remplacer raspberrypi par son IP)
Tapez le password raspberry quand c’est demandé.

Tout de suite, la première chose à faire est de configurer la distribution Raspbian :

pi@raspberrypi:~$ sudo raspi-config

Commencez par mettre à jour (update), puis étendez la partition (expand_rootfs), changez le password, la locale et la timezone. Laissez SSH activé et le démarrage du bureau désactivé. Quittez et redémarrez. Ca peut prendre un peu de temps pour étendre la partition, patientez et reconnectez vous avec SSH.

Devenir root
Le compte root est desactivé pour la connexion, mais on peut devenir root une fois connecté pour éviter l’utilisation répétée de la commande sudo

pi@raspberrypi:~$ sudo su
root@raspberrypi:/home/pi# cd
root@raspberrypi:~#

Mise à jour de la distribution
Maintenant, mettez à jour les paquets pré-installés :

root@raspberrypi:~# aptitude update
root@raspberrypi:~# aptitude upgrade

Activer la sortie Jack
Une seule ligne de commande suffit à activer la sortie jack :

root@raspberrypi:~# amixer cset numid=3 1

Installer shairport
Avant de télécharger et d’installer shairport, on doit installer les paquets pré-requis :

root@raspberrypi:~# aptitude install git libao-dev libssl-dev libcrypt-openssl-rsa-perl libio-socket-inet6-perl libwww-perl avahi-utils

On télécharge ensuite les sources de shairport pour les compiler :

root@raspberrypi:~# git clone https://github.com/albertz/shairport.git shairport
root@raspberrypi:~# cd shairport
root@raspberrypi:~/shairport# make

On peut enfin lancer shairport en premier plan :

root@raspberrypi:~/shairport# ./shairport.pl -a AirPi

Il est maintenant possible d’utiliser son iDevice pour essayer AirPlay, sans avoir oublié de brancher un casque ou une paire d’enceinte sur la sortie jack.

Pour lancer automatiquement shairport, il suffit d’installer shairport et de copier le script de démarrage :

root@raspberrypi:~/shairport# make install
root@raspberrypi:~/shairport# cp shairport.init.sample /etc/init.d/shairport
root@raspberrypi:~/shairport# cd /etc/init.d
root@raspberrypi:/etc/init.d# chmod a+x shairport
root@raspberrypi:/etc/init.d# update-rc.d shairport defaults

Avant de démarrer le service, on doit ajouter le nom d’AP dans les paramètres de démarrage. Editez le fichier avec nano shairport et changer la ligne avec la variable DAEMON_ARGS  :

DAEMON_ARGS="-w $PIDFILE -a AirPi"

Remplacez AirPi par ce que vous voulez, sauvegardez, quittez et démarrez le service pour profiter pleinement de AirPlay audio avec shairport en arrière plan :

root@raspberrypi:/etc/init.d# ./shairport start

Pour aller plus loin, on peut remplacer le cable ethernet par un dongle WIFI USB, faire un trou dans une boite tupperware pour l’alimentation et le cable audio, et enfin y mettre le Pi pour avoir un AirPi prêt pour la salle de bain ;)

Le son peut ne pas être de bonne qualité. Cela est dû à la sortie analogique qui n’est pas une vrai carte son. Une une carte son USB donnera de meilleurs résultats.

Aug 03

AirPi – AirPlay audio with Raspberry

update here

Raspberry Pi Media Center book by Sam Nazarko is available at amazon.com and amazon.co.uk.

I always wanted to stream music from my music player using network to serve each room. With AirPlay, Apple gave me an easy way to achieve it, but requires more device from that company. An Airport Express costs 99$/€, and even if I love my iPhone and my MacBook, I will never pay for a an Airport or AppleTV device.

With RaspberryPi, the foundation gave me the solution ! Around 30$/€ and some recycled extras, and we are up to enjoy AirPlay Audio, open source and low-cost. It relies on shairport, and we’ll make it without pluging any keyboard, mouse or display.

If we need a Video support, just deal with RaspBMC. But if you only want an audio player, read the rest of the post ;)

Install Raspbian “wheezy”
Follow instructions given on the official raspberry website. Once you have your SD card ready, insert it in your Pi then plug Ethernet and Power cables in.

First boot and login
To log into your Pi with SSH, you need to know its IP adress.
If you have a decent DHCP/DNS server on your network, the Pi should have been registered on your DNS, so try ping raspberrypi from your computer command-line.

If it doesn’t work, you may try to log into your router to see DHCP leases/allocations.
You can also try all IPs of your network range, or use a network scanner like Fing (iOS) or Scapy (python).

 

When you have your Pi’s IP, you can login using SSH :
On Windows, you will need to download and install Putty.
On Linux/MacOS, open a terminal then type : ssh pi@raspberrypi (or replace raspberrypi with its IP)
When prompted, type the password raspberry

Right now, the first thing to do is to configure your raspbian :

pi@raspberrypi:~$ sudo raspi-config

I suggest to first update, then expand the filesystem, change the password, the locale and timezone. Keep SSH enabled and desktop start disabled. Finish and reboot when prompted.
It may take some time to expand the filesystem at reboot. Just wait few minutes then login using ssh again.

Gaining root access
root user is disabled for login, but you can become root if you are already logged to avoid multiple sudo

pi@raspberrypi:~$ sudo su
root@raspberrypi:/home/pi# cd
root@raspberrypi:~#

Upgrade Debian
At this step, it’s a good idea to upgrade pre-installed packages :

root@raspberrypi:~# aptitude update
root@raspberrypi:~# aptitude upgrade

Change audio output
To force audio output to stereo jack, a single line is required :

root@raspberrypi:~# amixer cset numid=3 1

Install shairport
Before download and compile shairport, we need to install prerequisites :

root@raspberrypi:~# aptitude install git libao-dev libssl-dev libcrypt-openssl-rsa-perl libio-socket-inet6-perl libwww-perl avahi-utils

Then download shairport sources and compile it :

root@raspberrypi:~# git clone https://github.com/albertz/shairport.git shairport
root@raspberrypi:~# cd shairport
root@raspberrypi:~/shairport# make

Finally, launch shairport foreground :

root@raspberrypi:~/shairport# ./shairport.pl -a AirPi

You can now use your iDevice to try AirPlay audio, don’t forget to plug an headphone or speakers into the 3.5mm stereo jack.

If you want or need your Pi load automatically shairport, follow next procedure :

root@raspberrypi:~/shairport# make install
root@raspberrypi:~/shairport# cp shairport.init.sample /etc/init.d/shairport
root@raspberrypi:~/shairport# cd /etc/init.d
root@raspberrypi:/etc/init.d# chmod a+x shairport
root@raspberrypi:/etc/init.d# update-rc.d shairport defaults

Before starting the daemon, we have to add the AP Name in the launch parameters. Edit the file using nano shairport then change the DAEMON_ARGS variable line so it looks like to :

DAEMON_ARGS="-w $PIDFILE -a AirPi"

Replace AirPi by whatever you want, save, quit and start the service to enjoy shairport in background and your AirPi :

root@raspberrypi:/etc/init.d# ./shairport start

To go more further, we can replace the Ethernet cord by a WIFI USB dongle, make a hole in a tupperware case for the power and audio cord, then place the Pi inside to get a bathroom-ready AirPi ;)

You may notice some glitchy noise. This is due to the analog output, which is not a real DAC, but a simple PWM generator. A USB sound card will give you a better audio quality.