Trying to launch my camera with motion sensor. Works fine like this:
import RPi.GPIO as GPIO
import time
import picamera
import datetime
import os
def getFileName():
return datetime.datetime.now().strftime("%Y-%m-%d_%H.%M.%S.h264")
pin = 4
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
prevState = False
currState = False
camera = picamera.PiCamera()
while True:
time.sleep(0.1)
prevState = currState
currState = GPIO.input(pin)
if currState != prevState:
newState = "HIGH" if currState else "LOW"
print ("GPIO pin %s is %s" % (pin, newState))
if currState:
fileName = getFileName()
print ("Starting Recording...")
camera.start_preview()
camera.start_recording(fileName)
time.sleep(10)
print (fileName)
else:
camera.stop_preview()
time.sleep(1)
camera.stop_recording()
print ("Stopped Recording")
else:
print("No motions")
But then i try to def my function for Tornado server:
def secure_on(prevState, currState):
pin = 4
#GPIO.setmode(GPIO.BCM)
#GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
#camera = picamera.PiCamera()
time.sleep(0.1)
prevState = currState
#currState = GPIO.input(pin)
if currState != prevState:
newState = "HIGH" if currState else "LOW"
return {'info': "GPIO pin %s is %s" % (pin, newState)}
if currState:
fileName = getFileName()
print ("Starting Recording...")
#camera.start_preview()
#camera.start_recording(fileName)
time.sleep(10)
return {'info': fileName}
else:
#camera.stop_preview()
time.sleep(1)
#camera.stop_recording()
return {'info': "Stopped Recording"}
else:
return {'info': "No motions"}
Tornado:
class SecureOnHandler(tornado.web.RequestHandler):
@gen.coroutine
def get(self):
result = RosPi.secure_on(prevSec, currSec)
self.write({"info": result['info']})
After that i get an error
"Camera component couldn't be enabled: Out of resources (other than memory) ERROR:tornado.access:500 GET /secure_on
What could be causing the error? Thanks in advance!