RaspberryPi real-world control with REST API
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-configEnsure mod-rewrite is enabled
sudo a2enmod rewriteInstall PHP SPI Extension
More info: https://github.com/frak/php_spi
git clone https://github.com/frak/php_spi.git
cd php_spi
./phpize
./configure --enable--spi
make
make test
make installInstall PiFace REST API
cd /var/www/
git clone https://github.com/natefanaro/piface-rest-api
cd piface-rest-api
curl -sS https://getcomposer.org/installer | php
php composer.phar installThanks to Nate Fanaro for the excellent work on the API.
Make sure SPI is enabled on the RPi
raspi-configAdvanced Options –> A5 SPI –> yes
Install PiFace Modules
sudo apt-get install python3-pifacedigitalio python-pifacedigitalio
sudo usermod -a -G gpio www-data
sudo usermod -a -G spi www-dataFor more info visit http://www.piface.org.uk/guides.
Apache2 API Configuration
Enable SPI extension
sudo vim /etc/php5/apache2/php.ini
#add the following extension
extension="spi.so"Apache VHost config
sudo vim /etc/apache2/sites-available/pifacePaste the following VHost config
<Virtualhost *:80>
ServerName HOSTNAME
ServerAdmin webmaster@domain.com
DocumentRoot /usr/share/piface-rest-api/public_html
ErrorLog /var/log/apache2/piface_error.log
CustomLog /var/log/apache2/piface_access.log combined
<Directory />
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</Virtualhost>Enable the newly created VHost
a2ensite piface
service apache2 restartTesting
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.
Comments
Be the first to comment! Reply to this post from your Mastodon/Fediverse or Bluesky account, or mention this post's URL in your reply. Your comment will appear here automatically via webmention.
Follow this blog on Mastodon at @gaggl.com@web.brid.gy or on Bluesky at @gaggl.com
