Nic
Published © GPL3+

Raspberry Pi Smart Switch

Using the Nova Hologram, IoT Relay and a Raspberry Pi, easily make a remote smart switch so you can turn something on across the US.

EasyFull instructions provided1 hour1,022
Raspberry Pi Smart Switch

Things used in this project

Story

Read more

Schematics

Schematics

Code

The Reboot Code

Python
#Easy way to turn off and back on modem
#You would also want to go to Nova Hologram and get a phone number which is $1
#Also you will have to get a device key which is free
#If you want to start the code on boot up then you will have to put in: sudo nano .bashrc
#Go all the way to the bottom and put: sudo python project_name.py
#First ever python project
import time #import some stuff to help us out
import datetime
import subprocess
from Hologram.HologramCloud import HologramCloud
import RPi.GPIO as GPIO

GPIO.setwarnings(False) #turn off warnings
GPIO.setmode(GPIO.BCM) #initialize gpio mode and set pins to off by default
GPIO.setup(17, GPIO.OUT, initial=GPIO.LOW) # Relay is normally on, GPIO.LOW means modem power is on
print 'Home Modem/Router Reboot SMS Controller' #welcome message for console
hologram=HologramCloud(dict(), network='cellular') #setup hologram cloud
hologram.enableSMS #tell hologram to listen for sms
recv=None #if we dont set initial variables the loop breaks
cmd=None
while True: #start the loop
	recv = hologram.popReceivedSMS() #this works, makes the recv variable equal an incoming message
	if recv is not None: #works, run the following code when a message comes in
		print 'SMS From: ', recv.sender #print the sender of the sms
		cmd = recv.message #works, makes the cmd variable the payload of the message.
		print cmd #works, prints only what the sms message is.
		if cmd == 'Reset' or cmd == 'reset': #Checks for Reset or reset (one of them is capital because sometimes an iPhone will capitalize the first letter)
			print 'Start command received' #let the console show we know the SMS had the word start and we will process it
			GPIO.output(17, GPIO.HIGH) #Set normally on relay to off
			time.sleep(10) #Wait ten seconds sec, relay off
			GPIO.output(17, GPIO.LOW) #Set relay back to normally on
			subprocess.call (["hologram","send","--sms","--destination","+16619170871","Completed!","--devicekey","{U>sZ#6s"])#Sends SMS text "Completed!"
			print 'Command complete' #let the console know we are done
	if recv is None: #Runs the following code when there is no message
		print 'No Command, sleep 60 seconds', datetime.datetime.now() #Prints timestamp, handy for troubleshooting
		time.sleep(60) #60 seconds checks for new messages
		print '' #prints a blank line in the console between timestamps when we have no messages for easier reading

Credits

Nic

Nic

1 project • 1 follower

Comments

Add projectSign up / Login