コード例 #1
0
ファイル: mjpgclient.py プロジェクト: jmichault/motioneye.eo
    def on_close(self):
        logging.debug(
            'connection closed for mjpg client for camera %(camera_id)s on port %(port)s'
            % {
                'port': self._port,
                'camera_id': self._camera_id
            })

        if MjpgClient.clients.pop(self._camera_id, None):
            logging.debug(
                'mjpg client for camera %(camera_id)s on port %(port)s removed'
                % {
                    'port': self._port,
                    'camera_id': self._camera_id
                })

        if getattr(self, 'error',
                   None) and self.error.errno != errno.ECONNREFUSED:
            now = time.time()
            if now - MjpgClient._last_erroneous_close_time < settings.MJPG_CLIENT_TIMEOUT:
                msg = 'connection problem detected for mjpg client for camera %(camera_id)s on port %(port)s' % {
                    'port': self._port,
                    'camera_id': self._camera_id
                }

                logging.error(msg)

                if settings.MOTION_RESTART_ON_ERRORS:
                    motionctl.stop(invalidate=True
                                   )  # this will close all the mjpg clients
                    motionctl.start(deferred=True)

            MjpgClient._last_erroneous_close_time = now
コード例 #2
0
def start_motion():
    from motioneye import config
    from motioneye import motionctl

    io_loop = IOLoop.instance()

    # add a motion running checker
    def checker():

        if not motionctl.running() and motionctl.started(
        ) and config.get_enabled_local_motion_cameras():
            try:
                logging.error('motion not running, starting it')
                motionctl.start()

            except Exception as e:
                logging.error('failed to start motion: %(msg)s' %
                              {'msg': str(e)},
                              exc_info=True)

        io_loop.add_timeout(
            datetime.timedelta(seconds=settings.MOTION_CHECK_INTERVAL),
            checker)

    try:
        motionctl.start()

    except Exception as e:
        logging.error(str(e), exc_info=True)

    io_loop.add_timeout(
        datetime.timedelta(seconds=settings.MOTION_CHECK_INTERVAL), checker)
コード例 #3
0
    def rem_camera(self, camera_id):
        logging.debug('removing camera %(id)s' % {'id': camera_id})

        local = utils.is_local_motion_camera(config.get_camera(camera_id))
        config.rem_camera(camera_id)

        if local:
            motionctl.stop()
            motionctl.start()

        return self.finish_json()
コード例 #4
0
ファイル: smbctl.py プロジェクト: jmichault/motioneye.eo
def _check_mounts():
    from motioneye import motionctl

    logging.debug('checking SMB mounts...')

    stop, start = update_mounts()
    if stop:
        motionctl.stop()

    if start:
        motionctl.start()

    io_loop = IOLoop.instance()
    io_loop.add_timeout(
        datetime.timedelta(seconds=settings.MOUNT_CHECK_INTERVAL),
        _check_mounts)
コード例 #5
0
ファイル: mjpgclient.py プロジェクト: jmichault/motioneye.eo
def _garbage_collector():
    io_loop = IOLoop.instance()
    io_loop.add_timeout(
        datetime.timedelta(seconds=settings.MJPG_CLIENT_TIMEOUT),
        _garbage_collector)

    now = time.time()
    for camera_id, client in list(MjpgClient.clients.items()):
        port = client.get_port()

        if client.closed():
            continue

        # check for jpeg frame timeout
        last_jpg_time = client.get_last_jpg_time()
        delta = now - last_jpg_time
        if delta > settings.MJPG_CLIENT_TIMEOUT:
            logging.error(
                'mjpg client timed out receiving data for camera %(camera_id)s on port %(port)s'
                % {
                    'camera_id': camera_id,
                    'port': port
                })

            if settings.MOTION_RESTART_ON_ERRORS:
                motionctl.stop(
                    invalidate=True)  # this will close all the mjpg clients
                motionctl.start(deferred=True)

            break

        # check for last access timeout
        delta = now - client.get_last_access()
        if settings.MJPG_CLIENT_IDLE_TIMEOUT and delta > settings.MJPG_CLIENT_IDLE_TIMEOUT:
            msg = (
                'mjpg client for camera %(camera_id)s on port %(port)s has been idle '
                'for %(timeout)s seconds, removing it' % {
                    'camera_id': camera_id,
                    'port': port,
                    'timeout': settings.MJPG_CLIENT_IDLE_TIMEOUT
                })

            logging.debug(msg)

            client.close()

            continue
コード例 #6
0
    async def add_camera(self):
        logging.debug('adding new camera')

        try:
            device_details = json.loads(self.request.body)

        except Exception as e:
            logging.error('could not decode json: %(msg)s' % {'msg': str(e)})

            raise

        camera_config = config.add_camera(device_details)

        if utils.is_local_motion_camera(camera_config):
            motionctl.stop()

            if settings.SMB_SHARES:
                stop, start = smbctl.update_mounts()  # @UnusedVariable

                if start:
                    motionctl.start()

            else:
                motionctl.start()

            ui_config = config.motion_camera_dict_to_ui(camera_config)

            return self.finish_json(ui_config)

        elif utils.is_remote_camera(camera_config):
            resp = await remote.get_config(camera_config)
            if resp.error:
                return self.finish_json_with_error(resp.error)

            for key, value in list(camera_config.items()):
                resp.remote_ui_config[key.replace('@', '')] = value

            return self.finish_json(resp.remote_ui_config)

        else:  # assuming simple mjpeg camera
            ui_config = config.simple_mjpeg_camera_dict_to_ui(camera_config)

            return self.finish_json(ui_config)
コード例 #7
0
        def finish():
            if reboot[0]:
                if settings.ENABLE_REBOOT:

                    def call_reboot():
                        PowerControl.reboot()

                    io_loop = IOLoop.instance()
                    io_loop.add_timeout(datetime.timedelta(seconds=2),
                                        call_reboot)
                    return self.finish({
                        'reload': False,
                        'reboot': True,
                        'error': None
                    })

                else:
                    reboot[0] = False

            if restart[0]:
                logging.debug('motion needs to be restarted')

                motionctl.stop()

                if settings.SMB_SHARES:
                    logging.debug('updating SMB mounts')
                    stop, start = smbctl.update_mounts()  # @UnusedVariable

                    if start:
                        motionctl.start()

                else:
                    motionctl.start()

            self.finish({
                'reload': reload,
                'reboot': reboot[0],
                'error': error[0]
            })