The PurpleAirAPI package provides tools for accessing air quality data from PurpleAir sensors. This vignette demonstrates how to:
First, let’s get information about available sensors:
# Get sensor locations
sensors <- getPurpleairSensors(
  apiReadKey = api_key,
  fields = c("latitude", "longitude", "date_created", "last_seen", "location_type")
)##   sensor_index latitude longitude date_created  last_seen location_type
## 1         1234  37.7749 -122.4194   2020-01-01 2024-01-01             0
## 2         5678  34.0522 -118.2437   2020-02-01 2024-01-01             1Once you have identified sensors of interest, you can download their historical data:
# Download one week of hourly data
history <- getSensorHistory(
  sensorIndex = c(1234, 5678),  # Example sensor IDs
  apiReadKey = api_key,
  startDate = "2024-01-01",
  endDate = "2024-01-07",
  average = 60,  # hourly averages
  fields = c("pm2.5_alt", "temperature", "humidity")
)##            time_stamp humidity temperature pm2.5_alt sensor_index
## 1 2024-01-01 00:00:00     68.2        50.4       3.4         1234
## 2 2024-01-01 01:00:00     69.0        48.6       2.0         1234