コード例 #1
0
ファイル: video-monitor.py プロジェクト: stevewoolley/IoT
# logging setup
logger = set_logger(level=args.log_level)

video = Video(
    rotation=args.rotation,
    horizontal_resolution=args.horizontal_resolution,
    vertical_resolution=args.vertical_resolution
)
video.start()

pir = PIR(args.pin)
pir.start()

mqtt = MqttClient(args.endpoint, args.log_level, args.port)
mqtt.set_tls(args.ca_file, args.client_cert_file, args.client_key_file)
mqtt.add_callback(args.topic + args.subtopic, receive_command)
mqtt.add_subscription(args.topic + args.subtopic, qos=args.qos)
mqtt.loop_start()

# loop
while True:
    is_moving = pir.detects_movement()
    if is_monitoring:
        if not is_moving:
            if video.recording:
                Video.generate_thumbnail(video.stop_recording(), hres=args.horizontal_resolution,
                                         vres=args.vertical_resolution)
        elif is_moving:
            video.start_recording()
    sleep(args.wait)
コード例 #2
0
ファイル: motion-test.py プロジェクト: stevewoolley/IoT
#!/usr/bin/env python
import argparse
from pir import PIR
import time

# parse arguments
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--pin", help="gpio pin (using BCM numbering)", type=int, default=4)
args = parser.parse_args()

pir = PIR(args.pin)
pir.start()

last = None
while True:
    try:
        reading = pir.detects_movement()
        if reading != last:
            print("Motion: %s" % (reading))
            last = reading
    except KeyboardInterrupt:
        print "Shutting Down"
    time.sleep(0.1)