Control Linux servers over XMPP chat

  1. Install node.js
  2. mkdir xmpp-bot && cd $_
    npm install optimist
    sudo npm install forever -g
    npm install simple-xmpp
    mkdir conf
  3. Download the three JS files from the link.
  4. Put uptime.js inside the xmpp-bot/conf folder.
  5. Run
    export NODE_PATH=`pwd`/node_modules:$NODE_PATH
  6. dir structure should look like this
    pi@pi-lights:~/xmpp-bot/node_modules $ ls
    app.js  conf  helper.js
    pi@pi-lights:~/xmpp-bot/node_modules $ ls conf
    off1.js  on1.js  uptime.js
  7. Start the server with
    node app.js -u -p password -h '' --port 5222 --master
  8. If it’s working, you’ll see this
    (node) sys is deprecated. Use util instead.
    off1 loaded
    on1 loaded
    uptime loaded

    where all of the “loaded” statements are for the various modules you’ve created.

  9. To create new modules, copy the uptime.js file, rename it to whatever you want, then change the var, holder, and module.exports line to match the new module name you’ve created. Then on the child = exec line, change the part inside the quotation marks to the command you want to run. e.g.
    child = exec("/var/www/html/rfoutlet/codesend 5575996"

  10. To start service in the background, run forever start app.js -u -p <password> -h ‘’ –port 5222 –master

Raspberry Pi wireless power outlet control

Hook up the GPIO breakout to the Pi and breadboard.

Transmitter Module

  • GND (left pin near coil) = Ground
  • GPIO (center pin) -> GPIO #17 (also known as GPIO #0)
  • VCC (right pin) -> 5 volts

Receiver Module (only necessary for initial setup)

  • VCC (left pin) -> +5VDC
  • DATA (2nd pin from left) -> GPIO 21/27
  • GND (far right pin) -> Ground
git clone git://

Execute the build script to compile the code.

cd wiringPi

Use the command below to install Apache with the PHP modules.

sudo apt-get install apache2 php5 libapache2-mod-php5 -y
git clone git:// /var/www/html/rfoutlet
sudo chown root.root /var/www/html/rfoutlet/codesend
sudo chmod 4755 /var/www/html/rfoutlet/codesend

Then run the sniffer application and press the buttons on the remote to pick up the codes.

sudo /var/www/html/rfoutlet/RFSniffer

Each press of a button on the remote should produce something like this:

Received 21811
Received pulse 192

Edit /var/www/html/rfoutlet/toggle.php with the codes you recorded in step 5. Use the longer code (not the pulse).

Then go to the device webpage http://<device IP address>/rfoutlet/ (example) and test it.

To manually send codes:

root@raspberrypi:/home/pi# /var/www/html/rfoutlet/codesend 5575987

$codes = array(
“1” => array(
“on” => 5575987,
“off” => 5575996
“2” => array(
“on” => 5576131,
“off” => 5576140
“3” => array(
“on” => 5576451,
“off” => 5576460
“4” => array(
“on” => 5577987,
“off” => 5577996
“5” => array(
“on” => 5584131,
“off” => 5584140

To send POST data manually (if you wanted to create an app or something):


Finished product:


Pi read only filesystem

Disable swap
dphys-swapfile swapoff
dphys-swapfile uninstall
update-rc.d dphys-swapfile disable

Install UnionFS
aptitude install unionfs-fuse

Create mount script

nano /usr/local/bin/mount_unionfs

add the following content:
ROOT_MOUNT=$(awk '$2=="/" {print substr($4,1,2)}' < /etc/fstab)
if [ $ROOT_MOUNT = "rw" ]
/bin/mount --bind ${DIR}_org ${DIR}
/bin/mount -t tmpfs ramdisk ${DIR}_rw
/usr/bin/unionfs-fuse -o cow,allow_other,suid,dev,nonempty ${DIR}_rw=RW:${DIR}_org=RO ${DIR}

make it executable:

chmod +x /usr/local/bin/mount_unionfs

Update /etc/fstab to look like this:

nano /etc/fstab

Modify the file to read (adjust partitions for NOOBS!) as follows:

proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat ro 0 2
/dev/mmcblk0p2 / ext4 ro,noatime 0 1
mount_unionfs /etc fuse defaults 0 0
mount_unionfs /var fuse defaults 0 0
none /tmp tmpfs defaults 0 0

Change “defaults” on mmcblk lines to ro
Add three lines underneath for UnionFS

Prepare the directories and reboot

cp -al /etc /etc_org
mv /var /var_org
mkdir /etc_rw
mkdir /var /var_rw

Clean up the Log directory

mount -o remount,rw /
for f in $(find . -name *log); do > $f; done
cd /var_org/log
rm -f *.gz

To make changes afterwards, remount the file system as read/write:

mount -o remount,rw /

Raspi, Mate

Re-size file system

There are no utilities included for automatic file system re-sizing. However, it’s not hard to do manually. Once booted:

sudo fdisk /dev/mmcblk0

Delete the second partition (d, 2), then re-create it using the defaults (n, p, 2, enter, enter), then write and exit (w). Reboot the system, then:

sudo resize2fs /dev/mmcblk0p2

Raspberry Pi Power Off Shutdown Switch Button


Python script – change gpio_pin_number to corresponding pin on board. On Pi 1 rev B, GPIO pin 7 and ground pin are the ones closest to the composite video port.

#This script was authored by AndrewH7 and belongs to him (
#You have permission to modify and use this script only for your own personal usage
#You do not have permission to redistribute this script as your own work
#Use this script at your own risk

import RPi.GPIO as GPIO
import os

#Replace YOUR_CHOSEN_GPIO_NUMBER_HERE with the GPIO pin number you wish to use
#Make sure you know which rapsberry pi revision you are using first
#The line should look something like this e.g. "gpio_pin_number=7"

#Use BCM pin numbering (i.e. the GPIO number, not pin number)
#WARNING: this will change between Pi versions
#Check yours first and adjust accordingly

GPIO.setup(gpio_pin_number, GPIO.IN, pull_up_down=GPIO.PUD_UP)
#It's very important the pin is an input to avoid short-circuits
#The pull-up resistor means the pin is high by default

    GPIO.wait_for_edge(gpio_pin_number, GPIO.FALLING)
    #Use falling edge detection to see if pin is pulled 
    #low to avoid repeated polling
    os.system("sudo shutdown -h now")
    #Send command to system to shutdown

#Revert all GPIO pins to their normal states (i.e. input = safe)

To make the script at run at startup, edit rc.local – sudo nano /etc/rc.local

Then navigate to the bottom of this file and just before the “exit 0” line which is at the very end, add this:

python /home/pi/

Then plug in the button.

Raspberry Pi video looper

  1. git clone
  2. cd pi_video_looper
  3. sudo ./

Script starts the application automatically; message appears on connected display saying to insert a USB drive.

Put an MPEG4 video/videos on a USB drive, insert into Pi, and it will start playing.

TO temporarily stop: run sudo supervisorctl stop video_looper over SSH. 

Permanently stop: cd pi_video_looper
sudo ./

Webcam Streaming Server on Linux / Raspberry Pi

Either install the MotionEye OS (all components included, but otherwise stripped out):

or install Raspbian and then install the packages on top. – be sure to add bcm2835-v4l2to /etc/modules and reboot before starting. Follow the instructions exactly as written – simple.

Configuration file can be edited:

e.g. to change web port from 8765 (default) to 80

Create a free website or blog at

Up ↑