Introduction
Motion gives us a lot of tools to work with, but adding weather data is a great way to see what it was like when you look back at historical images from your webcam. With these simple instructions, you should have weather data up in no time on your webcam.
Installation
You will require a few things:
- Motion
- Python
- pymetar (
http://www.schwarzvogel.de/software-pymetar.shtml)
Users Guide
First off, we want to enable the motion control port.
/etc/motion.cfg:
############################################################
# Control options
############################################################
# To protect HTTP Control by username and password, use this option for HTTP
# 1.1 Basic authentication. The string is specified as username:password. Do
# not specify this option for no authentication. This option must be placed in
# motion.conf and not in a thread config file.
control_authentication username:password
# Limits the http (html) control to the localhost. This option must be placed
# in motion.conf and not in a thread config file.
control_localhost on
# Enable HTML in the answer sent back to a browser connecting to the control_port.
# This option must be placed in motion.conf and not in a thread config file.
control_html_output on
# Sets the port number for the http (html using browser) based remote control.
# This option must be placed in motion.conf and not in a thread config file.
control_port 9080
Then, we will want to write our script that will fetch the weather data and then send it to the control port. I have written this simple script but feel free to modify it to fit your needs and the placement of the text in either the left or the right text fields.
#!/bin/sh
# Look up your city code and replace the CITY variable
# http://www.nws.noaa.gov/tg/siteloc.shtml
CITY=cyul
WEATHER=/tmp/weather.$CITY.current
/usr/bin/weather.py $CITY > $WEATHER
TEMPERATURE=`cat $WEATHER | grep "Temperature:"`
CONDITIONS=`cat $WEATHER | grep "Weather:"`
HUMIDITY=`cat $WEATHER | grep "Rel. Humidity:"`
# Camera 1
/usr/bin/wget --delete-after "http://username:password@localhost:9080/1/config/set?text_left=$CONDITIONS\n$TEMPERATURE - $HUMIDITY"
# Camera 2
/usr/bin/wget --delete-after "http://username:password@localhost:9080/2/config/set?text_left=$CONDITIONS\n$TEMPERATURE - $HUMIDITY"
rm $WEATHER
Once you have done all this, place the above script somewhere and place it in your crontab. I run mine every 15 minutes but you can update it as you wish.
*/15 * * * * /home/webcam/weather-cyul.sh 1>/dev/null 2>/dev/null
What's in weather.py?
--
RomanGaufman - 30 Mar 2009
weather.py is part of the pymetar (
http://www.schwarzvogel.de/software-pymetar.shtml) package
--
ZacharyMcGibbon - 31 Mar 2009
I see - however I opted to use
http://developer.yahoo.com/weather/ - because it gives you a condition code to use with your favourite weather icon collection and you can use it in a similar way to pymetar.
I've attached a python function to get weather from yahoo.
--
RomanGaufman - 07 Apr 2009
I was running this fine on a previous server, but after I moved to a new server, I get the following error. Any Ideas what I am doing wrong here? On a side note, is there a motion forum at all, or is everything through the support link on this site?
aaron@pele:/usr/local/scripts$ sudo ./weather.sh
Traceback (most recent call last):
File "/var/pymetar/bin/weather.py", line 6, in <module>
import pymetar
ImportError: No module named pymetar
--2009-10-11 13:37:07--
http://localhost:8080/0/config/set?text_left=%5Cn%20-%20
Resolving localhost... 127.0.0.1, ::1
Connecting to localhost|127.0.0.1|:8080... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `set?text_left=\n - '
[ <=> ] 223 --.-K/s in 0s
2009-10-11 13:37:07 (16.3 MB/s) - `set?text_left=\n - ' saved [223]
Removing set?text_left=\n - .
--
AaronWIsher - 11 Oct 2009