ftp causing invalid syntax

No matter, as I am going to remove shortly

Reply to
RobH
Loading thread data ...

I'm not sure what you mean about RAMname and NASName

RAMname = os.path.join("/run/shm", fname) NASname = os.path.join("/mnt/CCTV/PiZero" , fname)

Oops it was a typo, and is and should be PiZero

On my Ubuntu machine I open file manager or whatever it is called, the other locations and smb to my NAS box. From there I select the dataset or folder, which in this case is PiZero. When I have finished doing what I want I then close down file manager. So I view my NAS box in file manager

Reply to
RobH

I just tried the script again and it is now failing with Permissions denied again, aargh!!!

pi@raspberrypi:~/Downloads $ python intruder.py Traceback (most recent call last): File "intruder.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-06-15_17.23.59.h264'

The permissions for all the directories have not changed.

The shutil line was not commented out in this case.

I commented the shutil line again and ran the script. This time no errors and a 0 byte file was created on both the PiZero and my NAS box PiZero directory.

A strange thing is that selecting properties of a video file says it is

0 bytes, but in the bottom bar of file mangler, it says it is 5.1 MiB.
Reply to
RobH

On Fri, 15 Jun 2018 16:06:07 +0100, RobH declaimed the following:

My full suggestion was to change the camera capture statement (which was using RAMname) to directly use NASname. THEN comment out the shutil.copyfile() and the unlink() -- since the camera is no longer creating the local RAM data file.

