eccentricdyslexic
Posts: 157
Joined: Thu Jul 18, 2013 6:13 am
Location: Uttoxeter, Staffordshire, UK

Re: Upload a pic every minute

Wed Sep 18, 2019 9:14 pm

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.

markatlnk
Posts: 54
Joined: Sun Feb 23, 2014 7:53 pm

Re: Upload a pic every minute

Sun Sep 22, 2019 1:00 am

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.

eccentricdyslexic
Posts: 157
Joined: Thu Jul 18, 2013 6:13 am
Location: Uttoxeter, Staffordshire, UK

Re: Upload a pic every minute

Sun Sep 22, 2019 7:58 am

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?

markatlnk
Posts: 54
Joined: Sun Feb 23, 2014 7:53 pm

Re: Upload a pic every minute

Sun Sep 22, 2019 1:27 pm

That is what I am doing, see above post. The other computer that is hosting the web site is a pi also.

eccentricdyslexic
Posts: 157
Joined: Thu Jul 18, 2013 6:13 am
Location: Uttoxeter, Staffordshire, UK

Re: Upload a pic every minute

Sat Oct 05, 2019 9:14 pm

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

knute
Posts: 503
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: Upload a pic every minute

Sat Oct 05, 2019 9:59 pm

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.

eccentricdyslexic
Posts: 157
Joined: Thu Jul 18, 2013 6:13 am
Location: Uttoxeter, Staffordshire, UK

Re: Upload a pic every minute

Sat Oct 05, 2019 10:37 pm

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?

deepo
Posts: 436
Joined: Sun Dec 30, 2018 8:36 pm
Location: Denmark

Re: Upload a pic every minute

Sun Oct 06, 2019 4:07 pm

eccentricdyslexic wrote:
Sat Oct 05, 2019 10:37 pm
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?
Maybe UFW Uncomplicated Firewall could be of use.
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

eccentricdyslexic
Posts: 157
Joined: Thu Jul 18, 2013 6:13 am
Location: Uttoxeter, Staffordshire, UK

Re: Upload a pic every minute

Sun Oct 06, 2019 6:24 pm

Cool, will look into it,

Steve

knute
Posts: 503
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: Upload a pic every minute

Sun Oct 06, 2019 9:04 pm

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.

deepo
Posts: 436
Joined: Sun Dec 30, 2018 8:36 pm
Location: Denmark

Re: Upload a pic every minute

Tue Oct 08, 2019 7:48 pm

knute wrote:
Sun Oct 06, 2019 9:04 pm
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.
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.
I listed the commands to show how easy it was to use.

/Mogens

knute
Posts: 503
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: Upload a pic every minute

Wed Oct 09, 2019 2:22 am

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.

deepo
Posts: 436
Joined: Sun Dec 30, 2018 8:36 pm
Location: Denmark

Re: Upload a pic every minute

Wed Oct 09, 2019 6:22 am

knute wrote:
Wed Oct 09, 2019 2:22 am
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.
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

eccentricdyslexic
Posts: 157
Joined: Thu Jul 18, 2013 6:13 am
Location: Uttoxeter, Staffordshire, UK

Re: Upload a pic every minute

Tue Nov 05, 2019 2:33 pm

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

knute
Posts: 503
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: Upload a pic every minute

Tue Nov 05, 2019 7:44 pm

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.

eccentricdyslexic
Posts: 157
Joined: Thu Jul 18, 2013 6:13 am
Location: Uttoxeter, Staffordshire, UK

Re: Upload a pic every minute

Tue Nov 05, 2019 8:04 pm

Yes I’d like to keep the hi res for the timelapse so your idea sounds good, what js did you use?
Steve

knute
Posts: 503
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: Upload a pic every minute

Wed Nov 06, 2019 12:28 am

eccentricdyslexic wrote:
Tue Nov 05, 2019 8:04 pm
Yes 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);
    }
}


eccentricdyslexic
Posts: 157
Joined: Thu Jul 18, 2013 6:13 am
Location: Uttoxeter, Staffordshire, UK

Re: Upload a pic every minute

Wed Nov 06, 2019 8:41 am

So.... I need to install java on the pi and replace string...args with “latest image.jpg”, 1200x740 ?

knute
Posts: 503
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: Upload a pic every minute

Fri Nov 08, 2019 3:13 pm

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.

User avatar
neilgl
Posts: 1600
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: Upload a pic every minute

Fri Nov 08, 2019 11:07 pm

I would just use imagemagik to resize the current image - no java or perl (better) needed.

eccentricdyslexic
Posts: 157
Joined: Thu Jul 18, 2013 6:13 am
Location: Uttoxeter, Staffordshire, UK

Re: Upload a pic every minute

Fri Nov 08, 2019 11:26 pm

Before I go js I am trying convert -resize 1000x700
Will let you know tomorrow if it works:-)

Return to “General discussion”