Está en la página 1de 28

Universidad Tecnológica de Honduras

San Pedro Sula

Teoría y Diseño de Compiladores

Catedrático: NORMAN ALBERTO CUBILLA

Nombre de los Integrantes:


Anthony Paz, Joseph Cooper
Justo Valentín, Ramiro Leiva
Tema: Programación en consola Raspi-Linux y Python

Proyecto en Elaboración: Electronic Security Systems

1
Indice
# PanelDomotico.py ............................................................................................................................ 4
# Declaracion de Librerias del Modulo tkinter ................................................................................ 4
######### VENTANA # 1 ########### ......................................................................................... 4
#Programación Horaria de la Alarma y Activación del Sensor .................................................... 4
# FOCO -1 .................................................................................................................................... 6
#FOCO -2 ..................................................................................................................................... 7
#FOCO -3 ..................................................................................................................................... 8
#FOCO -4 ..................................................................................................................................... 9
#Configuración de las Luces por Horario .................................................................................. 10
#Label para Hora y Minuto ........................................................................................................ 12
#Las Cajas de Textos de Hora y Minuto .................................................................................... 12
#Boton para programar la hora................................................................................................. 14
# Reloj Time ............................................................................................................................... 14
######## VENTANA PROGRAMA ALARMA########................................................................... 14
# Boton Guardar ........................................................................................................................ 15
# Reloj Time ............................................................................................................................... 15
######### VENTANA PARA ACERCA DE ######### .................................................................... 16
########3 VENTANA PROGRAMAR FOCOS ######### ............................................................... 16
# Asignar imagenes a Foco1 ...................................................................................................... 20
# Asignar imagenes a Foco2 ...................................................................................................... 21
# Asignar Imagen a Foco3 ......................................................................................................... 21
# Asignar Imagen a Foco4 ......................................................................................................... 21
# Asignar Imagen a Alarma........................................................................................................ 22
# Alarma.sh........................................................................................................................................ 23
# Alarmaoff.sh ................................................................................................................................... 23
# Correo.sh ........................................................................................................................................ 23
#Foco1.sh .......................................................................................................................................... 23
#Foco1off.sh ...................................................................................................................................... 24
#Foco2.sh .......................................................................................................................................... 24
#Foco2off.sh ...................................................................................................................................... 24
#Foco3.sh .......................................................................................................................................... 24
#Foco3off.sh ...................................................................................................................................... 24

2
#Foco4.sh .......................................................................................................................................... 25
#Foco4off.sh ...................................................................................................................................... 25
#Foto.sh............................................................................................................................................. 25
#Alarma2.py ...................................................................................................................................... 25
#ApagarAlarma2.py ........................................................................................................................... 27

3
# PanelDomotico.py
# Declaracion de Librerias del Modulo tkinter
from Tkinter import *

from ttk import *

import tkFont

import tkMessageBox

import pygame

import os

import subprocess

import sqlite3

import time

import os

import webbrowser

pygame.mixer.init()

#pygame.mixer.music.load("/home/pi/PracticasTK/acceso1.mp3")

#sudo apt-get install timidity

######### VENTANA # 1 ###########


# TOPLEVEL

def settings():

global operator

operator=operator+str(numbers)

cod.set(operator)

#####################################################################

#Programación Horaria de la Alarma y Activación del Sensor


def save():

tab=StringVar()

hi=horai.get()

4
mi=mini.get()

hf=horaf.get()

mf=minf.get()

dia="*"

mes="*"

ano="*"

tab=" "

user="root"

path="/home/pi/alarma2.py"

path2="/home/pi/apagar_alarma2.py"

#Se Enciende cuando se cumple la hora definida

cadena=(str(mi)+''+str(tab)+''+str(hi)+''+str(tab)+''+str(dia)+''+str(tab)+''+str(mes)+''+str(tab)

+''+str(ano)+''+str(tab)+''+str(user)+''+str(tab)+''+str(path))

print(str(cadena))

tkMessageBox.showinfo("Save",message="Alarma Programada con Exito")

os.system("chmod -R 755 /etc/cron.d/alarma")

pf=open(r'/etc/cron.d/alarma','w')

pf.write(cadena)

pf.write("\n")

pf.close()

cadena2=(str(mf)+''+str(tab)+''+str(hf)+''+str(tab)+''+str(dia)+''+str(tab)+''+str(mes)+''+str(tab)

+''+str(ano)+''+str(tab)+''+str(user)+''+str(tab)+''+str(path2)) #CUANDO PASA EL TIEMPO


ESTIMADO SE APAGA

print(str(cadena2))

os.system("chmod -R 755 /etc/cron.d/alarmaoff")

pf2=open(r'/etc/cron.d/alarmaoff','w')

#LA CARPETA "CRON.D" AHI SE ALAMACENA LOS ARCHIVOS PARA PROGRAMAR A QUE HORA SE
ACTIVA LA ALARMA O FOCOS

pf2.write(cadena2)
5
pf2.write("\n")

pf2.close()

pygame.mixer.music.load("/home/pi/PracticasTK/horarioprog.mp3") #ESTOS ARCHIVOS


ACTIVAN UN SONIDO

pygame.mixer.music.play()

#####################################################################

# FOCO -1
def saveFocos():

tab=StringVar()

hi=horaih1.get()

mi=minih1.get()

hf=horafh1.get()

mf=minfh1.get()

dia="*"

mes="*"

ano="*"

tab=" "

user="root"

path="/home/pi/foco1.sh"

path2="/home/pi/foco1off.sh"

cadena=(str(mi)+''+str(tab)+''+str(hi)+''+str(tab)+''+str(dia)+''+str(tab)+''+str(mes)+''+str(tab)

+''+str(ano)+''+str(tab)+''+str(user)+''+str(tab)+''+str(path))

print(str(cadena))

os.system("chmod -R 755 /etc/cron.d/test")

pf=open(r'/etc/cron.d/test','w')

pf.write(cadena)

pf.write("\n")

pf.close()

6
cadena2=(str(mf)+''+str(tab)+''+str(hf)+''+str(tab)+''+str(dia)+''+str(tab)+''+str(mes)+''+str(tab)

+''+str(ano)+''+str(tab)+''+str(user)+''+str(tab)+''+str(path2))

print(str(cadena2))

os.system("chmod -R 755 /etc/cron.d/testoff")

pf2=open(r'/etc/cron.d/testoff','w')

pf2.write(cadena2)

pf2.write("\n")

pf2.close()

pygame.mixer.music.load("/home/pi/PracticasTK/horarioprog.mp3")

pygame.mixer.music.play()

########################################################

#FOCO -2
tab=StringVar()

hi=horaih2.get()

mi=minih2.get()

hf=horafh2.get()

mf=minfh2.get()

dia="*"

mes="*"

ano="*"

tab=" "

user="root"

path="/home/pi/foco2.sh"

path2="/home/pi/foco2off.sh"

cadena=(str(mi)+''+str(tab)+''+str(hi)+''+str(tab)+''+str(dia)+''+str(tab)+''+str(mes)+''+str(tab)

+''+str(ano)+''+str(tab)+''+str(user)+''+str(tab)+''+str(path))

print(str(cadena))

os.system("chmod -R 755 /etc/cron.d/test2")

7
pf=open(r'/etc/cron.d/test2','w')

pf.write(cadena)

pf.write("\n")

pf.close()

cadena2=(str(mf)+''+str(tab)+''+str(hf)+''+str(tab)+''+str(dia)+''+str(tab)+''+str(mes)+''+str(tab)

+''+str(ano)+''+str(tab)+''+str(user)+''+str(tab)+''+str(path2))

print(str(cadena2))

os.system("chmod -R 755 /etc/cron.d/testoff2")

pf2=open(r'/etc/cron.d/testoff2','w')

pf2.write(cadena2)

pf2.write("\n")

pf2.close()

pygame.mixer.music.load("/home/pi/PracticasTK/horarioprog.mp3")

pygame.mixer.music.play()

########################################################

#FOCO -3
tab=StringVar()

hi=horaih3.get()

mi=minih3.get()

hf=horafh3.get()

mf=minfh3.get()

dia="*"

mes="*"

ano="*"

tab=" "

user="root"

path="/home/pi/foco3.sh"

path2="/home/pi/foco3off.sh"

