Jan 122014
 

Using the Raspberry Pi for switching 433 MHz based power sockets has been well documented (here for example). I’ve set it up myself and will document all the steps needed (basically for myself), too.

Requirements
– Raspberry Pi (Model does not matter)
– Memory card (SD/USB, at least 4GB)
– Pi power supply (Micro USB, at least 1.2 A)
– Optional case, USB Wifi Dongle (I used a Netgear WNA1000M, which uses Realtek RTL8188CUS chipset, so COMFAST CF-WU710N should work, it is ~5€ from Ebay or AliExpress)
– 433 MHz Transmitter (FS1000A will work, around 1-2€ from dx.com, e.g. SKU 149254. This one has the antenna already soldered on it and claims higher range)
– 17cm cable and the ability to solder one 2mm Pin (=soldering iron)

Total cost: around 55-60€ currently (01 / 2014)

The setup
My Raspberry Pi came with NOOBS and it installed fine on a Class 4 4GB SDHC card using it. After the initial setup (username, date and so on), I did the following as root (sudo -s) (using wired network, not wireless yet)

apt-get update
apt-get upgrade
apt-get dist-upgrade
reboot
apt-get install vim nginx php5-fpm php5-cgi php5-cli php5-common git-core
mkdir /var/www
chown www-data:www-data /var/www
vim /etc/nginx/sites-enabled/default

Now in nginx I added my site on line 2 or 3 (where it says your server here):

server {
        listen 80;
        root /var/www;
        index index.html index.php;
        server_name pi;
        location / {
                try_files $uri $uri/ /index.php?$args;
        }
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

Then restart nginx, it should startup fine:
/etc/init.d/nginx restart

Now setup WiringPi and PowerPi:

cd
git clone git://git.drogon.net/wiringPi
cd wiringPi/
./build
cd
wget http://raspberrypiguide.de/stuff/powerpi-0.1.tar.gz
tar xfz powerpi-0.1.tar.gz
cd powerpi-0.1
make clean
make
make install
/etc/init.d/powerpi start
cp -r www/ /var/
chown -R www-data:www-data /var/www

That’s it, you can surf on your website and configure it now. The connection of the RF transmitter to the Pi depends on your RF transmitter, for me I used one of the 5V pins (Pin 4) and for ground Pin 6 and for data you have to use GPIO 17, which is Pin 11. The website has a help picture which will explain it better ;)

Antenna: If you want to increase range, you have to solder exactly 17cm of wire to the RF transmitter antenna pin. Here and here are some nice pictures.

Edit:
If you want to send data via command line, you can use raspberry-remote and the send command:
./send 11111 1 1
From within PHP it could be something like “shell_exec(‘/path/to/send ‘. 11111 1 1)

(My previous post shows how to configure Wifi for the Raspberry Pi.)