Live WebCam with Timestamp, Temp and Live Data Watermark

So I am working on a Live cam shot for my website that would list date and time with temp and a metar after a lot of googleing there wasn’t a lot out there so this is what I came up with.

First you will need the following packages.

sudo apt-get install imagemagick metar ttf-mscorefonts-installer

I am doing everything on the Pi, all files are in a zip file for download at bottom of page.

To get the temp from the DS18B20 temp sensor you need to create a python script.

NOTE: you will need to setup sensor first Adafruit has a great lesson on how-to.

#!/usr/bin/env python

import os
import glob
import time
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')

base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
device_file = device_folder + '/w1_slave'

def read_temp_raw():
    f = open(device_file, 'r')
    lines = f.readlines()
    return lines

def read_temp():
    lines = read_temp_raw()
    while lines[0].strip()[-3:] != 'YES':
        lines = read_temp_raw()
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:]
        temp_c = float(temp_string) / 1000.0
        temp_f = temp_c * 9.0 / 5.0 + 32.0
        temp_c = round(temp_c, 1)
  return temp_c

while True:

I have it set to round to to a single digit after the decimal if you don’t want to just change the 1 to what ever many digits you want after the decimal.

temp_c = round(temp_c, 1

This is main script it will setup all the vars and take the pic merge in with the overlay image that creates the transparent black bars for the text there is a way create the black bars in but i couldn’t figure out how so I did it this way and if i want to add a logo or anything i just need to change overly image without fooling with code


# Set up vars for captions
# metat uses metar linux app
METAR="$(metar cyyt)"
# raspistill capture settings
OPTIONS='-w 2592 -h 1944 -q 80 -x'
# Set time and date stamp format
DATETIME=$(date +"Taken on: %B %d, %Y @ %T  %p")
# Run python screipt to fetch temp from DS18B20 temp sensor

# set dir to put images
#cd /tmp
# Capture Image useing var settigns and save as cam.jpg
raspistill -o cam.jpg $OPTIONS

# use overlay.png to add black bar behind text of cam and create pre_webcam.jpg
composite -gravity center overlay.png cam.jpg pre_webcam.jpg

# Add text from vars and location of font to use and save as webcam
convert pre_webcam.jpg -font /usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf \
  -pointsize 30 -fill white -annotate +2000+1885  \
  -pointsize 30 -fill white -annotate +2000+1925  \
  "Outside Temp: $TEMP" \
  -pointsize 40 -fill white -annotate +10+43  \
  "$METAR" \
  -pointsize 80 -fill white -annotate +10+1925  \
  " - Image by RPi" \

I haven’t decided how I am going to move the image to my webserver yet I may use rsync, SFTP, etc… when I do I will post a update


Raspberry Pi 2

Waterproof DS18B20 Digital temperature sensor + extras

Raspberry Pi Camera Board


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.