-
- Posts: 179
- Joined: Thu Jul 18, 2013 6:13 am
- Location: Charenteshire, France
Re: Upload a pic every minute
Well, I'm in France, the pi is watching the going's on a rented house of mine...(the mother in laws!) in the Uk.
Re: Upload a pic every minute
You might want to create a small ramdisk, maybe 50-100 meg. Have raspistill save the image to there, it will reduce the writes to your SD card.
I have had a webcam going for several years. It was a pi 2 that would copy an image every 30 seconds to another server, a pi 4 now with 1T SSD for the system. The pi 4 is called zjunk.net and you should be able to see the web page. It also hosts a Wordpress Blog of our vacations (no comments allowed) and a full email system.
The system taking photos is minimal, the script is as follows.
while [ 1 ]; do
file=view-$(/bin/date +"%F-%T").jpg
echo $file
sudo raspistill -vf -hf -n -o /ram/view.jpg
scp /ram/view.jpg zjunk.net:~/webcam/view.jpg
# scp /ram/view.jpg 192.168.1.103:~/wwwImages/$file
sleep 20
done
To prevent the scp command from asking for passwords, I have setup authorized keys file.
It runs on an internal subnet. The commented out line will also copy over a file with date and time in the filename. That is when I want to do a time-lapse series. Takes up a lot of room on the server so I only do that when a big snow storm is expected or something like that.
To just see the view,
http://zjunk.net/webcam/view.jpg
That is likely more than you wanted to know, have fun.
I have had a webcam going for several years. It was a pi 2 that would copy an image every 30 seconds to another server, a pi 4 now with 1T SSD for the system. The pi 4 is called zjunk.net and you should be able to see the web page. It also hosts a Wordpress Blog of our vacations (no comments allowed) and a full email system.
The system taking photos is minimal, the script is as follows.
while [ 1 ]; do
file=view-$(/bin/date +"%F-%T").jpg
echo $file
sudo raspistill -vf -hf -n -o /ram/view.jpg
scp /ram/view.jpg zjunk.net:~/webcam/view.jpg
# scp /ram/view.jpg 192.168.1.103:~/wwwImages/$file
sleep 20
done
To prevent the scp command from asking for passwords, I have setup authorized keys file.
It runs on an internal subnet. The commented out line will also copy over a file with date and time in the filename. That is when I want to do a time-lapse series. Takes up a lot of room on the server so I only do that when a big snow storm is expected or something like that.
To just see the view,
http://zjunk.net/webcam/view.jpg
That is likely more than you wanted to know, have fun.
-
- Posts: 179
- Joined: Thu Jul 18, 2013 6:13 am
- Location: Charenteshire, France
Re: Upload a pic every minute
Could I transfer the most recently taken pic to a pc (always on) on the local network and use that to host the webpage for exterior viewing?
Re: Upload a pic every minute
That is what I am doing, see above post. The other computer that is hosting the web site is a pi also.
-
- Posts: 179
- Joined: Thu Jul 18, 2013 6:13 am
- Location: Charenteshire, France
Re: Upload a pic every minute
ok peeps, i have upgraded to Jessie and installed Apache. I have changed my dawn to dusk time lapse script to always keep the latest image on the home/pi.
I have followed Neil's instructions and created index.html with the suggested code.
I can view the standard Apache web page when i point my pc to the rpis ip address, but no picture as yet.
How do i run the html every minute to update the web-page? crontab? what command would i use?
FYI, i can only ssh in to the pi.
Thanks in advance:-)
Steve
I have followed Neil's instructions and created index.html with the suggested code.
I can view the standard Apache web page when i point my pc to the rpis ip address, but no picture as yet.
How do i run the html every minute to update the web-page? crontab? what command would i use?
FYI, i can only ssh in to the pi.
Thanks in advance:-)
Steve
Re: Upload a pic every minute
In the <HEAD> part of the HTML put <meta http-equiv="refresh" content="60"> to get a 60 second reload. If you don't like the flash that will occur with an image there is a more sophisticated method that uses some JavaScript. Take a look at my website, http://knutejohnson.com/pi, there are a couple of examples of how to do refreshed pages for a camera or a temperature sensor.
-
- Posts: 179
- Joined: Thu Jul 18, 2013 6:13 am
- Location: Charenteshire, France
Re: Upload a pic every minute
Great, I e got it working, crontab mv the img from home to var/www/html every minute.
Now, I want to share it with others, how to secure my pi?
Now, I want to share it with others, how to secure my pi?
Re: Upload a pic every minute
Maybe UFW Uncomplicated Firewall could be of use.eccentricdyslexic wrote: ↑Sat Oct 05, 2019 10:37 pmGreat, I e got it working, crontab mv the img from home to var/www/html every minute.
Now, I want to share it with others, how to secure my pi?
It's easy to configure. Here's what I did last time I configured it.
I have added a few commands on how to use it.
sudo apt-get install ufw
sudo ufw disable
sudo ufw enable
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow from 192.168.0.0/24
sudo ufw allow 8080/tcp
sudo ufw allow https
sudo ufw status verbose
The command involving 192.168.0.0 is to allow me accessing the RPi from my network.
The 8080/tcp is to allow access to port 8080 and TCP.
And the https is to allow standard https.
/Mogens
-
- Posts: 179
- Joined: Thu Jul 18, 2013 6:13 am
- Location: Charenteshire, France
Re: Upload a pic every minute
Cool, will look into it,
Steve
Steve
Re: Upload a pic every minute
I don't know how you are getting to your remote Pi but I would be very careful with using the ufw rules from above. If you are getting to your Pi via remote ssh you will be locked out forever using those commands. If that is not the case then kindly disregard my note.
Re: Upload a pic every minute
You are right, my goal was to allow SSH from the inside and only allow https (I later removed port 8080 from outside) from the outside.knute wrote: ↑Sun Oct 06, 2019 9:04 pmI don't know how you are getting to your remote Pi but I would be very careful with using the ufw rules from above. If you are getting to your Pi via remote ssh you will be locked out forever using those commands. If that is not the case then kindly disregard my note.
I listed the commands to show how easy it was to use.
/Mogens
Re: Upload a pic every minute
I never enable ufw until after I allow ssh.
The ufw default is to drop inbounds that are not specifically allowed and to allow outbounds. I don't think you gain anything by rejecting all the inbound as it is really nice to be able to ping the server.
The ufw default is to drop inbounds that are not specifically allowed and to allow outbounds. I don't think you gain anything by rejecting all the inbound as it is really nice to be able to ping the server.
Re: Upload a pic every minute
My RPi is connected to the internet via a port forward for https, so I have no need for allowing ping, but it's a good point.
/Mogens
-
- Posts: 179
- Joined: Thu Jul 18, 2013 6:13 am
- Location: Charenteshire, France
Re: Upload a pic every minute
Thanks all, I have it working fine, but my internet connection is very very slow, the Hd pictures from raspistill take ages to upload. Can I still take the picture hd then scale it down before sending it to the folder where apache picks it up from?
Cheers
Steve
Cheers
Steve
Re: Upload a pic every minute
If you don't have need for the hifi image you can have raspistill scale it for you. See the -width and -height command line options. If you want to keep the hifi images on the Pi and serve the lores image you can scale them with another program. I've written simple Java programs to scale images.
-
- Posts: 179
- Joined: Thu Jul 18, 2013 6:13 am
- Location: Charenteshire, France
Re: Upload a pic every minute
Yes I’d like to keep the hi res for the timelapse so your idea sounds good, what js did you use?
Steve
Steve
Re: Upload a pic every minute
eccentricdyslexic wrote: ↑Tue Nov 05, 2019 8:04 pmYes I’d like to keep the hi res for the timelapse so your idea sounds good, what js did you use?
Steve
Code: Select all
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
public class ScaleImage {
public static void main(String... args) throws Exception {
System.out.println("ScaleImage");
if (args.length != 3) {
System.out.println(
"usage: java ScaleImage.java srcFile dstFile WxH");
System.exit(0);
}
File src = new File(args[0]);
File dst = new File(args[1]);
String[] dim = args[2].split("x");
int width = Integer.parseInt(dim[0]);
int height = Integer.parseInt(dim[1]);
System.out.printf("Source File: %s%n",src.getName());
System.out.printf("Destination File: %s%n",dst.getName());
System.out.printf("Dimensions: W=%d x H=%d%n",width,height);
BufferedImage srcImage = ImageIO.read(src);
BufferedImage dstImage = new BufferedImage(width,height,
BufferedImage.TYPE_INT_RGB);
Graphics2D g = dstImage.createGraphics();
g.drawImage(srcImage,0,0,width,height,null);
g.dispose();
ImageIO.write(dstImage,"JPEG",dst);
}
}
-
- Posts: 179
- Joined: Thu Jul 18, 2013 6:13 am
- Location: Charenteshire, France
Re: Upload a pic every minute
So.... I need to install java on the pi and replace string...args with “latest image.jpg”, 1200x740 ?
Re: Upload a pic every minute
Yes you need to install Java (openjdk-11-jdk). The program is a command line program. You run it with the java command, the name of the Java file and the arguments.
java ScaleImage.java sourceFile destFile WxH
WxH is the width and height separated by a lower case 'x'. In your case 1200 by 740 would be 1200x740.
If you run it from cron then you need good paths to the argument files names. The java command will be available to cron if you installed the jdk correctly.
If you want to write image types other than JPEG you will need to modify the code. It should read BMP, PNG and JPEG files.
java ScaleImage.java sourceFile destFile WxH
WxH is the width and height separated by a lower case 'x'. In your case 1200 by 740 would be 1200x740.
If you run it from cron then you need good paths to the argument files names. The java command will be available to cron if you installed the jdk correctly.
If you want to write image types other than JPEG you will need to modify the code. It should read BMP, PNG and JPEG files.
Re: Upload a pic every minute
I would just use imagemagik to resize the current image - no java or perl (better) needed.
-
- Posts: 179
- Joined: Thu Jul 18, 2013 6:13 am
- Location: Charenteshire, France
Re: Upload a pic every minute
Before I go js I am trying convert -resize 1000x700
Will let you know tomorrow if it works:-)
Will let you know tomorrow if it works:-)