import RPi.GPIO as GPIO
import time
import sys
sensor = 4
GPIO.setmode(GPIO.BCM)
GPIO.setup(sensor, GPIO.IN, GPIO.PUD_DOWN)
previous_state = False
current_state = False
state = "+"
try:
while True:
time.sleep(0.01)
previous_state = current_state
current_state = GPIO.input(sensor)
if current_state != previous_state:
new_state = "HIGH" if current_state else "LOW"
if new_state == "HIGH":
state = "+"
else:
state = "="
else:
state = "_"
sys.stdout.write(state)
sys.stdout.flush()
except KeyboardInterrupt:
print "User Quit, doing GPIO clean up"
GPIO.cleanup()
___________________________________________+=___________________________+__=____________________+_=___________________________________+=__________________+______________________________=________________User Quit, doing GPIO clean up
#DropBox POC from stackoverflow
#http://stackoverflow.com/questions/23894221/upload-file-to-my-dropbox-from-python-script
import dropbox
client = dropbox.client.DropboxClient('DROPBOXAUTHKEYGETYOURSFROMYOURDROPBOXACCOUNT')
print 'linked account: ', client.account_info()
f = open('working-draft.txt', 'rb')
response = client.put_file('/88/magnum-opux.txt', f)
print 'uploaded: ', response
folder_metadata = client.metadata('/')
print 'metadata: ', folder_metadata
f, metadata = client.get_file_and_metadata('/88/magnum-opux.txt')
out = open('magnum-opux.txt', 'wb')
out.write(f.read())
out.close()
print metadata
# Pir_camera.py
#
# Polling script to take and upload images when PIR sensor is triggered
# Rob Davis 2015
#
import RPi.GPIO as GPIO
import time
import sys
import os
import picamera
import datetime
import dropbox
# Never upload your secret keys to github!
client = dropbox.client.DropboxClient('DROPBOXAUTHKEYGETYOURSFROMYOURDROPBOXACCOUNT')
liveOutput = False
#Create a camera interface with the half the maximum 5MP resolution
cam = picamera.PiCamera()
cam.resolution = (1296, 972)
#Which GPIO pin are we using?
sensor = 4
#Set the GPIO pin ready for input
GPIO.setmode(GPIO.BCM)
GPIO.setup(sensor, GPIO.IN, GPIO.PUD_DOWN)
#simple state variables
previous_state = False
current_state = False
state = "+"
capturing = False
captureCount = 0
#Upload a file name to a path on DropBox
def UploadFile(filename, uploadPath):
fileHandle = open(filename, 'rb')
response = client.put_file(uploadPath + filename, fileHandle)
#really should check the response, but, it always works ;)
os.remove(filename)
#Get a unique filename based on the datetime
def GetFileName(count):
return datetime.datetime.now().strftime("%Y%m%d%H%M%S_" + str(count) + ".jpg")
#Get a path based on the date, so a new folder each day
def GetUploadPath():
return datetime.datetime.now().strftime("%Y%m%d/")
if len(sys.argv) >= 2 and sys.argv[1] == "-v" :
liveOutput = True
#Main loop in a try/catch to allow for CTRL+c termination
try:
while True:
time.sleep(0.01) # very short sleep, 100th of a second
previous_state = current_state # back up current state
current_state = GPIO.input(sensor) # get new 'current' state
if current_state != previous_state:
new_state = "HIGH" if current_state else "LOW"
if new_state == "HIGH":
state = "+"
capturing = True
else:
state = "="
capturing = False
captureCount = 0
else:
state = "_"
if capturing:
state = "[o]"
captureCount += 1 # allows for multiple frames per-second
filename = GetFileName(captureCount)
uploadPath = GetUploadPath()
cam.annotate_background = picamera.Color('black')
cam.annotate_text = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
cam.capture(filename) # get a photo from the camera
UploadFile(filename, uploadPath) # upload the photo to a 'todays' folder on DropBox
if liveOutput :
sys.stdout.write(state) # print out the state without a LF
sys.stdout.flush() # flush to stdout or it will sit waiting for a LF
except KeyboardInterrupt:
print "User Quit, doing GPIO clean up"
GPIO.cleanup()
email
root
flog archives
Disclaimer:
This page is by me for me, if you are not me then please be aware of the following
I am not responsible for anything that works or does not work including files and pages made available at www.jumpstation.co.uk
I am also not responsible for any information(or what you or others do with it) available at www.jumpstation.co.uk
In fact I'm not responsible for anything ever, so there!