Project Secure Backup. Part 6

I moved the project to some acrylic in what is possibly the final stage for the project.While I thought the software reset for the Ethernet chip would suffice for connection problems, it appears this isn’t the case. I’ll try reprogramming the chip with an interrupt reboot for the main program loop, currently the device isn’t sending info to ThingSpeak.

Once the code is running smoothly (for at least a week) I’ll add email notifications. In the future I won’t use this Ethernet chip, there is a similarly priced chip I have which is much more capable.

Continue reading “Project Secure Backup. Part 6”

Hardware shutdown switch for RPi

Sometimes I need to power off one of my Raspberry Pis, and since I run these computers headless, going to a remote SSH terminal to issue a shutdown command can be extra work. I saw a webpage mentioning using a simple 2 pin jumper to initiate a shutdown script for the Pi. So that’s what I did (green tab on the GPIO pins), I chose python due to the wait_for_edge function.

This script will shutdown the RPi when the tab is pulled. Strangely the RPi will boot if you plug the jumper back in after it has shutdown, or if you pull it out after it has completed shut down (putting it back before it has completed shutting down). If there is no jumper in during boot, then the script will close.

#!/usr/bin/env python
#note crontab for superuser required a new PATH variable as here http://unix.stackexchange.com/questions/43392#answer-43394
import subprocess
try:
 import RPi.GPIO as GPIO
except RuntimeError:
 print("Error importing RPi.GPIO! This is probably because you need superuser privileges. You can achieve this by using 'sudo' to run your script")

#http://raspberrypi.stackexchange.com/questions/12966/what-is-the-difference-between-board-and-bcm-for-gpio-pin-numbering
GPIO.setmode(GPIO.BOARD)
GPIO.setup(5, GPIO.IN) #Hardware Pullup on this pin..

ShutdownCommand = ['shutdown', '-h', 'now', '"System halted by GPIO action"']

if GPIO.input(5) == 0:
 #run script waiting for jumper removal
 GPIO.wait_for_edge(5, GPIO.RISING)
 GPIO.remove_event_detect(5)
 KillProcess = subprocess.Popen(ShutdownCommand, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
 MountData, MountError = KillProcess.communicate()
 GPIO.cleanup() 
else:
 GPIO.cleanup()

Then I simply added this script to the bottom of my root crontab (sudo crontab -e) to run at reboot:

@reboot python /usr/local/sbin/ShutdownJumper.py

Monitoring RPi Temp and CPU with Thingspeak

I made the following python script to update CPU Temperature and 5 minute average CPU load of my RPi to Thingspeak:

#!/usr/bin/env python
import subprocess
import httplib, urllib

GetTempCommand = "cat /sys/class/thermal/thermal_zone0/temp"
GetCPUCommand = "cat /proc/loadavg"

GetTempProcess = subprocess.Popen(GetTempCommand.split(), stdout=subprocess.PIPE)
GetTempOutput = GetTempProcess.communicate()[0]
Temp = float(GetTempOutput) / 1000
#print Temp
GetCPUProcess = subprocess.Popen(GetCPUCommand.split(), stdout=subprocess.PIPE)
GetCPUOutput = GetCPUProcess.communicate()[0]
CPU = GetCPUOutput.split()
#print CPU[1]

params = urllib.urlencode({'field1': CPU[1],'field2': Temp, 'key':'######'})     # use your API key generated in the thingspeak channels for the value of 'key'
# temp is the data you will be sending to the thingspeak channel for plotting the graph. You can add more than one channel and plot more graphs
headers = {"Content-typZZe": "application/x-www-form-urlencoded","Accept": "text/plain"}
conn = httplib.HTTPConnection("api.thingspeak.com:80")                
try:
    conn.request("POST", "/update", params, headers)
    response = conn.getresponse()
    data = response.read()
    conn.close()
except:
    print "connection failed"

The script is run every 5 mins using cron ($ crontab -e):

*/5 * * * * python "/home/ubuntu/logging/TempCPUtoThingspeak.py"

I borrowed some script from here and here.

Raspbian on RPi3 for NAS

Note: I have swapped the RPi3 for a RPi2 due to Ubuntu compatibility. Even the supported RPi2 with Ubuntu is proving problematic, I want to move to something more reliable.

20161025_134850
Using a Western Digital PiDrive Cable to power the setup.
  • Raspbian comes with default user:pass = pi:raspbian so this needs to be changed
  • I confirmed SSH was installed and working.
  • Following these instructions;
    • I installed ufw
      sudo apt-get install ufw
      sudo ufw allow ssh
      etc..
    • I confirmed NTP configuration.
  • Installed autoupdates, similar to this with different config.
  • Installed postfix, kind of like this.
  • the rest of the steps are basically the same that I used for Ubuntu – except that there isn’t a proper Ubuntu release for RPI3 yet.

rsync on a GoFlex Home NAS

So the GoFlex home UI is pretty crap, it sure as hell doesn’t have a rsync deamon. Until now. This summer…. etc

So I want to send Synology backups to the old GoFlex NAS.

Here’s how I did it:

Take Drive plastic off, replace 2TB drive with 3TB drive.

Reformat. (and gain SSH root).

InstallĀ  and config rsync .
      • Install package manager.
      • Add rsync:
        sudo ipkg install rsync
      • Config rsync daemon. In mine I set the path to a symlink for a users private shared folder, and added settings for that user.
        I started the daemon with
        sudo /opt/etc/init.d/S57rsyncd start
        and played with this until it was reachable from my Synology (some celebrations may have been had)
      • I made a symlink for the rsync opt init script in the system init folder:
        sudo ln -s /home/opt/etc/init.d/S57rsyncd /etc/rc.d/init.d/rsyncd
      • Then symlinked that with a startup link in runlevel 3.
        sudo ln -s /etc/rc.d/init.d/rsyncd /etc/rc.d/rc3.d/S57rsyncd
    • Holy Macrol, it appears to work!