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("")                
    conn.request("POST", "/update", params, headers)
    response = conn.getresponse()
    data =
    print "connection failed"

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

*/5 * * * * python "/home/ubuntu/logging/"

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.

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
    • 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.

RPi GPIO: Adding switches and lights


Create a pair of LED’s and push buttons on my RPi which can run scripts. ?One will shut down the Pi (updated here), the other will rsync a directory to a USB. Also I will read the status of a UPS. This may/will become more complicated since the UPS doesn’t have any useful interface (requiring an Arduino to:

  • Watch the UPS battery voltage and tell the RPi to power down.
  • Monitor whether mains power is applied.
  • Once mains is re-powered, restart the RPi after a UPS shut down using the hardware reset pins on the Pi.)
  1. As in these RPi ubuntu instructions I installed python.. I removed sudo from the last command to make the command output happy
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-pip
pip install RPi.GPIO
  1. Initially I set up a breadboard as in this youtube video (using the linked files)
    from time import sleep
    import RPi.GPIO as GPIO
    GPIO.setup(12, GPIO.OUT)
    while 1:
     GPIO.output(12, False)
     GPIO.output(12, True)

    Continue reading “RPi GPIO: Adding switches and lights”

VPN Server on RPi Ubuntu

I installed OpenVPN on my RPi 2 running ubuntu 14.04 using these instructions. Initially it failed, the problem being that I hadn’t allowed UDP port forwarding on my WAN router…

Install Samba on Ubuntu (on an RPi 2)

Note: The RPi2 with officially supported Ubuntu is proving problematic, I want to move to something more reliable.

After installing Ubuntu on my RPi, I’ll now install Samba. This will allow USB drives attached to the RPi to be accessed by other computers, making the RPi into a NAS device.

  1. Install Samba:
    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install samba
  2. Duplicate original samba settings:
    sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.old

    Continue reading “Install Samba on Ubuntu (on an RPi 2)”

Installing Ubuntu on a RPi

  1. I will be using  Ubuntu 16.04 LTS ‘classic’.
    On the RPi site they mention Rpi pic
    the Snappy version of Ubuntu for IoT. This is not the one I want, as it doesn’t use the normal Ubuntu method for getting software (apt-get). The classic Ubuntu image is linked here. This image has SSH pre-installed, so you can boot without ever using a monitor.
    Writing the image to an SD card on Windows can be done with Win32 Disk Imager
    Continue reading “Installing Ubuntu on a RPi”