0.60

ReferenceHardwareHTTPRead task

HTTP read task

Poll a web API and record values from its JSON responses in channels.

An HTTP read task sends requests to a web API at a fixed rate and records values from each JSON response in channels. For example, it can record the temperature and humidity from a weather station once a second.

Before you start, you need a connected HTTP server.

Endpoints and fields

An endpoint is one request: a method, a path, and optional query parameters, headers, and body. A field is one value in the JSON response, found by a JSON pointer, such as /temperature. Each field records into one channel.

  • Numbers -> recorded as they are.
  • Booleans -> recorded as 1 and 0.
  • Strings -> converted with the Enum mapping, else read as a number. A string channel records the text.

Each endpoint has its own timestamps. Set the Source of an endpoint to one of these:

  • Poll time -> the Driver uses the time halfway through the request.
  • Response value -> the Driver reads the time from the response, at a Pointer, in a Format: ISO 8601, or Unix time in seconds, milliseconds, microseconds, or nanoseconds.

Create an HTTP read task

Enterprise
  1. In the devices toolbar, right-click the server and select Create read task.
  2. Set Rate, the number of requests per second to each endpoint.
  3. Click Add endpoint, then set Method and Path, such as /api/data.
  4. Click Add field on the endpoint, then set Pointer and Data type.
  5. Click (Start).

The Console creates a channel for each field and an index channel for each endpoint. For a server named “Weather station”, the path /api/data and the pointer /temperature give Weather_station_api_data_temperature, with the index Weather_station_api_data_time. To choose a name, set Channel before you start.

Task options

Console label Python field Default Notes
Rate rate 1 Hz Requests per second to each endpoint. One sample for each field.
Data saving data_saving_disabled On See data saving.
Auto start auto_start Off Starts the task each time the Driver starts.

Turn on NaN fill (nan_fill_enabled=True in Python, nanFillEnabled: true in TypeScript) to write NaN when a float field is missing or cannot be converted. It is off by default. With it off, an invalid field skips every field that shares its endpoint and index channel. Invalid non-float fields still skip that group.

The HTTP read task has no stream rate. Each response is sent to the Core at once. See read tasks.

Endpoint and field reference

Each table shows the Console label of a setting, with its Python field under it. An endpoint has these settings:

Setting Default Notes
Method method GET GET or POST in the Console. Code accepts any method.
Path path Added to the base address of the server.
Query parameters query_params None A list of {parameter, value}.
Headers headers None A list of {name, value}.
Body body Empty Sent only with methods that take a body, as application/json.

A field has these settings:

Setting Default Notes
Pointer pointer The JSON pointer to the value.
Data type data_type float64 Used only when the Console creates the channel.
Channel channel The channel that records the value.
Enum mapping enum_values None Maps text labels in the response to numbers.

Troubleshooting

For other problems, see Troubleshoot hardware.