Ok I misunderstood what you meant about the script, so you to save the picture on or to a local directory
This is the script I was supplied with,and where and how would save the video, as it is now, to a local directory. I imagine that the may well be an alteration or 2
from picamera import PiCamera import time import os import os.path import shutil
from gpiozero import MotionSensor #According to google motionsensor is in gpiozero
# Create object for PIR Sensor # PIR Sensor is on GPIO-4 (Pin 7) pir = MotionSensor(4)
# Create Object for Camera camera = PiCamera()
while True: # Wait for motion being detected pir.wait_for_motion() triggerTime = time.time()
#create base filename at time of motion trigger fname = time.strftime("%Y-%d-%d_%H.%M.%S.h264", time.localtime(triggerTime))
My yard light won't go off any more. I block the detector wait 60 seconds...
R
RobH
Well I tried the mkdir Public/myFakeNAs and it worked this time! I have no idea as to why it didn't before.
Presently the NASname = os.path.join("/mnt/CCTV/PiZero" , fname)
After running the script and a picture shows up on the monitor, it does not get saved to the /CCTV/PiZero directory, nor on my NAS box.
I realise there is something else I have to do but not sure what.
I think this was answered before, but as there are many posts on this thread, I can't find it just now.
Thanks
R
RobH
I found the post I was after and I added //NAS at the beginning of the line
pi@raspberrypi:~ $ sudo mount //NAS/CCTV/PiZero /mnt/CCTV/PiZero Password for root@//NAS/CCTV/PiZero: ********* mount error(115): Operation now in progress Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
Here I used the PiZero password.
Then I tried this:
pi@raspberrypi:~ $ sudo mount -t cifs -o username=root,password=****** //NAS/CCTV/PiZero /mnt/CCTV/PiZero mount error(115): Operation now in progress Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) pi@raspberrypi:~ $
Here I used both password and username for my NAS box
I did have a look at that page and to be hones, I am no wiser.
B
Björn Lundin
this seems close to what you want. BUT //NAS ? can you reach the nas from the PI via the nasme 'NAS'?
try ping NAS
if it comes back saying it does not recognize the name then try to swap NAS for its ip-address
The ip address here is not mine but some other somewhere.
pi@raspberrypi:~ $ ping NAS PING NAS (92.242.132.24) 56(84) bytes of data.
64 bytes from unallocated.barefruit.co.uk (92.242.132.24): icmp_seq=4 ttl=247 time=26.1 ms
64 bytes from unallocated.barefruit.co.uk (92.242.132.24): icmp_seq=5 ttl=247 time=24.1 ms
64 bytes from unallocated.barefruit.co.uk (92.242.132.24): icmp_seq=6 ttl=247 time=17.4 ms
64 bytes from unallocated.barefruit.co.uk (92.242.132.24): icmp_seq=7 ttl=247 time=20.4 ms
64 bytes from unallocated.barefruit.co.uk (92.242.132.24): icmp_seq=8 ttl=247 time=21.2 ms ^C
--- NAS ping statistics ---
8 packets transmitted, 5 received, 37% packet loss, time 7133ms rtt min/avg/max/mdev = 17.448/21.908/26.191/3.026 ms
This my NAS box and pinging the correct IP address Actually the real name of my NAS box is FreeNAS, but using that did not make difference to the above
64 bytes from 192.168.0.22: icmp_seq=1 ttl=64 time=2.03 ms
64 bytes from 192.168.0.22: icmp_seq=2 ttl=64 time=1.02 ms
64 bytes from 192.168.0.22: icmp_seq=3 ttl=64 time=0.989 ms
64 bytes from 192.168.0.22: icmp_seq=4 ttl=64 time=0.960 ms
64 bytes from 192.168.0.22: icmp_seq=5 ttl=64 time=0.989 ms
64 bytes from 192.168.0.22: icmp_seq=6 ttl=64 time=1.04 ms
64 bytes from 192.168.0.22: icmp_seq=7 ttl=64 time=0.986 ms
64 bytes from 192.168.0.22: icmp_seq=8 ttl=64 time=0.992 ms ^C
--- 192.168.0.22 ping statistics ---
8 packets transmitted, 8 received, 0% packet loss, time 7009ms rtt min/avg/max/mdev = 0.960/1.127/2.031/0.345 ms pi@raspberrypi:~ $
D
Dennis Lee Bieber
On Sat, 19 May 2018 09:39:50 +0100, RobH declaimed the following:
"/CCTV/PiZero" is not the same directory as "/mnt/CCTV/PiZero"
With the script as I provided it, the first place the video file should appear is that "shared memory" RAM; it should then be copied (the shutil line) to "/mnt/CCTV/PiZero"
It will only appear on the NAS box if you've managed a successful "mount ..." command.
Put a # in front of the os.unlink() line; that will keep it from deleting the RAM copy.
~15 seconds after you see a preview, execute (at the console prompt -- you may want to open a second console connection so the script can run in one console while you explore using the second): ls /run/shm {Hmmm, Debian Stretch in a virtual instance is using /dev/shm rather than /run/shm -- I shouldn't spend the time but I'm going to dig out my RPi to check.
... but the "Ubuntu BASH shell on Windows" is using /run/shm (and not in RAM either). I'm sure someone else on the thread suggested /run/shm; google searches imply that /run/shm is the new standard name, but it appears Debian hasn't changed from /dev/shm yet.
On your RPi, execute: df and look for either /run/shm or /dev/shm
If you find it is /dev/shm change the line in the script from
RAMname = os.path.join("/run/shm", fname)
to
RAMname = os.path.join("/dev/shm", fname)
I'm surprised the script didn't dump a traceback on a non-exist ant path if this is the case... Maybe the camera library is catching the error and just silently not doing the capture.
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
D
Dennis Lee Bieber
On Sat, 19 May 2018 10:08:03 +0100, RobH declaimed the following:
This is where you want the IP# of your NAS device, unless you have a DNS system that knows what machine "NAS" refers to...
Suggest rebooting the RPi to clean up any partial mount operations before starting again...
It took me a few attempts but I opened up a directory on my Windows box for network sharing. Had to add my admin account to the share (my user account does not have a password, but the mount command fails if I don't provide one).
Again -- all path names are for MY systems, don't take them literally; I'm doing these just to show functioning examples!
Create mount point directory on local machine pi@raspberrypi:~$ ls /media pi pi@raspberrypi:~$ sudo mkdir /media/Shared
Attempt to mount fails as Windows machine is not in any DNS lookup pi@raspberrypi:~$ sudo mount -t cifs //ElusiveUnicorn/VB_Shared /media/Shared -o username=wulfraed mount error: could not resolve address for ElusiveUnicorn: Unknown error
Using IP address; fails since my user account does not have a password to send pi@raspberrypi:~$ sudo mount -t cifs //192.168.2.109/VB_Shared /media/Shared -o username=wulfraed Password for wulfraed@//192.168.2.109/VB_Shared: mount error(13): Permission denied Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
After adding "root" (my Windows admin account, which does have a password) to the share (on Windows) (without adding that account to the share users I get no-permissions errors) pi@raspberrypi:~$ sudo mount -t cifs //192.168.2.109/VB_Shared /media/Shared -o username=root Password for root@//192.168.2.109/VB_Shared: **********
No error, display the contents of the shared directory pi@raspberrypi:~$ sudo ls /media/Shared/ BabaYagaHut.bmp cache code_1.16.0-1504714880_amd64.deb slrn.rc VB_share_permissions.txt BabaYagaHut.png cache.c myTest.dat so.py pi@raspberrypi:~$
Needed "sudo" since I didn't chown the mount to my RPi user. (Strange
-- the same sequence on my BBB is giving a "host is down" on the attempt to mount)
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
R
RobH
Password for root@//NAS/CCTV/PiZero: ********* mount error(115): Operation now in progress Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
Password for root@//NAS/CCTV/PiZero: ********* mount error(115): Operation now in progress Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
Password for root@//NAS/CCTV/PiZero: ********* mount error(115): Operation now in progress Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
First I mounted : pi@raspberrypi:~ $ sudo mount //NAS/CCTV/PiZero /mnt/CCTV/PiZero Password for root@//NAS/CCTV/PiZero: ********* mount error(115): Operation now in progress Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
Then put a # infront of os.unlink
I then ran the python script:
pi@raspberrypi:~ $ python intruder_recmotion.py Traceback (most recent call last): File "intruder_recmotion.py", line 37, in pi@raspberrypi:~ $ shutil.copyfile(RAMname, NASname) File "/usr/lib/python2.7/shutil.py", line 83, in copyfile with open(dst, 'wb') as fdst: IOError: [Errno 13] Permission denied: '/mnt/CCTV/PiZero/2018-19-19_17.43.42.h264'
Whilst the script was running, ie 15 seconds after the video, I then ran
It very well looks like the files are created, but where to.
B
Björn Lundin
so - use 192.168.0.22 - NOT NAS
--
D
Dennis Lee Bieber
On Sat, 19 May 2018 17:54:28 +0100, RobH declaimed the following:
Unless you know for certain that the name NAS resolves to YOUR NAS device, you should probably be using YOUR IP# there.
No... You ATTEMPTED to mount it -- the mount did not complete successfully; likely because the name NAS is not pointing to your device but to something defined somewhere else (and how it is visible to your network I have no idea).
Expected if you have a partial mount success -- that is, it thinks it is mounted, but you have no privileges to do anything on that location.... OR: the non-mounted directory is not writable by your user account. Try running
sudo chown pi:pi /mnt/CCTV/PiZero
and maybe for safety also
sudo chown pi:pi /mnt/CCTV
Interesting -- it appears that your system sees /run/shm and /dev/shm as the same location.
Those files are located in a shared RAM(disk) -- which is why you'll want the unlink() statement once the mount works. Though why you show files going back three days if they are in RAM I don't know -- Unless you haven't rebooted the system in all that time, and my script was silently dying on the copyfile() so the unlink() never ran. The unlink() is supposed to delete the temporary file from RAM after it is copied to /mnt/whatever...
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
R
RobH
Password for root@//192.168.0.22/CCTV/PiZero: ****** pi@raspberrypi:~ $
Ok, I think I am getting somewhere now.
I did sudo chown pi:pi /mnt/CCTV/PiZero and sudo chown pi:pi /mnt/CCTV
Then I: pi@raspberrypi:~ $ sudo mount //192.168.0.22/CCTV/PiZero /mnt/CCTV/PiZero Password for root@//192.168.0.22/CCTV/PiZero: ****** pi@raspberrypi:~ $
No error messages of any kind now, so in the script you provided, where or what should I change to incorporate FreeNAS ip address.
Regarding the files going back 3 days, no I have not rebooted the Pi Zero at all, so that is maybe the reason why.
Thanks
>
D
Dennis Lee Bieber
On Sun, 20 May 2018 19:00:49 +0100, RobH declaimed the following:
NOTHING...
The "mount" command is what linked your FreeNAS directory to a directory on the RPI... The RPI only has to put files into what looks to it like just another local directory. And if you haven't changed anything, that should be /mnt/CCTV/PiZero
If the "copyfile" was failing because of the bad mount point, the program wouldn't have executed the unlink() calls.
You might want to clear out that region before you run out of RAM
rm /dev/shm/*.h264 or rm /run/shm/*.h264
since it seems both paths were the same on your system.
Once you see files appear in /mnt/CCTV/PiZero then verify externally that the NAS shows them... Then restore the unlink() statement in the script (and empty /dev/shm again -- if the script is running without problems it should be removing the RAM files after they get copied to the NAS mount point.
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
R
RobH
I mounted the directory again:
pi@raspberrypi:~ $ sudo mount //192.168.0.22/CCTV/PiZero /mnt/CCTV/PiZero -o username=root,password=******
Then I ran the python script:
pi@raspberrypi:~ $ python intruder_recmotion.pyTraceback (most recent call last): File "intruder_recmotion.py", line 37, in shutil.copyfile(RAMname, NASname) File "/usr/lib/python2.7/shutil.py", line 83, in copyfile with open(dst, 'wb') as fdst: IOError: [Errno 13] Permission denied: '/mnt/CCTV/PiZero/2018-20-20_20.02.21.h264'
Then :
pi@raspberrypi:~ $ rm /run/shm/*.h264 pi@raspberrypi:~ $ rm /dev/shm/*.h264 rm: cannot remove '/dev/shm/*.h264': No such file or directory pi@raspberrypi:~ $
B
Björn Lundin
great. before fiddling with the script try this
echo "test" > /mnt/CCTV/PiZero/test.txt
check on you nas if you see the file at CCTC/piZero if you do - then try the script
if you get permission denied, try
sudo echo "test" > /mnt/CCTV/PiZero/test.txt
check again.
if ok (you see in in the nas) remove the file with
what does ls -la /mnt/CCTV/PiZero say? (run the command and paste its output here)
--
R
RobH
pi@raspberrypi:~ $ ls -ls /mnt/CCTV/PiZero total 7
1 -rw-r--r-- 1 pi pi 0 May 21 11:50 2018-050-21_11.50.09.h264
1 -rw-r--r-- 1 pi pi 0 May 22 09:46 2018-050-22_09.46.39.h264
1 -rw-r--r-- 1 pi pi 0 May 22 09:51 2018-050-22_09.51.12.h264
1 -rw-r--r-- 1 pi pi 0 May 22 11:35 2018-050-22_11.34.55.h264
1 -rw-r--r-- 1 root pi 0 May 22 11:44 2018-050-22_11.44.02.h264
1 -rw-r--r-- 1 root pi 0 May 22 11:46 2018-050-22_11.46.02.h264
1 -rw-r--r-- 1 pi pi 0 May 19 17:31 2018-19-19_17.31.32.h264
1 -rw-r--r-- 1 pi pi 0 May 19 17:40 2018-19-19_17.40.13.h264
1 -rw-r--r-- 1 pi pi 0 May 19 17:43 2018-19-19_17.43.42.h264
1 -rw-r--r-- 1 pi pi 0 May 20 19:02 2018-20-20_19.01.50.h264
1 -rw-r--r-- 1 pi pi 0 May 20 19:08 2018-20-20_19.08.38.h264
1 -rw-r--r-- 1 pi pi 0 May 20 20:02 2018-20-20_20.02.21.h264
1 -rw-r--r-- 1 pi pi 0 May 20 20:51 2018-20-20_20.51.49.h264 pi@raspberrypi:~ $
M
Mike
You might want to change that root password now you've just posted it.
--------------------------------------+------------------------------------
Mike Brown: mjb[-at-]signal11.org.uk | http://www.signal11.org.uk
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required
Report Content
You are reporting this content to the moderators. They will look at it
ASAP.