Ejemplo n.º 1
0
 def saveImage(self,settings, width, height, quality, diskSpaceToReserve):
     self.keepDiskSpaceFree(diskSpaceToReserve)
     time = datetime.now()
     filename = filepath + "/" + filenamePrefix + "-%04d%02d%02d-%02d%02d%02d.jpg" % (time.year, time.month, time.day, time.hour, time.minute, time.second)
     subprocess.call("raspistill %s -w %s -h %s -t 200 -e jpg -q %s -n -o %s" % (settings, width, height, quality, filename), shell=True)
     #print "Captured %s" % filename
     Helper.log("Captured %s" % filename)
Ejemplo n.º 2
0
 def keepDiskSpaceFree(self,bytesToReserve):
     if (self.getFreeSpace() < bytesToReserve):
         for filename in sorted(os.listdir(filepath + "/")):
             if filename.startswith(filenamePrefix) and filename.endswith(".jpg"):
                 os.remove(filepath + "/" + filename)
                 #print "Deleted %s/%s to avoid filling disk" % (filepath,filename)
                 Helper.log("Deleted %s/%s to avoid filling disk" % (filepath,filename))
                 if (self.getFreeSpace() > bytesToReserve):
                     return
Ejemplo n.º 3
0
 def check_inactivity(self):
     try:
         while (time.time() - self.latestActivity) < self.maxInactivityTime:
             print "Inaktivitaet: Client aktiv?"
             time.sleep(5)
         
         Helper.log("Client inactive, diconncted.")
         self.write_message("Inactive.. Disconnected!")
         self.close()
         self.on_close()
     except tornado.websocket.WebSocketClosedError:
         print "Inaktivitaet: Inaktivter Client hat Seite bereits verlassen.."
Ejemplo n.º 4
0
 def open(self):
     #Globals.COUNT_CLIENTS
     #print "WebSocket opened"
     Helper.log("WebSocket opened")
     Globals.COUNT_CLIENTS  = Globals.COUNT_CLIENTS + 1
     
     # Variable mit Timestamp der letzten Aktion, wird in on_message aktualisiert
     self.latestActivity = time.time()
     
     # Nur 1 Client darf Kamera kontrollieren
     if Globals.COUNT_CLIENTS > 1:
         self.write_message("Camera already in use.. Disconnected!")
         Globals.COUNT_CLIENTS  = Globals.COUNT_CLIENTS - 1
         self.close()
     
     # Pruefen ob der Client inactiv wird
     self.activityThread = thread.start_new_thread(self.check_inactivity,()) 
Ejemplo n.º 5
0
 def on_message(self, message):
     #global PAN_START_ANGLE,TILT_START_ANGLE
     self.latestActivity = time.time()
     return_message = "Camera moved!"
     try:
        
         result = json.loads(message)
         Helper.log("JSON erhalten: %s" % (result))
         #print result
         delta = float(result['delta'])
         #Horizontale Bewegung
         if result['direction'] == 'h':
             #print "Horizontal:"
             if (Globals.PAN_START_ANGLE + delta) > self.MAX_ANGLE or (Globals.PAN_START_ANGLE + delta) < self.MIN_ANGLE:
                  return_message ="Maximum pan stop reached!"
             else: 
                 Globals.PAN_START_ANGLE = Globals.PAN_START_ANGLE + delta
                 #print "Horizontal: Move to " + str(Globals.PAN_START_ANGLE)
                 Helper.log("Horizontal: Move to " + str(Globals.PAN_START_ANGLE))
                 Globals.panServoPWM.setCommand(Globals.PAN_START_ANGLE)
         elif result['direction'] == 'v':
             print "Vertikal:"
         #Vertikale Bewegung
             if (Globals.TILT_START_ANGLE  + delta) > self.MAX_ANGLE or (Globals.TILT_START_ANGLE  + delta) < self.MIN_ANGLE:
                  return_message ="Maximum tilt stop reached!"
             else:
                 Globals.TILT_START_ANGLE = Globals.TILT_START_ANGLE + delta
                 Helper.log("Vertikal: Move to " + str(Globals.PAN_START_ANGLE))
                 Globals.tiltServoPWM.setCommand(Globals.TILT_START_ANGLE)
         else:
             print "initialize.."
             
         
         # Ergebnis zurueckgeben
         self.write_message(return_message)
     except ValueError:
         #print "invalid json.."
         Helper.log("Received invalid JSON")
Ejemplo n.º 6
0
def exitThreads():
    Helper.log("Hoticam duch Signal beendet")
    global picamThread
    global cameraStream
    print ("You pressed Ctrl+C!")
    # Threads beenden
    try:
        if cameraStream.isAlive():
            cameraStream.stop()
            cameraStream.join()
    except AttributeError:
        Helper.log("CameraStream Undefined..")
    try:
        if picamThread.isAlive():
            picamThread.stop()
    except AttributeError:
        print "picamThread Undefined.."
        Helper.log("picamThread Undefined..")
    sys.exit(0)
Ejemplo n.º 7
0
def switchStreamOrMotion():
    global picamThread
    global cameraStream
    picamThread = PicamThread()
    cameraStream = CameraStream()

    while True:
        if Globals.COUNT_CLIENTS > 0:
            if not cameraStream.isAlive():
                Helper.log("Stope Bewegungserkennung")
                picamThread.stop()
                picamThread.join()
                Helper.log("Schalte um auf Streaming")
                cameraStream.start()
            else:
                Helper.log("Stream laeuft..")
        else:
            # Wenn Stream laeuft, beenden
            if cameraStream.isAlive():
                cameraStream.stop()
            # Wenn Thread beendet wurde, neuen Thread erstellen
            if picamThread.stopped():
                picamThread = PicamThread()
            if not picamThread.isAlive():
                Helper.log("Stoppe Streaming")
                picamThread.start()
                Helper.log("Schalte um auf Bewegungserkennung")
            else:
                # print "motion laeuft bereits!"
                Helper.log("Bewegungserkennung laeuft")
        time.sleep(5)
Ejemplo n.º 8
0
        Helper.log("CameraStream Undefined..")
    try:
        if picamThread.isAlive():
            picamThread.stop()
    except AttributeError:
        print "picamThread Undefined.."
        Helper.log("picamThread Undefined..")
    sys.exit(0)


application = tornado.web.Application([(r"/", WebSocketServer)])

if __name__ == "__main__":
    try:

        Helper.log("Starte Hoticam")

        # Create ServoPWM instances to control the servos

        Globals.tiltServoPWM = ServoPWM(
            TILT_PWM_PIN,
            minAnglePulseWidthPair=(0.0, 2350),
            midAnglePulseWidthPair=(90.0, 1500),
            maxAnglePulseWidthPair=(180.0, 500.0),
        )
        Globals.panServoPWM = ServoPWM(
            PAN_PWM_PIN,
            minAnglePulseWidthPair=(0.0, 610.0),
            midAnglePulseWidthPair=(90.0, 1500),
            maxAnglePulseWidthPair=(180.0, 2350),
        )
Ejemplo n.º 9
0
 def on_close(self):
     #global COUNT_CLIENTS
     Globals.COUNT_CLIENTS  = Globals.COUNT_CLIENTS - 1
     Helper.log("WebSocket closed")