HTTP Camera Agent

The HTTP Camera Agent is an OCS Agent which grabs screenshots from cameras using HTTP requests and saves files to a directory.

usage: python3 agent.py [-h] [--config-file CONFIG_FILE] [--mode {acq,test}]
                        [--renew-token RENEW_TOKEN]

Agent Options

--config-file

Config file path relative to OCS_CONFIG_DIR

--mode

Possible choices: acq, test

--renew-token

Renew API token after this amount of seconds. Used for Reolink cameras.

Default: 2700

Configuration File Examples

Below are configuration examples for the ocs config file and for running the Agent in a docker container.

OCS Site Config

To configure the HTTP Camera Agent we need to add an HTTPCameraAgent block to our ocs configuration file. Here is an example configuration block using all of the available arguments:

{'agent-class': 'HTTPCameraAgent',
 'instance-id': 'cameras',
 'arguments': [['--mode', 'acq'],
               ['--config-file', 'cameras.yaml'],
               ['--renew-token', 2700]]},

Note

The --config-file argument should be the config file path relative to OCS_CONFIG_DIR and contain an entry for each camera with relevant information. An example is given below which is also found at config.

Docker Compose

The HTTP Camera Agent should be configured to run in a Docker container. An example docker-compose service configuration is shown here:

ocs-cameras:
  image: simonsobs/socs:latest
  hostname: ocs-docker
  environment:
    - INSTANCE_ID=cameras
    - SITE_HUB=ws://127.0.0.1:8001/ws
    - SITE_HTTP=http://127.0.0.1:8001/call
    - LOGLEVEL=info
  volumes:
    - ${OCS_CONFIG_DIR}:/config:ro
    - /mnt/nfs/data/cameras:/screenshots
  user: 9000:9000

The LOGLEVEL environment variable can be used to set the log level for debugging. The default level is “info”. The volume must mount to /screenshots. The user must have permissions to write to the mounted local directory.

Camera Config

cameras:
  # ACTi cameras must include `resolution` which contains resolution and
  # quality. Ex: N640x480,100 where the image is 640x480 size and the quality is 100%
  # Note: Certain models (A815) do not accept the quality. In this case simply
  # include the image size such as 'N1280x960' for `resolution`
  - address: '192.168.xx.xx'
    location: 'highbay_cargo'
    resolution: 'N640x480,100'
    user: 'user'
    password: 'password'
    brand: 'acti'

  # Reolink cameras should NOT include `resolution`
  - address: '192.168.xx.xx'
    location: 'satp1'
    user: 'user'
    password: 'password'
    brand: 'reolink'

Description

The HTTP cameras will be used to monitor conditions at the SO site. The HTTP Camera Agent periodically (1 minute) grabs screenshots from each HTTP camera on the network. The images are saved to a location on disk. A webserver should then be configured to serve this directory to some URL. Then we can use HTML to access the webserver and display latest.jpg for an up-to-date view of the camera. For example, this can be done directly in Grafana using the Text panel in HTML mode.

Agent API

class socs.agents.http_camera.agent.HTTPCameraAgent(agent, config_file, renew_token=2700)[source]

Grab screenshots from HTTP cameras.

Parameters:
  • agent (OCSAgent) – OCSAgent object which forms this Agent

  • config_file (str) – Config file path relative to OCS_CONFIG_DIR

agent

OCSAgent object which forms this Agent

Type:

OCSAgent

is_streaming

Tracks whether or not the agent is actively issuing requests to grab screenshots from cameras. Setting to false stops sending commands.

Type:

bool

log

txaio logger object, created by the OCSAgent

Type:

txaio.tx.Logger

acq(test_mode=False)[source]

Process - Grab screenshots from HTTP cameras.

Parameters:

test_mode (bool, optional) – Run the Process loop only once. Meant only for testing. Default is False.

Notes

The most recent data collected is stored in session.data in the structure:

>>> response.session['data']
# for each camera
{'location1': {'location': 'location1',
             'last_attempt': 1701983575.032506,
             'connected': True,
             'address': '10.10.10.41'},
 'location2': ...
}