RaspberryPi real-world control with REST API
By Leo Gaggl
Finally found some time playing with a RaspberryPi and an attached PiFace Interface board to control some garden pumps and potentially an Aquaponics setup in the near future.
Requirements
- Raspberry Pi (Model B in my case, but any will do)
- PiFace Interface board (http://www.piface.org.uk)
Base Raspian (Debian Wheezy) Install (I prefer the clean minimal install via https://githutb.com/hifi/raspbian-ua-netins).
Configure the base system as per my previous base install.
Install Apache & PHP
sudo apt-get install apache2 php5 php5-dev php5-cli php5-mcrypt curl raspi-config
Ensure mod-rewrite is enabled
sudo a2enmod rewrite
Install PHP SPI Extension
More info: https://github.com/frak/php_spi
git clone https://github.com/frak/php_spi.git<br></br>cd php_spi<br></br>./phpize<br></br>./configure --enable--spi<br></br>make<br></br>make test<br></br>make install
Install PiFace REST API
cd /var/www/<br></br>git clone https://github.com/natefanaro/piface-rest-api<br></br>cd piface-rest-api<br></br>curl -sS https://getcomposer.org/installer | php<br></br>php composer.phar install
Thanks to Nate Fanaro for the excellent work on the API.
Make sure SPI is enabled on the RPi
raspi-config
Advanced Options –> A5 SPI –> yes
Install PiFace Modules
sudo apt-get install python3-pifacedigitalio python-pifacedigitalio<br></br>sudo usermod -a -G gpio www-data<br></br>sudo usermod -a -G spi www-data
For more info visit http://www.piface.org.uk/guides.
Apache2 API Configuration
Enable SPI extension
sudo vim /etc/php5/apache2/php.ini<br></br>#add the following extension<br></br>extension="spi.so"
Apache VHost config
sudo vim /etc/apache2/sites-available/piface
Paste the following VHost config
<Virtualhost *:80><br></br>ServerName HOSTNAME<br></br>ServerAdmin webmaster@domain.com<br></br>DocumentRoot /usr/share/piface-rest-api/public_html<br></br>ErrorLog /var/log/apache2/piface_error.log<br></br>CustomLog /var/log/apache2/piface_access.log combined<br></br><Directory /><br></br>AllowOverride All<br></br>Order allow,deny<br></br>Allow from all<br></br></Directory><br></br></Virtualhost>
Enable the newly created VHost
a2ensite piface<br></br>service apache2 restart
Testing
curl http://HOSTNAME/led/test/
Next up will be some modification for securing access to the PiFace REST API via some sort of API Key or digital certificate as it’s open by default at the moment.