Exemple #1
0
    def idle_handler(self, widget):
        use_tmp_file = False
        if use_tmp_file:
            tmpfile = "/tmp/still.jpg"
            print "Snapping to", tmpfile
            take_still(outfile=tmpfile, res=self.test_res, verbose=False)
            im = Image.open(tmpfile)
        else:
            print "Snapping to memory"
            img_data = take_still(outfile='-',
                                  res=self.test_res,
                                  verbose=False)
            im = Image.open(img_data)

        different, debugimage = self.md.compare_images(im)
        if different:
            print "They're different!"

        # debugimage.load()
        self.load_image(debugimage)
        self.show_image()

        self.buf1 = self.buf2

        return True
Exemple #2
0
    def idle_handler(self, widget):
        use_tmp_file = False
        if use_tmp_file:
            tmpfile = "/tmp/still.jpg"
            print "Snapping to", tmpfile
            take_still(outfile=tmpfile, res=self.test_res, verbose=False)
            im = Image.open(tmpfile)
        else:
            print "Snapping to memory"
            img_data = take_still(outfile='-', res=self.test_res, verbose=False)
            im = Image.open(img_data)

        different, debugimage = self.md.compare_images(im)
        if different:
            print "They're different!"

        # debugimage.load()
        self.load_image(debugimage)
        self.show_image()

        self.buf1 = self.buf2

        return True
    def run(self, interactive, latency, pic_mode, local_mode, notify_mode) :

        global BASEDIR_FOR_PIDOORBELL_VIDEOS, \
               MIN_TRIGGER_DISTANCE, MAX_TRIGGER_DISTANCE, \
               BASEPORT_FOR_SENSOR_DATA, BASEPORT_BAUD_RATE

        if not local_mode:
            import sms_auth_info

        valid_pic_count = 0

        try:
            init_HC_SR04()

            while True :
                data = average_distance()
                if not data :
                    continue

                if not interactive :
                    print data
                    continue

                print "Distance: %.1f inches" % data
                print data
                if int(data) <= MIN_TRIGGER_DISTANCE or int(data) >= MAX_TRIGGER_DISTANCE:
                    continue

                # There's an object in the target distance range
                print "******  DETECTED AN OBJECT AT --    ", data ,"-- INCHES ****** "

                valid_pic_count += 1

                if valid_pic_count < VALID_PIC_THRESHOLD:
                    continue

                # We have enough pics:
                # build pidoorbell_filename with date and timestamp
                now = datetime.datetime.now()

                if pic_mode == VIDEO:
                    pidoorbell_filename = "visitor-video-%d:%d:%d-%d:%d.mpg" % \
                        (now.year, now.month, now.day, now.hour, now.minute)
                    #take a video snippet 
                    take_videoclip_cmd = FFMPEG_CMD + pidoorbell_filename

                    print PRINT_STARTING_VIDEOCLIP

                    videoclip_cmd_rc = call(take_videoclip_cmd, shell=True)

                    print PRINT_STOPPING_VIDEOCLIP + pidoorbell_filename

                # default to photo
                else: 
                    pidoorbell_filename = "visitor-photo-%d:%d:%d-%d:%d.jpg" % \
                               (now.year, now.month, now.day, now.hour, now.minute)
                    # take a photo snippet
                    try:
                        take_still(BASEDIR_FOR_PIDOORBELL_VIDEOS+pidoorbell_filename, verbose=True)
                    except SystemError:
                        print "Couldn't take a photo"
                        continue

                #reset valid_pic_count
                valid_pic_count = 0

                if local_mode:
                    print "Local mode: not syncing to the outside world"
                    sleep(DELAY_BETWEEN_VISITORS)
                    continue

                # Not local mode, so proceed with dropbox and sms:
                print PRINT_UPLOAD_TO_DROPBOX

                sync_dropbox_cmd = "./dropbox_uploader.sh upload ./dropbox-pidoorbell/" + \
                    pidoorbell_filename + " "+ pidoorbell_filename
                process = Popen(sync_dropbox_cmd, shell=True)

                ## account for network latency 
                print "latency is %s " % latency
                sleep(float(latency))

                get_link_cmd = "./dropbox_uploader.sh share " + pidoorbell_filename

                p = Popen(get_link_cmd, stdout=PIPE, shell=True)
                (output, err) = p.communicate()

                # Send notifications using both Twilio (USA) and Twitter (worldwide)
                # for demo purposes.  Else, use "-m sms" for SMS, "-m tweet" for TWITTER
                # See definitions section for predefined vars to use (SEND_NOTIFICATIONS_SMS,
                # SEND_NOTIFICATIONS_TWEET)

		if notify_mode == "local":
			break;
		else:
		    if notify_mode == "sms":
                       send_sms_cmd = SEND_NOTIFICATIONS_SMS + output
		    elif notify_mode == "tweet":
                       send_sms_cmd = SEND_NOTIFICATIONS_TWEET + output
		    elif notify_mode == "all":
                       send_sms_cmd = SEND_NOTIFICATIONS_ALL + output

                    sms_url_rc = call(send_sms_cmd, shell=True)

                #sleep for a short while before checking again
                sleep(DELAY_BETWEEN_VISITORS)

                print "Done sleeping  - I'm awake again!!!! "
                continue      

        except KeyboardInterrupt:
            # User pressed CTRL-C: reset GPIO settings.
            print "Cleaning up ..."
            GPIO.cleanup()