Weather Cam

1,048 views
Skip to first unread message

Robin

unread,
Feb 28, 2016, 2:06:21 AM2/28/16
to weewx-user
Greetings to all you good people.

WeeWX and my Davis weather station are running just fine (that statement is asking for trouble in itself), so I thought it was time I found a new way to 'break' things!

I have taken a shine to the idea of a weather cam that I can add to Weather Underground and my own website.

Now comes the rub, I have no idea what I am doing or even how to start. I have an ONVIF compatible IP camera that captures video. Does anybody out there know how I get this working or can anybody point me in the right direction to get started?

I need to capture a jpg image (every 5 minutes) and ftp to WU or ftp it to my site so WUcan 'grab' it. I have a Raspberry Pi running Raspian.

????

Thanks
Robin

Andrew Milner

unread,
Feb 28, 2016, 2:41:40 AM2/28/16
to weewx-user

Chris Swanda

unread,
Feb 28, 2016, 7:11:37 AM2/28/16
to weewx-user
I have a few installs of Zoneminder for various projects and thought that one day I would try to incorporate that into my Weewx.  (Among a 1000 other projects I'll get to one day....)


ZM is very well documented and fairly easy to use.  Maybe start here?

Robin

unread,
Feb 28, 2016, 8:23:01 AM2/28/16
to weewx-user
Andrew,

Thank you for the link, but this uses a USB camera and a Raspberry Pi to male an IP camera. I already have the IP camera and need a way of capturing a static image from it using my RPi.

Robin

Robin

unread,
Feb 28, 2016, 8:50:13 AM2/28/16
to weewx-user
Chris,

Thank you. Interesting. I'm almost managing with my armbands and feel like I've just fallen in at the deep end of the Linux pool!!! Perhaps I am a little (lot) out of my depth? 

Looking at zoneminder, it is clearly designed to do a lot more than I need. I have had a quick look through the documentation but could not see a simple way to capture a jpeg every 5 minutes and save or ftp it. Any other function is not needed and would only give my Raspberry Pi extra workload.

I off to put my armbands on and dive back into Linux school.

In the meantime impatient as ever, any help still gratefully accepted.

Robin

Dave Webb KB1PVH

unread,
Feb 28, 2016, 9:01:44 AM2/28/16
to weewx...@googlegroups.com

Not sure if there are work around for an IP cam. https://github.com/ccrisan/motioneye/wiki/Install-On-Raspbian

Dave-KB1PVH

Sent from my Samsung S4

Message has been deleted

Andy

unread,
Feb 28, 2016, 11:32:23 AM2/28/16
to weewx-user
Used this to find the url to connect to my camera:  https://github.com/sightmachine/SimpleCV/wiki/List-of-IP-Camera-Stream-URLs  

You will need an entry in /etc/fstab for the ram disk
tmpfs    /var/tmp    tmpfs    defaults,noatime,nosuid,size=30m    0 0


This runs every five minutes in cron.

##Get the image from my security camera and save to /var/tmp which is a ram disk.  I had to play around with the url to get it correct. 
wget  http
://192.168.1.200/img/snapshot.cgi?size=3 --output-document=/var/tmp/image.jpg --timeout=20 -q

###wait just a bit
sleep 
10 

### Put the image on wunderground.  This is the user for your WU weather cam and your usual WU password
lftp  
-' set net:timeout 10 ;  put /var/tmp/image.jpg ; exit '  -u USER,PASSWORD webcam.wunderground.com &>/dev/null

Andy

Aldo Bord

unread,
Feb 29, 2016, 3:00:12 AM2/29/16
to weewx-user


Il giorno domenica 28 febbraio 2016 08:06:21 UTC+1, Robin ha scritto:

Now comes the rub, I have no idea what I am doing or even how to start. I have an ONVIF compatible IP camera that captures video. Does anybody out there know how I get this working or can anybody point me in the right direction to get started?

Most Ip cams have an option to upload an image every n minutes to a ftp site.
You need to upload the image with a fixed filename (i.e. image.jpg). 
Then modify the index.html.tmpl file in weewx to display the image, inserting something like this:

      <p style="text-align:center" align="center"> <w:anchorlock>
         <img src="http://www.mysite.com/image.jpg"
            ></w:anchorlock></p>

Here an example from my site: www.bordieri.it

Aldo
Message has been deleted

Robin

unread,
Feb 29, 2016, 8:00:59 AM2/29/16
to weewx-user
Aldo hi,

My IP camera is a £13 Chinese 'special' and has no image upload function in the firmware forcing me to look at other options.

The camera does have an RTSP stream that I can see using VLC in windows, so I know I can see a stream. All I need now is to capture it (at a file soze of less than 150 Kb) and I might be in business.

Robin

Andy

unread,
Mar 1, 2016, 11:49:37 PM3/1/16
to weewx-user
Robin, can you post make model of camera please?

ffmpeg can get a still image from an rtp stream

Robin

unread,
Mar 2, 2016, 3:04:52 AM3/2/16
to weewx-user
Hi Andy,

Thank you for your continued help. The Camera has no branding at all. The box simply says "Infrared Waterproof Digital Video Camera".

ONVIF device manager identifies it as "Manufacturer: H264 Model: 001".

I have identified the rtsp stream and can view it in VLC. It looks like:


I have started investigating ffmpeg and am currently trying to get my head round the syntax. So far my limited understanding has produced.

ffmpeg -i rtsp://as_above -f image2 -q:v 5 /var/lib/weewx/backup/image.jpg 

-q:v to be adjusted to keep me within the 150 Kb limit. I already have a USB stick mounted at /var/lib/weewx/backup to rsync the data base, so I might as well use that as a destination.

Not sure how I install ffmpeg on my Pi, but it makes for an interesting life. After a recent HDD crash on my PC I'm going to take an image of the working SD card before I start.

Wish me luck, any advice from those with experience would be most welcome.

Robin

Risto Virtanen

unread,
Mar 2, 2016, 5:18:32 AM3/2/16
to weewx-user
Hi,

have you looked at this:

A bit off-topic, but FYI:

I have a RPi webcam taking stills with the Rapsberry Pi Camera onboard, configured as instructed in


To protect the SD card (I've already destroyed 2 cards) the images are stored in a tmpfs folder as described and moved quickly to a network mounted harddisk.

Every night a timelapse video is created from the stills with gst-launch with a command
gst-launch-1.0 multifilesrc location=wcimage-%06d.jpg index=100001 caps="image/jpeg,framerate=8/1" ! jpegdec ! videoscale ! video/x-raw, width=640, height=480 ! theoraenc bitrate=768 ! oggmux ! filesink location=rpwc_tl-${PVM}.ogv


The result can be seen on http://www.hassula.net/webcam/ (lower image frame, the upper is the camera stillshot taken a couple of minutes ago)

Thi RPi is an old B model, still quite capable of making the video.

//rkv

meltz...@gmail.com

unread,
Mar 2, 2016, 10:28:57 AM3/2/16
to weewx-user
Risto:  I started following this thread, and I want to thank you for posting all of this very useful information! This is a project I will probably try in the near future. I think your time lapse is wonderful; if we had unplowed roads like that where I used to live, there would be cars piled up on both sides!

Steve


vince

unread,
Mar 2, 2016, 11:10:21 AM3/2/16
to weewx-user
On Wednesday, March 2, 2016 at 2:18:32 AM UTC-8, Risto Virtanen wrote:
I have a RPi webcam taking stills with the Rapsberry Pi Camera onboard, configured as instructed in

Every night a timelapse video is created from the stills with gst-launch with a command
gst-launch-1.0 multifilesrc location=wcimage-%06d.jpg index=100001 caps="image/jpeg,framerate=8/1" ! jpegdec ! videoscale ! video/x-raw, width=640, height=480 ! theoraenc bitrate=768 ! oggmux ! filesink location=rpwc_tl-${PVM}.ogv


wow - you are working very hard to do that, especially on a model-B.....I've been doing the same thing for a couple years on my model-B using 'motion' as the app software with a plugged in Logitech USB webcam, although the same thing would work for the built-in pi camera module too.

Motion runs great on a pi and supports both timelapse generation and snapshots natively.  No need to glue multiple snaps into a timelapse  :-)

I agree on the SD card issue, I do all my work to a tmpfs directory in ramdisk.  Very very stable now.

For 'motion', the magic is in the config file.   I also have a few trivial cron jobs to aid in maintenance:
  • one cleans up the tmpfs dir based on age, so I don't fill it up
  • one scp's the snapshot to my weewx system so it's integrated into my local skin
  • another sftp's the snapshot to Weather Underground
  • another rsync's the timelapse movie up to my ISP

Examples are on http://www.skahan.net/weewx if you wanted to take a peek - current snap is in the top left, link to the historical timelapse bottom left

(and yes, I have a bug - forgot to update my rsync script to push 2016 movies up to the ISP.  Fortunately I have a local copy on the LAN at home)


I can post the config file/scripts/readme up to github if anybody cares......



Re: reading a stream from a network-enabled camera, I do that too in a VM that runs zoneminder as a security camera app under ubuntu.  The key for zm in connecting to a network stream is getting the URL right.   Most of these cameras expect something for the user and/or password, and it's sometimes hard to pass a value of "no value here" in a config file.  My camera is a Hootoo (an unbranded Foscam) but it configured just like the Foscam examples for zoneminder that are all over the 'net.  Google was my friend there.


Motion had some forks that supported rtsp streams as of late 2014 according to google, but I didn't look to see if the current official version has been updated or not.   Nice thing about using zm or motion is they hide all that ffmpeg stuff that they use behind the scenes, and all you need to do is cook up the right app-level config file and it does the rest.




 

Risto Virtanen

unread,
Mar 2, 2016, 1:13:56 PM3/2/16
to weewx-user
keskiviikko 2. maaliskuuta 2016 18.10.21 UTC+2 vince kirjoitti:

wow - you are working very hard to do that, especially on a model-B.....I've been doing the same thing for a couple years on my model-B using 'motion' as the app software with a plugged in Logitech USB webcam,

The python 'motion' sw is not so heavy and the RPi graphic processor which does the timelapse encoding is quite powerful, and during the night no photos taken, time to encode:)

  • one cleans up the tmpfs dir based on age, so I don't fill it up
