Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##############################################################################################################################################################################################################################################################################
- ############### PLEASE NOTE ####################
- ############### THERE ARE SOME ADDITIONAL STEPS THAT NEED TO BE ####################
- ############### COMPLETED ON THE Pi FOR IT TO SEND THE AUTOREMOTE MESSAGE ####################
- ############### TO MY PHONE SO I CAN MONITOR THINGS ON MY POOL WHILE I AM HOME OR AWAY FROM HOME ####################
- ############### IF ANYONE IS INTRESTED IN SETTING UP THE AUTOREMOTE ON THE Pi I CAN HELP WITH THAT ####################
- ##############################################################################################################################################################################################################################################################################
- import RPi.GPIO as GPIO
- import time
- from time import sleep
- import urllib.request
- # Define Variables
- AR_KEY = "MY ARKEY GOES HERE BETWEEN QUOTES"
- WATER_FLOW_PIN = 17 # Water Flow sensor pin
- def sendAR(msg):
- print(msg)
- message = 'http://autoremotejoaomgcd.appspot.com/sendmessage?key=' + AR_KEY + '&message=' + msg
- urllib.request.urlopen(message).read()
- # Is Water flowing
- def isWaterFlowing():
- sampleData = []
- t_end = time.time() + 3 # 3 sec sample
- while time.time() < t_end:
- sampleData.append(GPIO.input(WATER_FLOW_PIN))
- sleep(.1) # wait .1 sec for an other sample
- print(sampleData)
- return sampleData.count(0) >= 1 and sampleData.count(1) >= 1
- # Setup GPIO ports
- GPIO.cleanup
- GPIO.setmode(GPIO.BCM)
- GPIO.setwarnings(False)
- GPIO.setup(WATER_FLOW_PIN, GPIO.IN)
- # water flow status
- waterFlowingState = ""
- while True:
- # Check the state again
- tmpWaterFlowingState = isWaterFlowing()
- if waterFlowingState != tmpWaterFlowingState:
- # State has changed update flag and send msg
- waterFlowingState = tmpWaterFlowingState
- if waterFlowingState:
- sendAR("water=:=flowing") # Send message to phone
- else:
- sendAR("water=:=closed") # Send message to phone
- sleep(1) # Wait 1 seconds before checking again
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement