You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#!/usr/bin/python
# encoding:utf-8
# 目前用的人体红外传感器模块是最迷你型的,因此感应的距离只有一米
# 当检测到人体活动时, 会持续高电平2~ 4秒
import RPi . GPIO as GPIO
import time
import renlian as rl
import lighting as l
import MySQL as m
import jiqiren as jqr
import huoyan as hy
# !/usr/bin/python
# encoding:utf-8
def gy ( ) :
Infrared = 22
GPIO . setmode ( GPIO . BCM )
GPIO . setup ( Infrared , GPIO . IN )
for i in range ( 5 ) :
t = time . strftime ( ' % Y- % m- %d % H: % M: % S ' )
if ( GPIO . input ( Infrared ) == True ) :
print ( t + " 家居环境异常 ! " )
GPIO . cleanup ( Infrared )
return t
else :
# print(t + " Nobody !")
time . sleep ( 0.1 )
GPIO . cleanup ( Infrared )
return 0
# gy()
# time.sleep(10) #找出感应器重置的时间
# gy()
def check_env ( ) :
hy . hy ( )
sign = gy ( )
if ( sign != 0 ) :
jqr . Key ( " 检测到环境异常!即将启动自动监控! " )
while True :
l . L_hcsr_open ( )
id = rl . auto_video ( )
if ( id [ 1 ] == 0 ) :
jqr . Key ( " 警报解除! " )
l . L_hcsr_close ( )
break
sign = gy ( )
if ( sign != 0 ) :
jqr . Key ( " 警告警告!环境异常! " )
m . hcsr_update ( " hcsr " , " alarm_time " , sign , id [ 0 ] )
continue
else :
jqr . Key ( " 警报解除! " )
l . L_hcsr_close ( )
break
# check_env()