1 есептеу жүйесін жәНЕ



бет18/18
Дата26.11.2022
өлшемі0,91 Mb.
#159951
1   ...   10   11   12   13   14   15   16   17   18
Байланысты:
Оралбеков Диас ВТиПО video

import sqlite3
import cgitb


cgitb.enable()
#Rooms where the sensors are:
sensorl room="Kitchen"
sensor2_room="Garage"


#Sensors ID-numbers:
sensorl_lD="/sys/bus/wl/devices/10-000802e614ec/wl_slave" sensor2_lD="/sys/bus/wl/devices/10-000802e67b6f/wlslave"


#Database name
dbname='/var/www/temperatures.db'


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 ()


Camera.py бағдарламасы


#!/usr/bin/env python


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()

Достарыңызбен бөлісу:
1   ...   10   11   12   13   14   15   16   17   18




©engime.org 2024
әкімшілігінің қараңыз

    Басты бет