-
Raspberry Pi with an SD card (I recommend 8GB) and running raspbian image
-
Temperature sensor (I used DS18B20 with cable and waterproof)
-
Some cables, breadboard, resistances, LEDs (for testing purposes), multimeter
-
Relay (I used a 5V AC250V10A 1-channel relay module)
-
GSM/3G USB modem, unlocked (I used gsmliberty.net to unlock mine)
-
valid SIM card (prepaid, preferably refillable via internet)
-
Powered USB hub (I used this 4-port hub from i-tec, product number U2HUB412: small size and delivers enough current to power both the 3G USB modem and the RPi)
-
Maybe some angled USB cables to save some space when packaging the whole thing (I bought one here)
-
A rasp and a drilling machine to make the holes for the cables
-
Power cable with male and female plug; cable will be cut in half to put the relay in between
-
Connect the temperature sensor to correct power/ground/data pins on the Pi using a 'pullup' resistor of 4K7 Ohm. See sensor specification and my corresponding python script. Adafruit.com also has a nice tutorial here. My temperature sensor has cable colors red=3V3, black=GND and 3rd cable (white or yellow) is DATA.
-
Connect the relay to the configured (in my.cfg) GPIO pins on the Pi - see your relay specification
# uninstall some useless/non-required packages
> sudo apt-get autoremove -y sonic-pi python-minecraftpi wolfram-engine
> sudo apt-get autoremove -y x11-common omxplayer scratch dillo xpdf
> sudo apt-get autoremove -y galculator netsurf-common netsurf-gtk
> sudo apt-get autoremove -y lxde-common lxde-icon-theme lxterminal hicolor-icon-theme
> sudo apt-get autoremove -y lxpanel lxpanel-data
> sudo apt-get autoremove -y
# finally clear the apt cache from all downloaded .deb packages
> sudo apt-get clean
# update RPi to latest and greatest
> sudo apt-get update
> sudo apt-get upgrade
# and if you want to run latest RPi (nightly) builds:
> sudo rpi-update
#install gammu (python library to send/read sms)
> sudo apt-get install gammu python-gammu
# if you want to use an USB Ethernet adapter to connect to the RPi
# (for updating, configuring, debugging etc), then
# ensure that you have the following lines (and no other lines
# relating to interface eth1) in /etc/network/interfaces :
# allow-hotplug eth1
# iface eth1 inet dhcp
# Enable 1-wire support (for DS18B20 temperature sensor):
# For newer kernels >= 3.18.5):
# ensure following lines appear in your /boot/config.txt :
device_tree=bcm2708-rpi-b-plus.dtb #for RPi A+/B+
device_tree_overlay=overlays/w1-gpio-overlay.dtb
# For older kernels:
# ensure the following lines appear in your /etc/modules :
w1_gpio
w1_therm
# ensure that the following module is listed in /etc/modules :
usbserial
# force fsck to run upon every boot (since only way to shut down will be to cut the power)
> sudo fdisk -l # to find out your filesystem device identifier
> sudo tune2fs -c 1 /dev/<filesystem-device-identifier>
# at this point restart if you haven't done so yet:
> sudo shutdown -r now
# generate a gammu configuration and store it into .gammurc in home dir (usb modem must be connected)
> gammu-detect > ~/.gammurc
# if not yet done: generate an ssh key pair
> ssh-keygen -t rsa -C "your_email@example.com"
# now clone this git repository into the pi home folder
> cd
> git clone git@github.com:stefanthurnherr/sms-temperature-control.git
# Create your personal configuration
> cp sms-temperature-control/my.cfg.example sms-temperature-control/my.cfg
# now go through sms-temperature-control/my.cfg and adjust as needed
# add python script to root crontab (root is required to read/write GPIO channels)
# sudo crontab -e
# */15 * * * * /usr/bin/python /home/pi/sms-temperature-control/bin/say_hello.py >> /home/pi/sms-temperature-control/log/heartbeat.stdout 2>&1
# */01 * * * * /usr/bin/python /home/pi/sms-temperature-control/bin/process_sms.py >> /home/pi/sms-temperature-control/log/smsprocessing.stdout 2>&1
# */05 * * * * /usr/bin/python /home/pi/sms-temperature-control/bin/autocontrol_power.py >> /home/pi/sms-temperature-control/log/powerautocontrolling.stdout 2>&1
# @reboot /usr/bin/python /home/pi/sms-temperature-control/bin/run_once_after_boot.py >> /home/pi/sms-temperature-control/log/afterboot.stdout 2>&1
#
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * command to be executed
## gammu version and supported features
> gammu features
# waiting for PIN?
> gammu getsecuritystatus
# enter PIN
> gammu entersecuritycode PIN -
# phone info
> gammu identify
# cell network info
> gammu networkinfo
# send sms
> echo "sms content" | gammu sendsms TEXT +1234567890 # mobile number in international format
# send USSD code (to check sim card balance etc.). Make sure to choose correct
# section with the -s parameter, not all seem to work equally well for USSD.
> gammu -c ${HOME}/.gammurc.cfg -s 1 getussd '*100#'-
make OS run fsck upon every boot (and maybe force boot once every week?)
-
Warn administrator if balance falls below (configurable) threshold (for prepaid SIM cards)
-
Configurable timer function for switching relays on/off
-
Add support for remote-controlled relay (TellStick? z-wave?) to be able to physically separate 5V circuit from 230V circuit. This would increase safety.
For the reference, here’s how to install an additional python module (like pytz or rpi.gpio or psutil if not already available):
# install python development headers required by some packages (e.g. psutil)
> sudo apt-get install python-dev
# install python-pip using the package manager
> sudo apt-get install python-pip
# then simply install the target module, e.g. pytz:
> sudo pip install pytz
