wallace95
Posts: 1
Joined: Fri Apr 07, 2017 8:59 pm

Pi camera with pir sensor to web server

Fri Apr 07, 2017 9:07 pm

Hi guys,

I have my camera working displaying an image captured on my web server. I have writen code to detect motion using a pir sensor and sounding a buzzer and lighting and led. I don't know how to implement this code so that it will store the image on my web server rather than on the desktop?

pcmanbob
Posts: 9612
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Pi camera with pir sensor to web server

Sat Apr 08, 2017 11:33 am

Hi.

With the little information supplied, you need to change the line that is doing the image saving to reflect were you want it saving.
you really need to tell us if the web server is running on the same Pi or on some other machine.
and you need to post what ever python code you have that does the picture taking.

The more information you supply the better change of getting a meaningful answer.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

mawallace
Posts: 13
Joined: Tue Mar 28, 2017 11:07 pm

Re: Pi camera with pir sensor to web server

Fri Apr 21, 2017 9:36 pm

Yes the web server is running off the PI's IP address

this is the code I have...
from gpiozero import MotionSensor
from gpiozero import Buzzer
from picamera import PiCamera
from datetime import datetime
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
buzzer_pin = 21
led_pin = 12
GPIO.setup(21, GPIO.OUT)
GPIO.setup(12, GPIO.OUT)
camera = PiCamera()
pir = MotionSensor(4)

while True:
pir.wait_for_motion()
filename = datetime.now().strftime("%Y-%m-%d_%H.%M.%S.h264")
camera.start_recording(filename)
GPIO.output(buzzer_pin, True)
GPIO.output(led_pin, True)
sleep(1)
GPIO.output(buzzer_pin, False)
pir.wait_for_no_motion()
GPIO.output(led_pin, False)
GPIO.output(buzzer_pin, True)
sleep(1)
GPIO.output(buzzer_pin, False)
camera.stop_recording()

pcmanbob
Posts: 9612
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Pi camera with pir sensor to web server

Sat Apr 22, 2017 8:29 am

To change were the file is saved you need to specify a directory in your file name.
also you filename line is incorrect there is no "now" or "strftime" attribute for datetime, and you should be using "time.strftime"

so to save the file in the /home/pi directory you would do it like this.

Code: Select all

filename = time.strftime("%Y-%m-%d_%H.%M.%S.h264")
filename = "/home/pi/" + filename
which would give you a file name

Code: Select all

/home/pi/2017-04-22_09.24.19.h264
to use a different directory just change the "/home/pi/" bit.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Return to “Python”