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

Upload a pic every minute

Tue Sep 17, 2019 6:16 am

Hi, I have a rpi that takes a pic every minute from sunrise to sunset, makes a video of it and uploads it to Dropbox.
What I'd like to do now is to upload those pics as a live webcam stream somehow as they are taken as the rpi is not doing anything during the day other than taking pictures.
Any suggestions how to do this?
Cheers
Steve

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

Re: Upload a pic every minute

Tue Sep 17, 2019 10:46 am

We could use raspistill (thanks to @6by9 and @mikerr) to link the most recently taken image to "new.jpg". We can then host a webserver on the pi with a page showing new.jpg and having a javascript refesh every minute. Look at that page from anywhere to see the latest image.
e.g use raspistill timelapse to grab images, one per minute for an hour:

Code: Select all

raspistill -n -o image_%04d.jpg -tl 60000 -l new.jpg -t 3600000 &

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

Re: Upload a pic every minute

Tue Sep 17, 2019 11:12 am

The time lapse currently saves pic hd pics throughout the day. I could run a crontab to run every minute, find the latest image, upload it or somehow host it locally.

User avatar
graysky
Posts: 93
Joined: Fri Apr 05, 2013 11:43 am
Location: /run/user/1000
Contact: Website

Re: Upload a pic every minute

Tue Sep 17, 2019 11:36 am

Do you need/want to save each pic or just overwrite? I am assuming your pi user has a passwordless key for ssh connections to your webhost and the correct permissions to read/write files on the webhost. You could create a simple script that takes the pic then sends to the webhost and then have a systemd timer or cron entry trigger it:

Code: Select all

#!/bin/bash

<command to take a single pic>
rsync -a /path/to/pic.jpg user@host:/path/to/webshare/filename.jpg

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

Re: Upload a pic every minute

Tue Sep 17, 2019 12:53 pm

The pics are taken and stored in the root of pi/home(not pretty but functional) as the day progresses, the folder fills up. That's all fine, but I'd like to do more with the pics as they are produced, like be able to view the current one on a webpage.
I don't want to do anything with the actual image because at sunset, all the images are used and then deleted once the timeplapse video has been made from them and uploaded

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

Re: Upload a pic every minute

Tue Sep 17, 2019 1:01 pm

Sorry I did not explain it very well. The example I gave will create a folder full of images (one every minute) and also links the latest image to "new.jpg". So we can just use new.jpg every time; it will show the latest image. And the video creation will still work.
Is your existing timelapse using raspistill or something else?

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

Re: Upload a pic every minute

Tue Sep 17, 2019 1:15 pm

Thanks Neil for your help.
The time lapse uses the raspistill command from a python script.
The name of the latest photo changes as the day progresses with an appreciating number at the end. Ie pic1.jpg, pic2.jpg etc
How can one then display the latest image on a webpage?
Cheers
Steve

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

Re: Upload a pic every minute

Tue Sep 17, 2019 3:05 pm

eccentricdyslexic wrote:
Tue Sep 17, 2019 1:15 pm
How can one then display the latest image on a webpage?
Cheers
Steve
Just send the image file to the webserver. Do you want your Pi to be the webserver or is it to be remote? If it is local you can just copy the file to the appropriate directory, if remote you can send the photos via FTP or some other scheme.

Until lightning took it offline, there was a camera running on Silver Peak in California that sent a photo via FTP to a Pi in Bishop. There was also a SCADA unit running on Silver Peak that kept track of temperatures and voltage levels in the facility. That also sent data to the Pi in Bishop via UDP packet. In the Pi there was software that created a new image with photo and SCADA data on the bottom and that was then sent via FTP to the radio club website. The webpage was created with auto reload so you could sit there all day and watch what was happening up on the mountain.

So I think that answers your question but if it doesn't ask again.

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

Re: Upload a pic every minute

Tue Sep 17, 2019 3:40 pm

I'd rather the pi act as a webserver, so as not too use all my bandwidth (internet very poor here).
Any good guides to setting up a webserver?

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

Re: Upload a pic every minute

Tue Sep 17, 2019 3:45 pm

OK so update that raspistill command and add the

Code: Select all

-l new.jpg
Now you will get new.jpg in your pictures folder. And, it always respresents the latest image so we can use it and its name does not change.
That makes it easier to create a web page on your pi, or upload that file (new.jpg) regularly to some other web server.
Here is a simple web page (index.html) for that:

