Download the PHP package azuyalabs/waqi without Composer
On this page you can find all versions of the php package azuyalabs/waqi. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download azuyalabs/waqi
More information about azuyalabs/waqi
Files in azuyalabs/waqi
Package waqi
Short Description Simple PHP Wrapper for the World Air Quality Index API
License MIT
Homepage https://github.com/azuyalabs/waqi
Informations about the package waqi
A simple PHP Wrapper for the World Air Quality Index API
The World Air Quality Index project is an initiative to map the current and real-time air quality around the globe. The Air Quality indexes are based on PM2.5, PM10, Ozone, NO2, SO2 and CO hourly measurements provided by various monitoring stations in the world.
This packages makes it easy to retrieve the Air Quality Index for your area and is based on the real-time Air Quality data feed (API) of the WAQI project.
Note: To make use of this package (and the underlying AQI API) an access token is required. You can acquire your token here: https://aqicn.org/data-platform/token..
System Requirements
You need PHP >= 8.2 to use azuyalabs/waqi
.
Installation
You can pull in this package via composer:
Usage
Start with including the Composer autoload
file in your project:
Using your AQI access token, create an instance of the WAQI object:
Next, use the getObservationByStation
method with the desired city or monitoring station name (e.g.
'new york'). This will obtain the latest air quality observations:
Air Quality
If all goes well, use the various API methods to get details about the retrieved Air Quality Index of the chosen city or monitoring station.
To get the AQI (Air Quality Index), use the method getAQI
:
This returns an array structure containing the Air Quality Index measured at this monitoring station at the time of measurement. It contains 4 elements:
- 'aqi': the AQI level (which is defined by the monitoring stations' dominant pollution type)
- 'pollution_level': a narrative describing the air pollution level
- 'health_implications': a narrative describing the health implications associated with the measured pollution level
- 'cautionary_statement': a cautionary statement associated with the measured pollution level (only for PM2.5)
Example output (for 'New York'):
In addition to the general Air Quality Information, specific pollutant level information is available as well. Be aware that not every monitoring station captures all pollutant types, so some of these API functions may return 'null'.
The following API functions are available to get specific pollutant level information:
getCO()
: returns the carbon monoxide (CO) level measured at the monitoring station at the time of measurement.getNO2()
: returns the nitrogen dioxide (NO2) level measured at the monitoring station at the time of measurement.getO3()
: returns the ozone (O3) level measured at the monitoring station at the time of measurement.getSO2()
: returns the sulfur dioxide (SO2) level measured at the monitoring station at the time of measurement.getPM10()
: returns the level of particulate matter 10 micrometers or lower (PM10), measured at this monitoring station at the time of measurement.getPM25()
: returns the level of particulate matter 2.5 micrometers or lower (PM2.5), measured at this monitoring station at the time of measurement.
Monitoring Station
Information about the monitoring station can be obtained through two API methods.
First, using the API method getMonitoringStation()
, will return information about the given monitoring station:
- 'id': the unique ID for this monitoring station
- 'name': the name (or description) of this monitoring station
- 'coordinates': the geographical coordinates of this monitoring station (array of 'longitude' and 'latitude')
- 'url': the URL of this monitoring station
Secondly, the API method getAttributions()
will return a list of EPA attributions for this monitoring station.
Other
Other API methods that provide additional information, are:
getMeasurementTime()
: returns the date/time the last measurement was taken. (as aDateTime
object).getHumidity()
: returns the humidity (in %) measured at this monitoring station at the time of measurement.getTemperature()
: returns the temperature (in degrees Celsius) measured at this monitoring station at the time of measurement.getPressure()
: returns the barometric pressure (in millibars) measured at this monitoring station at the time of measurement.getPrimaryPollutant()
: returns the name of the primary pollutant at this monitoring station at the time of measurement (e.g. 'pm25').
Changelog
Please see CHANGELOG for more information what has changed.
Testing
This package comes with a PHPUnit test suite. To run the tests, run the following command from the project directory:
,or alternatively run with:
Contributing
Contributions are encouraged and welcome; I am always happy to get feedback or pull requests on GitHub :) Create GitHub Issues for bugs and new features and comment on the ones you are interested in.
If you enjoy what I am making, an extra cup of coffee is very much appreciated :). Your support helps me to put more time into Open-Source Software projects like this.
Credits
- Sacha Telgenhof
- All contributors
License
This package is open-sourced software licensed under the MIT License. Please see LICENSE for more information.