def getTemperature(ID, sensor_room): tfile=open(ID) text=tfile.read() tfile.close() #Split the text with new lines (\n) and select the second line secondline= text.split("\n")[1] #Split the line into words, referring to the spaces and select the 10th word temperaturedata= secondline.split (" ") [9] #The first two characters are "t=", so get rid of those and convert # the temperature from a string to a number. temperature=float(temperaturedata[2:])
#Put the decimal point in the right place and display the temperature sensor_data = temperature/1000 #Round the result to the 2decimals sensordata = round(sensordata, 2) # Insert temperature to database: # Connect to the temperature database db=sqlite3.connect(dbname) cur = db.cursor() cur.execute("INSERT INTO temperatures VALUES(date('nowlocaltime'), time('now'localtime'), (?), (?));", (sensor_room, sensor_data,)) db.commit() db.close()
def main(): getTemperature(sensorl_ID, sensorlroom) getTemperature(sensor2_ID, sensor2_room) main ()
import cgitb import datetime import picamera import time
cgitb.enable() def takePicture(): location='/var/www/camera/1 date=datetime.datetime.now() #Get current date file_name=date.strftime("%Y-%m-%d %H%M") #Format the string
#configuration for the pictures camera = picamera.PiCamera() camera.resolution = (1280,720) camera.start_preview()
#Camera warm up time time.sleep(10) # Capture the picture and saved it with the current date camera.capture("%s%s.jpg" % (location,file_name), quality=75) camera.stop_preview() camera.close() takePicture()