-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultisensor.py
86 lines (73 loc) · 3.05 KB
/
multisensor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import os
import threading
import time
import RPi.GPIO as GPIO
#import smbus2 as smbus
##local references
import picamera_video as video
#import thermal_AMG8833 as grideye
import temperature_BME280 as temperature
import getCPUserial as serial
#import someaudio as audio
#import airquality_SGP30 as airquality
##GPIO setting up for PIR and LED
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN)
#GPIO.setup(24, GPIO.OUT)
##Specify the functoin in each ref
#str_video = "video.capture(25,60)"
#str_audio =
#ge = grideye.GridEye(i2c_bus=smbus.SMBusWrapper(1))
#str_grideye = "ge.get_thermistor_temp()"
#str_grideye = "GridEye.get_thermistor_temp()"
#str_temperature = "temperature.readBME280All()"
#str_airquality = "airquality.getvalue()"
##generating threads
#thread_video = threading.Thread(target = str_video)
#thread_audio = threading.Thread(target = str_audio)
#thread_grideye = threading.Thread(target = str_grideye)
#thread_temperature = threading.Thread(target = str_temperature)
#thread_airquality = threading.Thread(target = str_airquality)
thread_video = threading.Thread(target = video.capture(25,60))
#thread_audio = threading.Thread(target = )
#thread_grideye = threading.Thread(target = grideye.GridEye.get_thermistor_temp())
thread_temperature = threading.Thread(target = temperature.readBME280All())
#thread_airquality = threading.Thread(target = airquality.getvalue())
##main
try:
time.sleep(2) # to stabilize sensor
SerialNumber = serial.getserial()
print("IR detection in progress..")
while True:
if GPIO.input(4):
Startingtime = time.time()
Log = open("%s" % Startingtime + "_%s.txt" % SerialNumber,'a')
# GPIO.output(24, True)
# time.sleep(0.5) #LED turns on for 0.5 sec
# GPIO.output(24, False)
print("Motion Detected. Data gatehring in progress...")
##Capturing video clip. output will be "temporary.h264" and be converted later
thread_video.start()
for i in range(750):
##?format/dimension? Getting data from grideye in 25fps
# value0 = thread_grideye.start()
##?format/dimension? Getting data from BMP280 and SGP30 in 1 fps (putting NA for most points)
if i % 25 == 0:
value1 = thread_temperature.start()
value2 = thread_airquality.start()
else:
value1 = "NA"
value2 = "NA"
##Writing gatehred values
# Log.write("%s," % value0)
Log.write("%s," % value1)
Log.write("%s\n" % value2)
time.sleep(1/25)
##converting video clip to mp4
os.system("MP4Box -add temporary.h264" + " %s.mp4" % Startingtime)
os.system("rm temporary.h264")
##For PIR
time.sleep(2) #to avoid multiple detection
time.sleep(0.1) #loop delay, should be less than detection delay
except:
GPIO.cleanup()