cron is handy tool. I created a script as described in the python webcam page, containing only
lines

 while :
  do
   find /mnt/picam_tmpfs -type f -mmin +1 -exec mv '{}' /mnt/nassula2_hh/webcam/rpicam1/ \;
   sleep 60
  done

and start that during boot every morning.
  • one scp's the snapshot to my weewx system so it's integrated into my local skin
That is a thing on my todo-list. At the moment the webcam image is handled separately and the weewx page is having a link only. Weewx is running on an old laptop for historical reasons. Will change it to a RPi when the laptop dies some day. My old weather station (a Huger/Oregon Scientific WM918) needs a wired serial connection and it is still in use although the anemometer has been broken for years...

Examples are on http://www.skahan.net/weewx if you wanted to take a peek - current snap is in the top left, link to the historical timelapse bottom left


Far smoother and the effects in the sky are quite nice:)

What are the 'Console battery' and 'ISS battery'  entries on the weewx page?

//rkv



vince

unread,
Mar 2, 2016, 1:23:09 PM3/2/16
to weewx-user
On Wednesday, March 2, 2016 at 10:13:56 AM UTC-8, Risto Virtanen wrote:
keskiviikko 2. maaliskuuta 2016 18.10.21 UTC+2 vince kirjoitti:
The python 'motion' sw is not so heavy and the RPi graphic processor which does the timelapse encoding is quite powerful, and during the night no photos taken, time to encode:)


