Hardware Reference
In-Depth Information
#Create datetime objects
startTime = datetime.datetime(now.year,now.month,now.
day,17,30,0)
endTime = datetime.datetime(now.year, now.month,now.
day,22,45,0)
#Create unix time stamps
unixStart = (startTime - datetime.datetime(1970,1,1)).
total_seconds()
unixEnd = (endTime - datetime.datetime(1970,1,1)).total_
seconds()
unixNow = (now - datetime.datetime(1970,1,1)).total_
seconds()
The Unix timestamps are used to check whether it is time to turn on/off
the appliances:
if ( unixStart <= unixNow <= unixEnd):
GPIO.output(25,GPIO.HIGH)
while ( unixStart <= unixNow <= unixEnd):
now = datetime.datetime.now()
unixNow = (now - datetime.datetime(1970,1,1,0,0,0)).
total_seconds()
print "Triggered", now.hour,":",now.minute,":",now.
second
sleep(1)
GPIO.output(25,GPIO.LOW)
Objective complete - mini debriefing
Yay! We are done with a simple automaion task of keeping the lights on at a given ime
period everyday.
Alternative solutions and some project ideas to consider
1. If it is not possible to install Raspberry Pi right next to the power tail switch, it is
possible to interface the PowerSwitch Tail 2 to an Arduino Ethernet board and
controlled by Raspberry Pi using the Twisted framework example (hint: refer to
the examples from the previous project, Project 10 , Raspberry Pi Personal Health
Monitor ). This enables you to control a network of devices using Raspberry Pi.
2. One alternaive to consider if it is not possible to purchase a PowerSwitch Tail
2—SparkFun has an excellent tutorial on building a controllable AC power outlet
( https://www.sparkfun.co m/tutorials/119 ).
 
Search WWH ::




Custom Search