Control Linux servers over XMPP chat

https://web-beta.archive.org/web/20140209155007/http://oskarhane.com/make-your-raspberry-pis-and-other-servers-a-botnet-controlled-via-xmpp

http://oskarhane.com/make-your-raspberry-pis-and-other-servers-a-botnet-controlled-via-xmpp/

  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 archive.org 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 user@server.com -p password -h 'server.com' --port 5222 --master your_real_account@server.com
  8. If it’s working, you’ll see this
    (node) sys is deprecated. Use util instead.
    off1 loaded
    on1 loaded
    uptime loaded
    Connected!

    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 lights@chat.server.com -p <password> -h ‘chat.server.com’ –port 5222 –master chris@chat.server.com
Advertisements

Raspberry Pi wireless power outlet control

https://www.samkear.com/hardware/control-power-outlets-wirelessly-raspberry-pi

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://git.drogon.net/wiringPi

Execute the build script to compile the code.

cd wiringPi
./build

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

sudo apt-get install apache2 php5 libapache2-mod-php5 -y
git clone git://github.com/timleland/rfoutlet.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):

whippingpost

Finished product:

img_20170128_111856

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:
#!/bin/sh
DIR=$1
ROOT_MOUNT=$(awk '$2=="/" {print substr($4,1,2)}' < /etc/fstab)
if [ $ROOT_MOUNT = "rw" ]
then
/bin/mount --bind ${DIR}_org ${DIR}
else
/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}
fi

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
reboot

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
reboot

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

mount -o remount,rw /

http://blog.pi3g.com/2014/04/make-raspbian-system-read-only/

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

raspberry-pi-rev2-gpio-pinout

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.

#!/bin/python
#This script was authored by AndrewH7 and belongs to him (www.instructables.com/member/AndrewH7)
#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

gpio_pin_number=YOUR_CHOSEN_GPIO_NUMBER_HERE
#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"

GPIO.setmode(GPIO.BCM)
#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

try:
    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
except:
    pass

GPIO.cleanup()
#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/off_button.py

Then plug in the button.

Raspberry Pi video looper

https://learn.adafruit.com/raspberry-pi-video-looper/installation

  1. git clone https://github.com/adafruit/pi_video_looper.git
  2. cd pi_video_looper
  3. sudo ./install.sh

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 ./disable.sh

Webcam Streaming Server on Linux / Raspberry Pi

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

https://github.com/ccrisan/motioneyeos

or install Raspbian and then install the packages on top.

https://github.com/ccrisan/motioneye/wiki/Install-On-Raspbian – be sure to add bcm2835-v4l2to /etc/modules and reboot before starting. Follow the instructions exactly as written – simple.

Configuration file can be edited:

https://github.com/ccrisan/motioneye/wiki/Configuration-File

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

Create a free website or blog at WordPress.com.

Up ↑