I let mine run 24x7 and rotate the movie out nightly via cron, but I previously had cron jobs to start/stop the timelapse at dark.
 
What are the 'Console battery' and 'ISS battery'  entries on the weewx page?


Whatever weewx reports from my VP2 - personally I suspect the console battery value might not be too valuable since mine is plugged into the wall.  I'm hoping the ISS battery correctly would detect the sensor battery going low enough to need to replace it, which happens every few years....
 

Messy Potamia

unread,
Mar 3, 2016, 8:57:57 AM3/3/16
to weewx-user
I have a surveillance-grade (Hikvision) IP camera on the roof connected to a switch. Setting up its networking parameters, and leaving most video settings default, is fairly academic. I then grab a single frame of this periodically (per crontab) and place the result in my /home/weewx/public_html folder where it is uploaded to my public website cafebardeli.net. Also, because I told weather underground where to find the image, they pull it from there (see KALGUNTE8). Note, that most cameras have a http: protocol access method which allows single frame grab. I use the following lines in a script to accomplish this:

=============================================================
#I have a usb permanently mounted in my pi's fs as /mnt/wxdata, but you put it wherever it's convenient for you.
wget -i /home/pi/wget.cfg -a /mnt/wxdata/wget.log  --auth-no-challenge -O /mnt/wxdata/wxout.jpg
#the wget.cfg file has a simple config line in it for accessing the camera, could've also put it in the above line but too awkward, here it is sanitized of password:
#http://login:password@weathercam/Streaming/channels/101/picture
# in my Pi's /etc/hosts file I have an entry for weathercam pointing to its static ip address.
#Since this is a 1080p camera the files get pretty big so I run the following command before distributing it:
convert /mnt/wxdata/wxout.jpg -resize 780x480 -quality 85 /mnt/wxdata/wxout.jpg
=============================================================
Sure the camera isn't connected to the Pi, and because of this it's more flexible (it's also connected to my surveillance server) with what you can do with the video. You might try this with a simple external camera for which you can get the interface reference. I think wget comes with raspbian but you may be to apt-get the convert function. It's worth it.

Best wishes -"MP"



On Sunday, February 28, 2016 at 1:06:21 AM UTC-6, Robin wrote:

Messy Potamia

unread,
Mar 3, 2016, 9:01:07 AM3/3/16
to weewx-user
If it's an ONVIF compliant IP camera, I'm sure you an use a wget command. My Hikvision are professional grade, but I got mine on sale from a security distributor, I think it was around $120 though.

Robin

unread,
Mar 17, 2016, 11:49:09 AM3/17/16
to weewx-user
Thank you to everyone who took time to reply. Your help has given me the push to get this working.

I have set up a cron to do the work every 5 minutes and the £13 camera is working fine.

#!/bin/bash

# grab new image.jpg from rtsp stream and save to mounted usb stick
avconv -loglevel panic -i rtsp://192.168.1.10:554/user=admin_password=asdafoo_channel=1_stream=0.sdp?real_stream -f image2 /var/lib/weewx/backup/image.jpg

# pause for breath
sleep 10

# upload file to wunderground
lftp  -e "set net:timeout 10 ; put /var/lib/weewx/backup/image.jpg ; exit"  -u USER,PASSWORD webcam.wunderground.com

I have one worry. If the camera stops working, then the cron will fail to grab an image, but the old file will still exist and will be (re)uploaded every five minutes.

Can anybody suggest a simple/elegant way of stopping the upload until a new image file has been written?

Andrew Milner

unread,
Mar 17, 2016, 12:16:22 PM3/17/16
to weewx-user
You could delete the old image before getting a new one.  If getting a new one fails then you wont have a file to upload, and the cron task should give an error or fail.

vince

unread,
Mar 17, 2016, 12:23:03 PM3/17/16
to weewx-user
On Thursday, March 17, 2016 at 8:49:09 AM UTC-7, Robin wrote:
I have one worry. If the camera stops working, then the cron will fail to grab an image, but the old file will still exist and will be (re)uploaded every five minutes.
Can anybody suggest a simple/elegant way of stopping the upload until a new image file has been written?

sure - after you successfully upload (you should check $?=0), delete the file.
Only upload if there is a file 'to' upload present.

pretty simple if-then thing to add...

Robin

unread,
Mar 17, 2016, 12:27:08 PM3/17/16
to weewx-user
Andrew, Vince

This was the solution that I had worked out:

  1. Check if image file exists, if so, delete it 
  2. Save new image from rtsp stream
  3. check if image file exists, if so upload it
It just seems 'ugly' and I wondered if there was a 'prettier' way! 

I suppose I should also check to see what happens if there is no stream to grab from!!!

vince

unread,
Mar 17, 2016, 1:42:41 PM3/17/16
to weewx-user
On Thursday, March 17, 2016 at 9:27:08 AM UTC-7, Robin wrote:
This was the solution that I had worked out:
  1. Check if image file exists, if so, delete it 
  2. Save new image from rtsp stream
  3. check if image file exists, if so upload it
It just seems 'ugly' and I wondered if there was a 'prettier' way! 


If it works before you get fired/divorced/bankrupt/bored then it isn't ugly.
 
I suppose I should also check to see what happens if there is no stream to grab from!!!

There are dozens of programming best practices docs you can find on Google, but yes always check for unexpected conditions, always check return status of commands etc. if you're trying to write bulletproof code.

But it's done when you say 'good enough'.
 

Andy

unread,
Mar 18, 2016, 8:15:43 PM3/18/16
to weewx-user
Since my camera points outside and it is dark at night, I would like to add something that stops getting the image at dusk and starts up at dawn.  This would avoid uploading many black images. 


The bandwidth is much less at night, this is a quick way to verify the camera is running.  



  

vince

unread,
Mar 18, 2016, 9:36:35 PM3/18/16
to weewx-user
On Friday, March 18, 2016 at 5:15:43 PM UTC-7, Andy wrote:
Since my camera points outside and it is dark at night, I would like to add something that stops getting the image at dusk and starts up at dawn.  This would avoid uploading many black images. 

Really depends on what software you have and how it works, but basically you'd need:
  • something that can calculate local dusk/dawn correctly as the year progresses based on your location.  I think pyephem can do this, if you wanted to write your own thing based on that.  There are many other options, do a google search for 'linux command to calculate dusk'
Wrapper your existing stuff you mentioned in late Feb in this thread to put it all in one script.  Enhance the current steps to:
  • if it's dusk or later, touch a flag file in /tmp to indicate do-not-update
  • have your script look for that file and skip the upload steps if that flag file is present
  • if it's dawn or later (before dusk), remove that flag file in /tmp if one was there
Pretty simple if-then-else loop to put in a bash script.


vince

unread,
Mar 18, 2016, 9:38:08 PM3/18/16
to weewx-user
Reply all
Reply to author
Forward
0 new messages