As long as the network speed is fast enough, those changes would mean the capture file is directly generated in the NAS (or the camera capture itself will fail with permission problems -- again, ignoring the script, unless you can copy files from your home directory to /mnt/CCTV/PiZero without getting an error, the script is not going to succeed.

--
	Wulfraed                 Dennis Lee Bieber         AF6VN 
	wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/
Reply to
Dennis Lee Bieber

I have done a couple of changes to the script earlier, as I did a bit of reading about shutil and moving files.

src = join('/', RAMname) #new lines here dst = join('/', NASname)

The script has been running for about 2 hours with no errors, and only a

0 byte file moved over the the NAS box.

I commented those 2 lines out and used this as you have suggested:

#camera.start_recording(RAMname) camera.start_recording(NASname)

#shutil.copyfile(RAMname, NASname)

#os.unlink(RAMname)

Is that what you meant, above.

Running the script now produces:

pi@raspberrypi:~/Downloads $ python intruder.py Traceback (most recent call last): File "intruder.py", line 37, in camera.start_recording(NASname) File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line

1049, in start_recording encoder.start(output, options.get('motion_output')) File "/usr/lib/python2.7/dist-packages/picamera/encoders.py", line 812, in start super(PiVideoEncoder, self).start(output) File "/usr/lib/python2.7/dist-packages/picamera/encoders.py", line 375, in start self._open_output(output) File "/usr/lib/python2.7/dist-packages/picamera/encoders.py", line 331, in _open_output self.outputs[key] = mo.open_stream(output) File "/usr/lib/python2.7/dist-packages/picamera/mmalobj.py", line 344, in open_stream stream = io.open(stream, 'wb' if output else 'rb', buffering) IOError: [Errno 13] Permission denied: '/mnt/CCTV/PiZero/2018-06-15_23.04.43.h264'

I have done a bit of reading up on shutil

formatting link

and have tried this

src = join('/', RAMname) #new lines here dst = join('/', NASname)

I realise that the modification may well only guess work, but it doesn't produce errors.

The script runs without errors, but again the files produced from the script are only 0 bytes in size on my NAS box, and no files were written to the PIZero.

On the question of moving or transferring files from the PiZero to my NAS box, I can move the test junk file over, so that part seems to work ok.

Reply to
RobH

This!

Reply to
mm0fmf

What happens if you manually try

echo "hello" > /mnt/CCTV/PiZero/test.txt

does the file get created? zero bytes long?

Reply to
Andy Burns

Going from the GUI to the command line (guessing but it seems likely) is quite a transition, instead of a guided environment you have a big box of small tools that can do amazing things once you know how they all work (or at least many of them) and can be combined. Without some sort of guide it is easy to get lost in the woods.

--
Steve O'Hara-Smith                          |   Directable Mirror Arrays 
C:\>WIN                                     | A better way to focus the sun 
The computer obeys and wins.                |    licences available see 
You lose and Bill collects.                 |    http://www.sohara.org/
Reply to
Ahem A Rivet's Shot

???

Reply to
RobH

Yes, that file was created and sent to my NAS box, and says hello.

Reply to
RobH

I am going to get the linux for dummies book and have a play around.

Reply to
RobH

If you can write a file, the script ought to manage it too, do you want to post the current version of it?

Reply to
Andy Burns

Current version of what, the code ?

Reply to
RobH

yes, unless it's huge ...

Reply to
Andy Burns

As you look down through the code, you will see what I have added by something like this: < I added this, < and this I was just trying different things which I read about the shutil module

CODE: from picamera import PiCamera import time import os import os.path import shutil from os.path import join < I added this

src = ("RAMname")< and this dst = ("NASname")< this

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-%m-%d_%H.%M.%S.h264", time.localtime(triggerTime))

RAMname = os.path.join("/run/shm", fname) NASname = os.path.join("/mnt/CCTV/PiZero" , fname)

camera.start_preview()

#capture video to RAM device first camera.start_recording(RAMname) camera.wait_recording(10) camera.stop_recording() camera.stop_preview()

#copy from RAM device to NAS device #shutil.copyfile(RAMname, NASname)

Reply to
RobH

On Sat, 16 Jun 2018 12:49:30 +0100, RobH declaimed the following:

Why? Was typing os.path.join too much effort?

These lines do nothing useful since you never use the names src and dst later (except to replace the contents and again not use them)

I suggested trying NASname in that call, to directly capture to the end device rather than buffering in RAM first and then copying. If that fails, then the problem is not inherent to the script but is something wrong in the environment. RAMname (and later the shutil copyfile) was proposed to let the RPi capture to RAM without the overhead of network traffic (given that the network interface of an RPi is via the USB system)

Similarly, these do nothing useful since "src" and "dst" are never referenced in the code... And what they are doing is just trying to add another / to the front of the names generated earlier. But since / is the path separator in Linux, and .join() puts the components together by putting a path separator between them...

-=-=-=-=-

'2018-06-16_08.45.24.h264'

'/mnt/CCTV/PiZero/2018-06-16_08.45.24.h264'

'/mnt/CCTV/PiZero/2018-06-16_08.45.24.h264'

True

-=-=-=-=-

... there is no effect

I also asked you to comment that out... Since if the capture is going to NASname, there is no file in RAMname to be deleted

While picking up that beginners book on Linux, pick up a book on Python also...

--
	Wulfraed                 Dennis Lee Bieber         AF6VN 
	wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/
Reply to
Dennis Lee Bieber

Great plan - I think you'll like the tools it shows you once you get the hang of them - it's like the difference between Meccano and a kit that only makes one thing.

--
Steve O'Hara-Smith                          |   Directable Mirror Arrays 
C:\>WIN                                     | A better way to focus the sun 
The computer obeys and wins.                |    licences available see 
You lose and Bill collects.                 |    http://www.sohara.org/
Reply to
Ahem A Rivet's Shot

No it wasn't actually, as I said in another reply on here, I have been reading up on the shutil module, and I thought to try some of the examples I looked at.

No I have removed them now

Ok , I've removed them

Yes I did do that last night, but there was some sort of error. I can't recall it now as it was late.

I have now commented out what you asked me to and also:

camera.start_recording(NASname)

The script is running without errors, and producing video files of around 5 or 6MiB on the PiZero, but nothing of todays date on the NAS box. So the script is producing the files but not moving/copying them accross to the NAS box

Reply to
RobH

No the script didn't run very long, as it produced this error which I now recall from last night.

pi@raspberrypi:~/Downloads $ python intruder.py Traceback (most recent call last): File "intruder.py", line 36, in camera.start_recording(NASname) File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line

1049, in start_recording encoder.start(output, options.get('motion_output')) File "/usr/lib/python2.7/dist-packages/picamera/encoders.py", line 812, in start super(PiVideoEncoder, self).start(output) File "/usr/lib/python2.7/dist-packages/picamera/encoders.py", line 375, in start self._open_output(output) File "/usr/lib/python2.7/dist-packages/picamera/encoders.py", line 331, in _open_output self.outputs[key] = mo.open_stream(output) File "/usr/lib/python2.7/dist-packages/picamera/mmalobj.py", line 344, in open_stream stream = io.open(stream, 'wb' if output else 'rb', buffering) IOError: [Errno 13] Permission denied: '/mnt/CCTV/PiZero/2018-06-16_15.03.02.h264'

I have just checked all the mounted directories, and they are all owned by pi:pi and have appropriate permissions.

Reply to
RobH

Adendum:

The script as it is now runs for about 10 seconds and falls down with a permission error. It also produces 0 byte files on the NAS box, but no files on the PiZero now.

Reply to
RobH

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.