Skip to content
Sam Carlberg edited this page Nov 9, 2016 · 3 revisions

The HTTP API

GRIP is able to be controlled remotely through a simple HTTP API that allows remote applications to:

  • Upload a pipeline for GRIP to run (headless mode only)
  • Supply image sources for a loaded pipeline
  • Retrieve published data

The server defaults to use the TCP port 8080. This can be changed in the settings dialog or with the -p or --port command line options


How to use

Connecting

If GRIP is run a RoboRIO, the HTTP API will be available at roborio-TEAM-frc.local:PORT/GRIP/, where TEAM is your FRC team number and PORT is the port set in the settings dialog, or 8080 if not set. (If your team uses static IP addresses instead of mDNS, it will normally be at 10.TE.AM.2:PORT/GRIP/)

If connecting from the machine that GRIP is running on, the host is simply localhost or 127.0.0.1.

Uploading pipelines

Note: This only works when GRIP is running in headless mode.

Send a POST request to /GRIP/upload/pipeline with the contents of the save file to load. This will trigger the pipeline to run.

HTTP request format:

| Name| Type or Content| |---|---|---|---| | Request | POST | | Data type | text/plain | | Data | Text content of the GRIP save file | | Path | /GRIP/upload/pipeline |

Supplying images

When adding an HTTP Source to a pipeline, the user is prompted with a dialog asking for the path that the image will be uploaded to. This path must start with /GRIP/upload/image/, but may define further collections e.g. /GRIP/upload/image/stereo to logically group inputs.

HTTP Sources act like any other image source in GRIP and will trigger the pipeline to run when a new image is uploaded . Uploading the same image repeatedly will not trigger a run.

HTTP request format:

| Name| Type or Content | |---|---|---|---| | Request | POST | | Data type | binary | | Data | Raw binary data of an image | | Path | /GRIP/upload/image/[source-name] |

Example paths:

  • /GRIP/upload/image/gompei
  • /GRIP/upload/image/myImage
  • /GRIP/upload/image/stereo/left
  • /GRIP/upload/image/stereo/right

Retrieving data

Data is published in JSON format to /GRIP/data. A request to the base URL /GRIP/data will have a response for all data published with an HTTP Publish X operation. For example, if a ContoursReport is published with the name myContoursReport and a LinesReport is published with the name myLinesReport, the response will look something like

{
  "myContoursReport": {
    // Data omitted for brevity
  },
  "myLinesReport": {
    // Data omitted for brevity
  }
}

If you only want specific data (such as myContoursReport), use the URL format

/GRIP/data?[data-name-1]&[data-name-2]& ... &[data-name-n],

which for this example would resolve to /GRIP/data?myContoursReport

HTTP request format:

| Name| Type or Content| |---|---|---|---| | Request | GET | | Data type | None | | Data | None | | Path | /GRIP/data |

Example paths:

  • /GRIP/data
  • /GRIP/data?myContoursReport
  • /GRIP/data?myContoursReport&myLinesReport
  • /GRIP/data?foo&bar&baz

NOTE: Getting data via the HTTP API will block until the pipeline finishes running. This may take a while if the pipeline is long, uses large images, or uses computationally intensive operations