8
cadena=(str(mi)+''+str(tab)+''+str(hi)+''+str(tab)+''+str(dia)+''+str(tab)+''+str(mes)+''+str(tab)

+''+str(ano)+''+str(tab)+''+str(user)+''+str(tab)+''+str(path))

print(str(cadena))

os.system("chmod -R 755 /etc/cron.d/test3")

pf=open(r'/etc/cron.d/test3','w')

pf.write(cadena)

pf.write("\n")

pf.close()

cadena2=(str(mf)+''+str(tab)+''+str(hf)+''+str(tab)+''+str(dia)+''+str(tab)+''+str(mes)+''+str(tab)

+''+str(ano)+''+str(tab)+''+str(user)+''+str(tab)+''+str(path2))

print(str(cadena2))

os.system("chmod -R 755 /etc/cron.d/testoff3")

pf2=open(r'/etc/cron.d/testoff3','w')

pf2.write(cadena2)

pf2.write("\n")

pf2.close()

pygame.mixer.music.load("/home/pi/PracticasTK/horarioprog.mp3")

pygame.mixer.music.play()

########################################################

#FOCO -4
tab=StringVar()

hi=horaih4.get()

mi=minih4.get()

hf=horafh4.get()

mf=minfh4.get()

dia="*"

mes="*"

ano="*"

9
tab=" "

user="root"

path="/home/pi/foco4.sh"

path2="/home/pi/foco4off.sh"

cadena=(str(mi)+''+str(tab)+''+str(hi)+''+str(tab)+''+str(dia)+''+str(tab)+''+str(mes)+''+str(tab)

+''+str(ano)+''+str(tab)+''+str(user)+''+str(tab)+''+str(path))

print(str(cadena))

