Advertisement
careingemt

Untitled

Jan 5th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. ##############################################################################################################################################################################################################################################################################
  2. ############### PLEASE NOTE ####################
  3. ############### THERE ARE SOME ADDITIONAL STEPS THAT NEED TO BE ####################
  4. ############### COMPLETED ON THE Pi FOR IT TO SEND THE AUTOREMOTE MESSAGE ####################
  5. ############### TO MY PHONE SO I CAN MONITOR THINGS ON MY POOL WHILE I AM HOME OR AWAY FROM HOME ####################
  6. ############### IF ANYONE IS INTRESTED IN SETTING UP THE AUTOREMOTE ON THE Pi I CAN HELP WITH THAT ####################
  7. ##############################################################################################################################################################################################################################################################################
  8.  
  9.  
  10. import RPi.GPIO as GPIO
  11. import time
  12. from time import sleep
  13. import urllib.request
  14.  
  15. # Define Variables
  16. AR_KEY = "MY ARKEY GOES HERE BETWEEN QUOTES"
  17. WATER_FLOW_PIN = 17 # Water Flow sensor pin
  18.  
  19. def sendAR(msg):
  20. print(msg)
  21. message = 'http://autoremotejoaomgcd.appspot.com/sendmessage?key=' + AR_KEY + '&message=' + msg
  22. urllib.request.urlopen(message).read()
  23.  
  24. # Is Water flowing
  25. def isWaterFlowing():
  26. sampleData = []
  27. t_end = time.time() + 3 # 3 sec sample
  28. while time.time() < t_end:
  29. sampleData.append(GPIO.input(WATER_FLOW_PIN))
  30. sleep(.1) # wait .1 sec for an other sample
  31.  
  32. print(sampleData)
  33. return sampleData.count(0) >= 1 and sampleData.count(1) >= 1
  34.  
  35. # Setup GPIO ports
  36. GPIO.cleanup
  37. GPIO.setmode(GPIO.BCM)
  38. GPIO.setwarnings(False)
  39. GPIO.setup(WATER_FLOW_PIN, GPIO.IN)
  40.  
  41. # water flow status
  42. waterFlowingState = ""
  43.  
  44. while True:
  45. # Check the state again
  46. tmpWaterFlowingState = isWaterFlowing()
  47. if waterFlowingState != tmpWaterFlowingState:
  48. # State has changed update flag and send msg
  49. waterFlowingState = tmpWaterFlowingState
  50. if waterFlowingState:
  51. sendAR("water=:=flowing") # Send message to phone
  52. else:
  53. sendAR("water=:=closed") # Send message to phone
  54.  
  55. sleep(1) # Wait 1 seconds before checking again
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement