Exemplo n.º 1
0
    def pir_led(self,args):
        register_set = Message(arlo.messages.REGISTER_SET)
        enabled = args['enabled']
        sensitivity = args['sensitivity']

        register_set["SetValues"] = {
            "PIREnableLED":enabled,
            "PIRLEDSensitivity":sensitivity
            }

        return self.send_message(register_set)
Exemplo n.º 2
0
    def set_quality(self,args):
        quality = args["quality"].lower()
        if quality == "low":
            ra_params = Message(arlo.messages.RA_PARAMS_LOW_QUALITY)
            registerSet = Message(arlo.messages.REGISTER_SET_LOW_QUALITY)
        elif quality == "medium":
            ra_params = Message(arlo.messages.RA_PARAMS_MEDIUM_QUALITY)
            registerSet = Message(arlo.messages.REGISTER_SET_MEDIUM_QUALITY)
        elif quality == "high":
            ra_params = Message(arlo.messages.RA_PARAMS_HIGH_QUALITY)
            registerSet = Message(arlo.messages.REGISTER_SET_HIGH_QUALITY)
        elif quality == "subscription":
            ra_params = Message(arlo.messages.RA_PARAMS_SUBSCRIPTION_QUALITY)
            registerSet = Message(arlo.messages.REGISTER_SET_SUBSCRIPTION_QUALITY)
        else:
            return False

        return self.send_message(ra_params) and self.send_message(registerSet)
Exemplo n.º 3
0
    def arm(self,args):
        register_set = Message(arlo.messages.REGISTER_SET)
        pir_target_state = args['PIRTargetState']
        video_motion_estimation_enable = args['VideoMotionEstimationEnable']
        audio_target_state = args['AudioTargetState']

        register_set["SetValues"] = {
                "PIRTargetState":pir_target_state,
                "PIRStartSensitivity":80,
                "PIRAction":"Stream",
                "VideoMotionEstimationEnable":video_motion_estimation_enable,
                "VideoMotionSensitivity":80,
                "AudioTargetState":audio_target_state,
                "DefaultMotionStreamTimeLimit":10 # Unclear what this does, only set in normal traffic when 'Disarmed'
            }

        return self.send_message(register_set)
Exemplo n.º 4
0
 def receive(self):
     data = self.sock.recv(1024).decode(encoding="utf-8")
     if data.startswith("L:"):
         delimiter = data.index(" ")
         dataLength = int(data[2:delimiter])
         json_data = data[delimiter+1:delimiter+1+dataLength]
     else:
         return None
     read = len(json_data)
     while read < dataLength:
         to_read = min(dataLength - read, 1024)
         chunk = self.sock.recv(to_read)
         if chunk == b'':
             raise RuntimeError("socket connection broken")
         chunk_str = chunk.decode(encoding="utf-8")
         json_data += chunk_str
         read = read + len(chunk_str)
     return Message(json.loads(json_data))
Exemplo n.º 5
0
 def unset_activity_zones(self,args):
     activity_zones = Message(arlo.messages.ACTIVITY_ZONE_DELETE)
     return self.send_message(activity_zones)
Exemplo n.º 6
0
 def set_activity_zones(self,args):
     activity_zones = Message(arlo.messages.ACTIVITY_ZONE_ALL)
     # TODO:Set The Co-ordinates  
     return self.send_message(activity_zones)
Exemplo n.º 7
0
 def speaker_request(self, enabled):
     register_set = Message(arlo.messages.REGISTER_SET)
     register_set['AudioSpkrEnable'] = enabled
     return self.send_message(register_set)
Exemplo n.º 8
0
 def snapshot_request(self, url):
     _snapshot_request = Message(arlo.messages.SNAPSHOT)
     _snapshot_request['DestinationURL'] = url
     return self.send_message(_snapshot_request)
Exemplo n.º 9
0
 def status_request(self):
     _status_request = Message(arlo.messages.STATUS_REQUEST)
     return self.send_message(_status_request)
Exemplo n.º 10
0
 def set_user_stream_active(self,active):
     register_set = Message(arlo.messages.REGISTER_SET)
     register_set['SetValues']['UserStreamActive'] = int(active)
     return self.send_message(register_set)
Exemplo n.º 11
0
    def run(self):
        while True:
            timestr = time.strftime("%Y%m%d-%H%M%S")
            msg = self.connection.receive()
            if msg != None:
                if (msg['Type'] == "registration"):
                    camera = Camera.from_db_serial(msg['SystemSerialNumber'])
                    if camera is None:
                        camera = Camera(self.ip, msg)
                    else:
                        camera.registration = msg
                    camera.persist()
                    s_print(
                        f"<[{self.ip}][{msg['ID']}] Registration from {msg['SystemSerialNumber']} - {camera.hostname}"
                    )
                    if msg['SystemModelNumber'] == 'VMC5040':
                        registerSet = Message(
                            arlo.messages.REGISTER_SET_INITIAL_ULTRA)
                    else:
                        registerSet = Message(
                            arlo.messages.REGISTER_SET_INITIAL)
                    registerSet['WifiCountryCode'] = WIFI_COUNTRY_CODE
                    camera.send_message(registerSet)
                elif (msg['Type'] == "status"):
                    s_print(
                        f"<[{self.ip}][{msg['ID']}] Status from {msg['SystemSerialNumber']}"
                    )
                    camera = Camera.from_db_serial(msg['SystemSerialNumber'])
                    camera.ip = self.ip
                    camera.status = msg
                    camera.persist()
                elif (msg['Type'] == "alert"):
                    camera = Camera.from_db_ip(self.ip)
                    alert_type = msg['AlertType']
                    s_print(f"<[{self.ip}][{msg['ID']}] {msg['AlertType']}")
                    if alert_type == "pirMotionAlert" and RECORD_ON_MOTION_ALERT:
                        filename = f"{RECORDING_BASE_PATH}{camera.serial_number}_{timestr}_motion.mpg"
                        recorder = Recorder(self.ip, filename,
                                            MOTION_RECORDING_TIMEOUT)
                        with recorder_lock:
                            if self.ip in recorders:
                                recorder[self.ip].stop()
                            recorders[self.ip] = recorder
                        recorder.run()
                        webhook_manager.motion_detected(
                            camera.ip, camera.friendly_name, camera.hostname,
                            camera.serial_number, msg['PIRMotion']['zones'],
                            filename)
                    elif alert_type == "audioAlert" and RECORD_ON_AUDIO_ALERT:
                        recorder = Recorder(
                            self.ip,
                            f"{RECORDING_BASE_PATH}{camera.serial_number}_{timestr}_audio.mpg",
                            AUDIO_RECORDING_TIMEOUT)
                        with recorder_lock:
                            if self.ip in recorders:
                                recorder[self.ip].stop()
                            recorders[self.ip] = recorder
                        recorder.run()
                    elif alert_type == "motionTimeoutAlert":
                        with recorder_lock:
                            if self.ip in recorders and recorders[
                                    self.ip] is not None:
                                recorders[self.ip].stop()
                                del recorders[self.ip]
                else:
                    s_print(f"<[{self.ip}][{msg['ID']}] Unknown message")
                    s_print(msg)

                ack = Message(arlo.messages.RESPONSE)
                ack['ID'] = msg['ID']
                s_print(f">[{self.ip}][{msg['ID']}] Ack")
                self.connection.send(ack)
                self.connection.close()
                break