tkMessageBox.showinfo("Save",message="Todos los Focos fueron programados


exitosamente!")

os.system("chmod -R 755 /etc/cron.d/test4")

pf=open(r'/etc/cron.d/test4','w')

pf.write(cadena)

pf.write("\n")

pf.close()

cadena2=(str(mf)+''+str(tab)+''+str(hf)+''+str(tab)+''+str(dia)+''+str(tab)+''+str(mes)+''+str(tab)

+''+str(ano)+''+str(tab)+''+str(user)+''+str(tab)+''+str(path2))

print(str(cadena2))

os.system("chmod -R 755 /etc/cron.d/testoff4")

pf2=open(r'/etc/cron.d/testoff4','w')

pf2.write(cadena2)

pf2.write("\n")

pf2.close()

pygame.mixer.music.load("/home/pi/PracticasTK/horarioprog.mp3") #HASTA AQUI


TERMINA LA PROGRAMACION DE SAVEFOCOS TODOS LOS FOCOS ESTAN EN LA MISMA NINGUNA
SALE

pygame.mixer.music.play()

######################################################

#Configuración de las Luces por Horario


###################

10
def toplevel2():

global horaih1,horaih2,horaih3,horaih4,horaih5,horaih6

global horafh1,horafh2,horafh3,horafh4,horafh5,horafh6

global minih1,minih2,minih3,minih4,minih5,minih6

global minfh1,minfh2,minfh3,minfh4,minfh5,minfh6

v2=Toplevel()

v2.title("Configurar ON/OFF de Luces x Horario")

v2.geometry("550x350+400+200")

horaih1=StringVar()

minih1=StringVar()

horafh1=StringVar()

minfh1=StringVar()

horaih2=StringVar()

minih2=StringVar()

horafh2=StringVar()

minfh2=StringVar()

horaih3=StringVar()

minih3=StringVar()

horafh3=StringVar()

minfh3=StringVar()

horaih4=StringVar()

minih4=StringVar()

horafh4=StringVar()

minfh4=StringVar()

11
#horaih5=StringVar()

#minih5=StringVar()

#horafh5=StringVar()

#minfh5=StringVar()

#NO OCUPAREMOS MAS FOCOS SOLO OCUPAMOS 4 FOCOS

#horaih6=StringVar()

#minih6=StringVar()

#horafh6=StringVar()

#minfh6=StringVar()

#Label para Hora y Minuto


textfont=tkFont.Font(family="Helvetica",size=11,weight="bold")

textfont2=tkFont.Font(family="Helvetica",size=10,weight="bold")

label1=Label(v2,text="PROGRAMAR ENCENDIDO Y APAGADO DE


LUCES",font=textfont).place(x=70,y=05)

labelon=Label(v2,text="- - - ON - - -",font=textfont).place(x=210,y=40)

labeloff=Label(v2,text="- - - OFF - - -",font=textfont).place(x=360,y=40)

labelhorai=Label(v2,text="Hora-ini").place(x=190,y=60)

labelmini=Label(v2,text="Min-ini").place(x=260,y=60)

labelhoraf=Label(v2,text="Hora-fin").place(x=330,y=60)

labelhorai=Label(v2,text="Min-fin").place(x=410,y=60)

labelhab1=Label(v2,text="Habitacion -1-",font=textfont).place(x=70,y=80)

labelhab2=Label(v2,text="Habitacion -2-",font=textfont).place(x=70,y=120)

labelhab3=Label(v2,text="Habitacion -3-",font=textfont).place(x=70,y=160)

labelhab4=Label(v2,text="Habitacion -4-",font=textfont).place(x=70,y=200)

#labelhab5=Label(v2,text="Habitacion -5-",font=textfont).place(x=70,y=240)

#labelhab6=Label(v2,text="Habitacion -6-",font=textfont).place(x=70,y=280)

#Las Cajas de Textos de Hora y Minuto


texthoraih1=Entry(v2,textvariable=horaih1,width=7).place(x=190,y=80)

12
textminih1=Entry(v2,textvariable=minih1,width=7).place(x=260,y=80)
#####################

texthorafh1=Entry(v2,textvariable=horafh1,width=7).place(x=330,y=80) #

textminfh1=Entry(v2,textvariable=minfh1,width=7).place(x=410,y=80) #

texthoraih2=Entry(v2,textvariable=horaih2,width=7).place(x=190,y=120) #

textminih2=Entry(v2,textvariable=minih2,width=7).place(x=260,y=120) #

texthorafh2=Entry(v2,textvariable=horafh2,width=7).place(x=330,y=120) #

textminfh2=Entry(v2,textvariable=minfh2,width=7).place(x=410,y=120) #

texthoraih3=Entry(v2,textvariable=horaih3,width=7).place(x=190,y=160) #

textminih3=Entry(v2,textvariable=minih3,width=7).place(x=260,y=160) #

texthorafh3=Entry(v2,textvariable=horafh3,width=7).place(x=330,y=160) #

textminfh3=Entry(v2,textvariable=minfh3,width=7).place(x=410,y=160) #

texthoraih4=Entry(v2,textvariable=horaih4,width=7).place(x=190,y=200) #

textminih4=Entry(v2,textvariable=minih4,width=7).place(x=260,y=200) #

texthorafh4=Entry(v2,textvariable=horafh4,width=7).place(x=330,y=200)

textminfh4=Entry(v2,textvariable=minfh4,width=7).place(x=410,y=200)

#texthoraih5=Entry(v2,textvariable=horaih5,width=7).place(x=190,y=240)

#textminih5=Entry(v2,textvariable=minih5,width=7).place(x=260,y=240)

#texthorafh5=Entry(v2,textvariable=horafh5,width=7).place(x=330,y=240)

#textminfh5=Entry(v2,textvariable=minfh5,width=7).place(x=410,y=240)

#texthoraih6=Entry(v2,textvariable=horaih6,width=7).place(x=190,y=280)

#textminih6=Entry(v2,textvariable=minih6,width=7).place(x=260,y=280)

#texthorafh6=Entry(v2,textvariable=horafh6,width=7).place(x=330,y=280)

#textminfh6=Entry(v2,textvariable=minfh6,width=7).place(x=410,y=280)

13
botosettings=Button(v2,text="PROGRAMAR",command=saveFocos).place(x=215,y=260,height=30)

#Boton para programar la hora


#SaveFocos es el comando para programar las horas de las habitaciones

botonclose=Button(v2,text="SALIR", command=v2.destroy).place(x=305,y=260,height=30)
#Boton para salir de la ventana

# Reloj Time
def update():

current=time.strftime("%H:%M:%S")

labelTiempo=Label(v2,text=" -- Tiempo --").place(x=110,y=240) # <---- Esto sirve para


mostrar la hora actual de la raspberry

labeltime=Label(v2,text=current).place(x=120,y=260)

v2.after(1000,update)

update()

v2.mainloop()

######## VENTANA PROGRAMA ALARMA########


def toplevel():

# Las variables Globales siempre deben de declarse al inicio de cada metodo o funcion

# Para que no generen advertencias o warning ejemplo:syntaxwarning name is assigned to


before global declaration

global horai

global horaf

global mini

global minf

v1=Toplevel()

v1.title("Configurar Alarma x Horarios")

v1.geometry("500x350+200+200")

mini=StringVar()

14
minf=StringVar()

horai=StringVar()

horaf=StringVar()

# Declarar Variables Globales para ser usadas dentro de cualquier funcion o metodo

texttop=tkFont.Font(family="Helvetica",size=10,weight="bold")

texttop2=tkFont.Font(family="Helvetica",size=9,weight="bold")

label1top=Label(v1,text="HORARIO DE ACTIVACION & DESACTIVACION DE


ALARMA",font=texttop).place(x=50,y=10)

label2top=Label(v1,text="HORA INICIAL :",font=texttop2).place(x=110,y=70)

caja2=Entry(v1,textvariable=horai,width=20).place(x=215,y=70)

label3top=Label(v1,text="MINUTO INICIAL :",font=texttop2).place(x=110,y=110)

TextBox2=Entry(v1,textvariable=mini,width=20).place(x=215,y=110)

label4top=Label(v1,text="HORA FINAL :",font=texttop2).place(x=110,y=150)

TextBox3=Entry(v1,textvariable=horaf,width=20).place(x=215,y=150)

label5top=Label(v1,text="MINUTO FINAL :",font=texttop2).place(x=110,y=190)

TextBox4=Entry(v1,textvariable=minf,width=20).place(x=215,y=190)

# Boton Guardar
imgsave=PhotoImage(file="guardar.gif")

botosettings=Button(v1,image=imgsave,command=save,width=50).place(x=215,y=220,height=50)
# COMMAND=SAVE, ESTA FUNCION ESTA AL INICIO DEL PROGRAMA

botonclose=Button(v1,text="Cerrar", command=v1.destroy).place(x=295,y=220,height=50)

# Reloj Time
def update():

current=time.strftime("%H:%M:%S")

labelTiempo=Label(v1,text=" -- Tiempo --").place(x=110,y=230) # <---- Esto sirve para


mostrar la hora actual de la raspberry

labeltime=Label(v1,text=current).place(x=120,y=250)

15
v1.after(1000,update)

update()

v1.mainloop()

######### VENTANA PARA ACERCA DE #########


def toplevel3():

v3=Toplevel()

v3.title("Acerca de")

v3.geometry("300x350+450+230")

bgtext1 = tkFont.Font(family="Helvetica", size=14, weight="bold")

label1=Label(v3,text="Panel Domotico v1.1",font=bgtext1).place(x=30,y=10)

bgtext2 = tkFont.Font(family="Helvetica", size=12, weight="bold")

label2=Label(v3,text="Programadores",font=bgtext2).place(x=30,y=70)

bgtext3 = tkFont.Font(family="Helvetica", size=9) #TODO ESTO ES PURO "LABEL"

label3=Label(v3,text="Anthony Paz",font=bgtext3).place(x=30,y=100)

label3=Label(v3,text="Ramiro Leiva",font=bgtext3).place(x=30,y=120)

label3=Label(v3,text="Justo Valentin",font=bgtext3).place(x=30,y=140)

label3=Label(v3,text="Joseph",font=bgtext3).place(x=30,y=160)

botonclose=Button(v3,text="Cerrar", command=v3.destroy).place(x=110,y=270,height=50)

v3.mainloop()

################################################################################
###############################

########3 VENTANA PROGRAMAR FOCOS #########


# Definiendo los metodos o funciones para cada Foco(Gpio)

def Foco1on():

os.system("/./home/pi/foco1.sh") #Esto ejecuta el archivo SH para Activar el Gpio

16
boton1b=Button(v0,image=imgboton1b,command=Foco1off,state='normal',width=100).place(x=1
40,y=50,height=100) #Esto activa el boton para desactivar el foco

boton1=Button(v0,image=imgboton1,command=Foco1on,state='disabled').place(x=20,y=50,height
=100,width=100) #El boton que presionamos quedara desactivado por lo que no podremos
activar el mismo foco hasta que lo desactivemos primero

tkMessageBox.showinfo("Habitacion 1",message="Foco 1 Encendido")

def Foco1off():

tkMessageBox.showinfo("Habitacion 1",message="Foco 1 Apagado")

os.system("/./home/pi/foco1off.sh")

boton1b=Button(v0,image=imgboton1b,command=Foco1off,state='disabled',width=100).place(x=
140,y=50,height=100) #El boton que presionamos quedara desactivado por lo que no podremos
desactivar el mismo foco hasta que lo activemos primero

boton1=Button(v0,image=imgboton1,command=Foco1on,state='normal').place(x=20,y=50,height=
100,width=100) #Esto activa el boton para activar el foco

tkMessageBox.showinfo("Habitacion 1",message="Foco 1 Apagado")

def Foco2on():

os.system("/./home/pi/foco2.sh")

boton2=Button(v0,image=imgboton2,command=Foco2on,width=100,state='disabled').place(x=20,
y=205,height=100)

boton2b=Button(v0,image=imgboton2b,command=Foco2off,state='normal',width=100).place(x=1
40,y=205,height=100)

tkMessageBox.showinfo("Habitacion 2",message="Foco 2 Encendido")

def Foco2off():

os.system("/./home/pi/foco2off.sh")

boton2=Button(v0,image=imgboton2,command=Foco2on,width=100,state='normal').place(x=20,y
=205,height=100)

17
boton2b=Button(v0,image=imgboton2b,command=Foco2off,state='disabled',width=100).place(x=
140,y=205,height=100)

tkMessageBox.showinfo("Habitacion 2",message="Foco 2 Apagado")

def Foco3on():

os.system("/./home/pi/foco3.sh")

boton3=Button(v0,image=imgboton3,command=Foco3on,width=100,state='disabled').place(x=20,
y=360,height=100)

boton3b=Button(v0,image=imgboton3b,command=Foco3off,state='normal',width=100).place(x=1
40,y=360,height=100)

tkMessageBox.showinfo("Habitacion 3",message="Foco 3 Encendido")

def Foco3off():

os.system("/./home/pi/foco3off.sh")

boton3=Button(v0,image=imgboton3,command=Foco3on,width=100,state='normal').place(x=20,y
=360,height=100)

boton3b=Button(v0,image=imgboton3b,command=Foco3off,state='disabled',width=100).place(x=
140,y=360,height=100)

tkMessageBox.showinfo("Habitacion 3",message="Foco 3 Apagado")

def Foco4on():

os.system("/./home/pi/foco4.sh")

boton4=Button(v0,image=imgboton4,command=Foco4on,width=100,state='disabled').place(x=28
0,y=50,height=100)

boton4b=Button(v0,image=imgboton4b,command=Foco4off,state='normal',width=100).place(x=4
00,y=50,height=100)

tkMessageBox.showinfo("Habitacion 4",message="Foco 4 Encendido")

def Foco4off():

18
os.system("/./home/pi/foco4off.sh")

boton4=Button(v0,image=imgboton4,command=Foco4on,width=100,state='normal').place(x=280,
y=50,height=100)

boton4b=Button(v0,image=imgboton4b,command=Foco4off,state='disabled',width=100).place(x=
400,y=50,height=100)

tkMessageBox.showinfo("Habitacion 4",message="Foco 4 Apagado")

def alarmaON():

os.system("/./home/pi/alarma.sh")

boton8=Button(v0,image=imgboton7,command=alarmaOFF,width=100).place(x=590,y=50,height=
100)

def alarmaOFF():

os.system("/./home/pi/alarmaoff.sh")

boton7=Button(v0,image=imgboton7,command=alarmaON,width=100).place(x=590,y=50,height=
100)

# Metodo para concatenar numeros en la caja1-variable->cod, al presionar diferentes botones

def btnClick(numbers):

global operator

operator=operator+str(numbers)

cod.set(operator)

def btnClsCaja1():

global operator

operator=""

cod.set(operator)

19
# Defincion de la Ventana Principal (ventana Padre)

v0=Tk()

v0.geometry("820x527+300+130")

v0.title("ELECTRONIC SECURITY SYSTEMS")

def Funcion():

print

menu_general = Menu(v0)

v0["menu"] = menu_general #hacemos que la ventana tenga de menu a "menu_general"

menu_archivo = Menu(menu_general) #menu archivo

menu_archivo.add_command(label = "Programar Focos", command = toplevel2)

menu_archivo.add_command(label = "Programar Alarma", command = toplevel)

menu_archivo.add_separator()

menu_archivo.add_command(label = "Salir", command = v0.destroy)

menu_general.add_cascade(label = "Archivo", menu = menu_archivo)

menu_ayuda = Menu(menu_general) #menu ayuda

menu_ayuda.add_command(label = "Acerca de...", command = toplevel3)

menu_general.add_cascade(label = "Ayuda", menu = menu_ayuda)

# Asignar imagenes a Foco1


bgtext1 = tkFont.Font(family="Helvetica", size=12, weight="bold")

label1=Label(v0,text="HABITACION 1",font=bgtext1).place(x=70,y=10)

imgboton1=PhotoImage(file="on.gif")

boton1=Button(v0,image=imgboton1,command=Foco1on).place(x=20,y=50,height=100,width=100
) #command=Foco1on: ESTO HACE LA FUNCION DE ENCENDER EL FOCO (ARRIBA ESTA LA
PROGRAMACION)

20
imgboton1b=PhotoImage(file="of.gif")

boton1b=Button(v0,image=imgboton1b,command=Foco1off,state='disabled',width=100).place(x=
140,y=50,height=100) #STATE=DISABLED: ESTO HACE QUE AL INICIAR EL PROGRAMA SE
DESHABILITEN EL BOTON DE DESACTIVAR FOCO 1 PARA EVITAR QUE UN FOCO QUE ESTE
APAGADO LO PUEDA VOLVER APAGAR

# Asignar imagenes a Foco2


bgtext2= tkFont.Font(family="Helvetica", size=12, weight="bold")

label2=Label(v0,text="HABITACION 2",font=bgtext2).place(x=70,y=160)

imgboton2=PhotoImage(file="on.gif")

boton2=Button(v0,image=imgboton2,command=Foco2on,width=100).place(x=20,y=205,height=10
0)

imgboton2b=PhotoImage(file="of.gif")

boton2b=Button(v0,image=imgboton2b,command=Foco2off,state='disabled',width=100).place(x=
140,y=205,height=100)

# Asignar Imagen a Foco3


bgtext3= tkFont.Font(family="Helvetica", size=12, weight="bold")

label3=Label(v0,text="HABITACION 3",font=bgtext3).place(x=70,y=315)

imgboton3=PhotoImage(file="on.gif")

boton3=Button(v0,image=imgboton3,command=Foco3on,width=100).place(x=20,y=360,height=10
0)

imgboton3b=PhotoImage(file="of.gif")

boton3b=Button(v0,image=imgboton3b,command=Foco3off,state='disabled',width=100).place(x=
140,y=360,height=100)

# Asignar Imagen a Foco4


bgtext4=tkFont.Font(family="Helvetica", size=12, weight="bold")

label4=Label(v0,text="HABITACION 4",font=bgtext4).place(x=320,y=10)

imgboton4=PhotoImage(file="on.gif")

boton4=Button(v0,image=imgboton4,command=Foco4on,width=100).place(x=280,y=50,height=10
0)
21
imgboton4b=PhotoImage(file="of.gif")

boton4b=Button(v0,image=imgboton4b,command=Foco4off,state='disabled',width=100).place(x=
400,y=50,height=100)

# Asignar Imagen a Alarma


bgtext7=tkFont.Font(family="Helvetica",size=12,weight="bold")

label7=Label(v0,text="ALARMA-SECTORIAL",font=bgtext7).place(x=560,y=7)

imgboton7=PhotoImage(file="Alarma.gif")

boton7=Button(v0,image=imgboton7,command=alarmaON,width=100).place(x=590,y=50,height=
100)

bgtext8=tkFont.Font(family="Helvetica",size=18,weight="bold")

label8=Label(v0,text="Electronic Security Systems v1.1",font=bgtext8).place(x=320,y=310)

v0.mainloop()

22
# Alarma.sh
#bin/bash

clear

echo 11 > /sys/class/gpio/export

echo out > /sys/class/gpio/gpio11/direction

echo 1 > /sys/class/gpio/gpio11/valve;

# Alarmaoff.sh
#bin/bash

clear

echo 0 > /sys/class/gpio/gpio11/valve

echo 11 > /sys/class/gpio/unexport;

# Correo.sh
#!/bin/bash

rm -f /tmp/out.mail

uuencode /home/pi/Foto1.jpg Foto1.jpg > /tmp/out.mail

mail -s "Alarma Peligro" anthonypazuth@gmail.com < /tmp/out.mail

echo "El Correo fue enviado exitosamente"

#Foco1.sh
#bin/bash

clear

echo 17 > /sys/class/gpio/export

echo out > /sys/class/gpio/gpio17/direction

echo 1 > /sys/class/gpio/gpio17/valve;

23
#Foco1off.sh
#bin/bash

clear

echo 0 > /sys/class/gpio/gpio17/valve

echo 17 > /sys/class/gpio/unexport;+

#Foco2.sh
#bin/bash

clear

echo 18 > /sys/class/gpio/export

echo out > /sys/class/gpio/gpio18/direction

echo 1 > /sys/class/gpio/gpio18/valve;

#Foco2off.sh
#bin/bash

clear

echo 0 > /sys/class/gpio/gpio18/valve

echo 18 > /sys/class/gpio/unexport;

#Foco3.sh
#bin/bash

clear

echo 27 > /sys/class/gpio/export

echo out > /sys/class/gpio/gpio27/direction

echo 1 > /sys/class/gpio/gpio27/valve;

#Foco3off.sh
#bin/bash

24
clear

echo 0 > /sys/class/gpio/gpio27/valve

echo 27 > /sys/class/gpio/unexport;

#Foco4.sh
#bin/bash

clear

echo 22 > /sys/class/gpio/export

echo out > /sys/class/gpio/gpio22/direction

echo 1 > /sys/class/gpio/gpio22/valve;

#Foco4off.sh
#bin/bash

clear

echo 0 > /sys/class/gpio/gpio22/valve

echo 22 > /sys/class/gpio/unexport;

#Foto.sh
SAVEDIR=/home/pi

filename=Foto1.jpg

/opt/vc/bin/raspistill --rotation 0 --exposure auto -w 1024 -h 768 -x -n -e bmp -o - | convert -


pointsize 30 -fill red -annotate +15+700 "Fecha y Hora - $(date +%D-%H:%M)" -
$SAVEDIR/$filename &

#Alarma2.py
#!/usr/bin/python3

import subprocess

import time

25
import pygame

import os

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

GPIO.setwarnings(False)

GPIO_PIR = 12 #Se establece al Gpio 12

GPIO.setup(GPIO_PIR,GPIO.IN)

num=0

status0 = 0

status1 = 0

try:

while True:

status0 = 0

print("Listo para comenzar!")

while True:

status0 = GPIO.input(GPIO_PIR)

if status0==1 and status1==0:

num=num+1

print("Atencion, se ha detectado movimiento ",num,"")

status1=1

os.system("/./home/pi/foto.sh") #Al detectar movimiento que tome una Foto

print("La Foto fue Tomada con Exito")

subprocess.call("/./etc/ssmtp/correo.sh") #La Foto que se tomo se enviara al


correo anthonypazuth@gmail.com

time.sleep(3.00) #Una vez enviado el correo se espera 3 segundos y se activara


la alarma

os.system('/./home/pi/alarma.sh') #Ejecuta la Alarma

time.sleep(3.00) #La alarma sonara 3 segundos y despues se desactiva


26
os.system('/./home/pi/alarmaoff.sh') #La Alarma se desactiva

elif status0==0 and status1==1:

print("Listo para comenzar!")

status1=0

time.sleep(0.01) #El ciclo se repite hasta que haya pasado el tiempo


programado!

except KeyboardInterrupt:

GPIO.cleanup()

#ApagarAlarma2.py

#!/usr/bin/python2

import subprocess

import time

import pygame

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

GPIO.setwarnings(False)

GPIO_PIR = 12

GPIO.setup(GPIO_PIR,GPIO.OUT) #Establece el Gpio en OUT

27
Anexos

28

También podría gustarte