Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import RPi.GPIO as GPIO
- import sys
- import os
- import time
- import glob
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(4, GPIO.OUT)
- def relayon():
- GPIO.output(4, GPIO.HIGH)
- # time.sleep(60)
- #GPIO.output(4, GPIO.HIGH)
- def relayoff():
- GPIO.output(4, GPIO.LOW)
- def getRecentFile():
- if os.environ.get('OS','') == 'Windows_NT':
- ## Windows OS try min to find most recent
- return min(glob.iglob('/var/spool/gammu/inbox/*.txt'), key=os.path.getctime)
- else: return max(glob.iglob('/var/spool/gammu/inbox/*.txt'), key=os.path.getctime)
- ## will try and use linux max which should find most recent file
- ## both examples will search for in theory most recent file created in that directory
- ## /var/spool/gammu/inbox/
- try:
- complete_filename=str(getRecentFile())
- ## complete_filename="/home/pi/proc1.py"
- sms_file=open(complete_filename,"r")
- message=sms_file.read(160)
- if (message.find("poweron")!= -1): (relayon)
- elif (message.find("poweroff") != -1): (relayoff)
- # GPIO.output(4, GPIO.LOW)
- except KeyboardInterupt:
- print "\n"
- finally: GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement