Gents
I am stuck on how to do this
I would like to create a web server that shows Motion web cam that has the following information overlaid on the screen using the Pi camera. (i have motion currently working ) Air Temp Humidity Air Pressure Water Temp water level
the following python code works but how do i run it on a web page updating every 10 seconds.
I already have Apache running how do i get it to run my python code or how do i get the information into html?
#!/usr/bin/env python # -*- coding: utf-8 -*-
# Can enable debug output by uncommenting: #import logging #logging.basicConfig(level=logging.DEBUG)
import Adafruit_BMP.BMP085 as BMP085 import sys import Adafruit_DHT import os import glob import time
# Default constructor will pick a default I2C bus.
sensor1 = BMP085.BMP085() sensor2 = Adafruit_DHT.AM2302 pin = 17
# Optionally you can override the bus number: #sensor = BMP085.BMP085(busnum=2) 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() f.close() return lines
def read_temp(): lines = read_temp_raw() while lines[0].strip()[-3:] != 'YES': time.sleep(0.2) 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 return temp_c
while True: print 'Box Temp = {0:0.2f} *C'.format(sensor1.read_temperature()) print 'Pressure = {0:0.2f} Pa'.format(sensor1.read_pressure()) print 'Altitude = {0:0.2f} m'.format(sensor1.read_altitude()) print 'Sealevel Pressure = {0:0.2f} Pa'.format(sensor1.read_sealevel_pressure()) humidity, temperature = Adafruit_DHT.read_retry(sensor2, pin) print 'Air Temp= ',temperature print 'Humidity= %',humidity print 'Water Temp = ',(read_temp()) print time.sleep(5)