Code: Select all

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Show latest picture</title>
  <body>
    <h1>Show new.jpg</h1>
    <a href="new.jpg">new.jpg</a>
  </body>
</html>
Create index.html in /home/pi where your pictures are, open it by double clicking it from File Manager. It opens Chromium, click the link and you will see new.jpg. (assuming you have run the new raspistill.

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

Re: Upload a pic every minute

Tue Sep 17, 2019 3:47 pm

pi as webserver - see https://www.raspberrypi.org/documentati ... /apache.md. You won't need the PHP stuff for now.
Later if you want to connect that to the actual internet, you will need better security than that article shows.

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

Re: Upload a pic every minute

Tue Sep 17, 2019 6:02 pm

I'm getting an error about not able to authenticate packages with apache2, will try an upgrade tomorrow after it's up,loaded today's time lapse.
Thing is, i can't change the raspi setting as it's part of the time lapse script. If I change it, it will break my script:-(

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

Re: Upload a pic every minute

Tue Sep 17, 2019 8:38 pm

eccentricdyslexic wrote:
Tue Sep 17, 2019 3:40 pm
I'd rather the pi act as a webserver, so as not too use all my bandwidth (internet very poor here).
Any good guides to setting up a webserver?
sudo apt install apache2 apache2-doc

Now you have a web server. Follow neilgl's fine instructions for creating a web page document. Put that in /var/www/html and copy the new.jpg file in there when you get a new one.

That's it, pretty simple.

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

Re: Upload a pic every minute

Wed Sep 18, 2019 8:27 am

Can you post that time lapse script here?
Also, there may be other ways to do it - just look for the most recent image in a directory and upload it / show it on a web page.
e.g this gets the most recent jpg in the directory

Code: Select all

ls -tr image*.jpg | tail -1

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:20 am

I can post the whole script if anyone wants it, but this is the raspistill line-

Code: Select all

os.system("raspistill -o /home/pi/image%s.jpg"%(imageNumber)) # -rot 270 need for cam on side

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

Re: Upload a pic every minute

Wed Sep 18, 2019 10:53 am

ok so can you make a backup of it, then change that line to:

Code: Select all

os.system("raspistill -l /home/pi/new.jpg -o /home/pi/image%s.jpg"%(imageNumber)) 

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 11:37 am

Ok, will do. I then have another exact copy of my usual image called new, over written every cycle?

Now, if I could just get Apache to install...grrr!

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

Re: Upload a pic every minute

Wed Sep 18, 2019 11:43 am

Yes new.jpg
Apache2 - have you done the

Code: Select all

sudo apt update
sudo apt upgrade
sudo apt install -y apache2

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 12:11 pm

yes, apt-get you mean?

i get -

After this operation, 4,631 kB of additional disk space will be used.
WARNING: The following packages cannot be authenticated!
libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap apache2.2-bin
apache2-utils apache2.2-common apache2-mpm-worker apache2 ssl-cert
E: There are problems and -y was used without --force-yes

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 2:42 pm

Looks like i have to upgrade to Jessie...hope it doesn't break things... either that or skip hosting and upload the pic every minute..

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

Re: Upload a pic every minute

Wed Sep 18, 2019 3:02 pm

eccentricdyslexic wrote:
Wed Sep 18, 2019 2:42 pm
Looks like i have to upgrade to Jessie...hope it doesn't break things... either that or skip hosting and upload the pic every minute..
Buster would be better.

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 5:58 pm

Is it pretty straight forward...and will I have to reinstall everything?

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

Re: Upload a pic every minute

Wed Sep 18, 2019 7:36 pm

Ah, I never expected you were on Wheezy ready to upgrade to Jessie

Code: Select all

Version	Code name	Toy Story character
7	Wheezy		Wheezy the penguin
8	Jessie		Jessie the cowgirl
9	Stretch		Rubber octopus from Toy Story 3
10	Buster		Andy's pet dog
I would use a new microSD card and install Raspbian Buster on it using etcher.

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 7:45 pm

Problem is it's gonna be a ball ache to retrieve it from its current remote position to swap cards, not to mention the rigmarole of setting up the static id and stuff. If I could upgrade from ssh, to a recent enough rasbian so I can run Apache, that would be a better solution for me. I don't want the time lapse broken for days if I can help it.
Cheers
Steve

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

Re: Upload a pic every minute

Wed Sep 18, 2019 7:48 pm

Ah, where is it located then?

Return to “General discussion”