Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import RPi.GPIO as GPIO
  3. import sys
  4. import os
  5. import time
  6. import glob
  7.  
  8. GPIO.setmode(GPIO.BCM)
  9. GPIO.setup(4, GPIO.OUT)
  10.  
  11. def relayon():
  12. GPIO.output(4, GPIO.HIGH)
  13. # time.sleep(60)
  14. #GPIO.output(4, GPIO.HIGH)
  15. def relayoff():
  16. GPIO.output(4, GPIO.LOW)
  17.  
  18. def getRecentFile():
  19. if os.environ.get('OS','') == 'Windows_NT':
  20. ## Windows OS try min to find most recent
  21. return min(glob.iglob('/var/spool/gammu/inbox/*.txt'), key=os.path.getctime)
  22. else: return max(glob.iglob('/var/spool/gammu/inbox/*.txt'), key=os.path.getctime)
  23. ## will try and use linux max which should find most recent file
  24. ## both examples will search for in theory most recent file created in that directory
  25. ## /var/spool/gammu/inbox/
  26. try:
  27. complete_filename=str(getRecentFile())
  28. ## complete_filename="/home/pi/proc1.py"
  29. sms_file=open(complete_filename,"r")
  30. message=sms_file.read(160)
  31. if (message.find("poweron")!= -1): (relayon)
  32. elif (message.find("poweroff") != -1): (relayoff)
  33. # GPIO.output(4, GPIO.LOW)
  34. except KeyboardInterupt:
  35. print "\n"
  36. finally: GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement