pa_getSensorHistoryCSV: Retrieve historical data for a single sensor as CSV.

View source: R/pa_API.R

pa_getSensorHistoryCSVR Documentation

Retrieve historical data for a single sensor as CSV.

Description

Sends a request to the PurpleAir API endpoint described at: https://api.purpleair.com/#api-sensors-get-sensor-history-csv

Usage

pa_getSensorHistoryCSV(
  api_key = NULL,
  sensor_index = NULL,
  start_timestamp = NULL,
  end_timestamp = NULL,
  average = 10,
  fields = SENSOR_HISTORY_PM25_FIELDS,
  baseUrl = "https://api.purpleair.com/v1/sensors"
)

Arguments

api_key

PurpleAir API READ key.

sensor_index

The sensor_index as found in the JSON for this specific sensor.

start_timestamp

Optional Unix timestamp in seconds since Jan 1, 1970.

end_timestamp

Optional Unix timestamp in seconds since Jan 1, 1970.

average

Temporal averaging in minutes performed by PurpleAir. One of: 0 (raw), 10, 30, 60 (hour), 360, 1440 (day).

fields

Character string specifying which 'sensor data fields' to include in the response.

baseUrl

URL endpoint for the "Get Sensor History (CSV)" API.

Value

Tibble with historical data for a single sensor.

Examples


# Fail gracefully if any resources are not available
try({

library(AirSensor)

start <-
  MazamaCoreUtils::parseDatetime("2023-01-29 00:00:00", timezone = "UTC") %>%
  as.numeric()

end <-
  MazamaCoreUtils::parseDatetime("2023-01-30 00:00:00", timezone = "UTC") %>%
  as.numeric()

pa_getSensorHistoryCSV(
  api_key = PURPLE_AIR_API_READ_KEY,
  sensor_index = 896,
  start_timestamp = start,
  end_timestamp = end,
  average = 0,
  fields = SENSOR_HISTORY_PM25_FIELDS
)

}, silent = FALSE)


MazamaScience/AirSensor documentation built on April 28, 2023, 11:16 a.m.