Files
arduino/docs/local-server.md

259 lines
17 KiB
Markdown
Raw Permalink Normal View History

2024-04-19 14:09:48 +07:00
## Local Server API
From [firmware version 3.0.10](firmwares) onwards, the AirGradient ONE and Open Air monitors have below API available.
### Discovery
2024-04-19 14:09:48 +07:00
The monitors run a mDNS discovery. So within the same network, the monitor can be accessed through:
http://airgradient_{{serialnumber}}.local
The following requests are possible:
### Get Current Air Quality (GET)
2024-04-19 14:09:48 +07:00
With the path "/measures/current" you can get the current air quality data.
http://airgradient_ecda3b1eaaaf.local/measures/current
2024-06-04 09:17:33 +02:00
“ecda3b1eaaaf” being the serial number of your monitor.
2024-04-19 14:09:48 +07:00
You get the following response:
2024-06-04 09:20:18 +02:00
```json
{
"wifi": -46,
"serialno": "ecda3b1eaaaf",
"rco2": 447,
"pm01": 3,
"pm02": 7,
"pm10": 8,
"pm003Count": 442,
"atmp": 25.87,
2024-06-17 08:46:56 +07:00
"atmpCompensated": 24.47,
2024-06-04 09:20:18 +02:00
"rhum": 43,
2024-06-17 08:46:56 +07:00
"rhumCompensated": 49,
2024-06-04 09:20:18 +02:00
"tvocIndex": 100,
2024-06-17 08:46:56 +07:00
"tvocRaw": 33051,
2024-06-04 09:20:18 +02:00
"noxIndex": 1,
2024-06-17 08:46:56 +07:00
"noxRaw": 16307,
2024-06-04 09:20:18 +02:00
"boot": 6,
2024-06-17 08:46:56 +07:00
"bootCount": 6,
2024-06-04 09:20:18 +02:00
"ledMode": "pm",
2024-06-17 08:46:56 +07:00
"firmware": "3.1.3",
2024-09-21 13:06:01 +07:00
"model": "I-9PSL",
"monitorDisplayCompensatedValues": true
2024-06-04 09:20:18 +02:00
}
```
2024-04-19 14:09:48 +07:00
2024-09-21 13:06:01 +07:00
| Properties | Type | Explanation |
|-----------------------------------|---------|----------------------------------------------------------------------------------------|
| `serialno` | String | Serial Number of the monitor |
| `wifi` | Number | WiFi signal strength |
2024-10-22 18:37:56 +07:00
| `pm01` | Number | PM1.0 in ug/m3 (atmospheric environment) |
| `pm02` | Number | PM2.5 in ug/m3 (atmospheric environment) |
| `pm10` | Number | PM10 in ug/m3 (atmospheric environment) |
2024-09-21 13:06:01 +07:00
| `pm02Compensated` | Number | PM2.5 in ug/m3 with correction applied (from fw version 3.1.4 onwards) |
| `pm01Standard` | Number | PM1.0 in ug/m3 (standard particle) |
| `pm02Standard` | Number | PM2.5 in ug/m3 (standard particle) |
| `pm10Standard` | Number | PM10 in ug/m3 (standard particle) |
2024-09-21 13:06:01 +07:00
| `rco2` | Number | CO2 in ppm |
2024-10-22 18:37:56 +07:00
| `pm003Count` | Number | Particle count 0.3um per dL |
2024-10-31 21:12:29 +07:00
| `pm005Count` | Number | Particle count 0.5um per dL |
2024-10-22 18:37:56 +07:00
| `pm01Count` | Number | Particle count 1.0um per dL |
| `pm02Count` | Number | Particle count 2.5um per dL |
| `pm50Count` | Number | Particle count 5.0um per dL (only for indoor monitor) |
2024-10-31 21:19:46 +07:00
| `pm10Count` | Number | Particle count 10um per dL (only for indoor monitor) |
2024-09-21 13:06:01 +07:00
| `atmp` | Number | Temperature in Degrees Celsius |
| `atmpCompensated` | Number | Temperature in Degrees Celsius with correction applied |
| `rhum` | Number | Relative Humidity |
| `rhumCompensated` | Number | Relative Humidity with correction applied |
| `tvocIndex` | Number | Senisiron VOC Index |
| `tvocRaw` | Number | VOC raw value |
| `noxIndex` | Number | Senisirion NOx Index |
| `noxRaw` | Number | NOx raw value |
| `boot` | Number | Counts every measurement cycle. Low boot counts indicate restarts. |
| `bootCount` | Number | Same as boot property. Required for Home Assistant compatability. (deprecated soon!) |
2024-09-21 13:06:01 +07:00
| `ledMode` | String | Current configuration of the LED mode |
| `firmware` | String | Current firmware version |
| `model` | String | Current model name |
2024-06-17 08:46:56 +07:00
Compensated values apply correction algorithms to make the sensor values more accurate. Temperature and relative humidity correction is only applied on the outdoor monitor Open Air but the properties _compensated will still be send also for the indoor monitor AirGradient ONE.
2024-04-19 14:09:48 +07:00
### Get Configuration Parameters (GET)
2024-11-03 14:06:32 +07:00
"/config" path returns the current configuration of the monitor.
2024-06-04 09:20:18 +02:00
```json
{
2024-09-24 09:46:18 +07:00
"country": "TH",
2024-06-04 09:20:18 +02:00
"pmStandard": "ugm3",
"ledBarMode": "pm",
2024-09-24 09:46:18 +07:00
"abcDays": 7,
2024-06-04 09:20:18 +02:00
"tvocLearningOffset": 12,
"noxLearningOffset": 12,
"mqttBrokerUrl": "",
2025-04-02 16:30:13 +07:00
"httpDomain": "",
2024-09-24 09:46:18 +07:00
"temperatureUnit": "c",
"configurationControl": "local",
"postDataToAirGradient": true,
"ledBarBrightness": 100,
"displayBrightness": 100,
"offlineMode": false,
"model": "I-9PSL",
"monitorDisplayCompensatedValues": true,
"corrections": {
"pm02": {
"correctionAlgorithm": "epa_2021",
"slr": {}
}
}
}
2024-06-04 09:20:18 +02:00
}
```
2024-04-19 14:09:48 +07:00
### Set Configuration Parameters (PUT)
2024-04-19 14:09:48 +07:00
Configuration parameters can be changed with a PUT request to the monitor, e.g.
2024-04-19 14:09:48 +07:00
Example to force CO2 calibration
```bash
curl -X PUT -H "Content-Type: application/json" -d '{"co2CalibrationRequested":true}' http://airgradient_84fce612eff4.local/config
```
2024-04-19 14:09:48 +07:00
2024-06-04 09:17:33 +02:00
Example to set monitor to Celsius
2024-04-19 14:09:48 +07:00
```bash
curl -X PUT -H "Content-Type: application/json" -d '{"temperatureUnit":"c"}' http://airgradient_84fce612eff4.local/config
```
2024-04-19 14:09:48 +07:00
2024-08-07 11:05:39 +07:00
If you use command prompt on Windows, you need to escape the quotes:
2024-08-07 11:08:48 +07:00
``` -d "{\"param\":\"value\"}" ```
2024-08-07 11:05:39 +07:00
### Avoiding Conflicts with Configuration on AirGradient Server
2024-11-03 14:06:32 +07:00
If the monitor is set up on the AirGradient dashboard, it will also receive the configuration parameters from there. In case you do not want this, please set `configurationControl` to `local`. In case you set it to `cloud` and want to change it to `local`, you need to make a factory reset.
2024-04-19 14:09:48 +07:00
### Configuration Parameters (GET/PUT)
2024-04-19 14:09:48 +07:00
2024-09-21 13:06:01 +07:00
| Properties | Description | Type | Accepted Values | Example |
|-----------------------------------|:-----------------------------------------------------------------|---------|-----------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------|
| `country` | Country where the device is. | String | Country code as [ALPHA-2 notation](https://www.iban.com/country-codes) | `{"country": "TH"}` |
| `model` | Hardware identifier (only GET). | String | I-9PSL-DE | `{"model": "I-9PSL-DE"}` |
| `pmStandard` | Particle matter standard used on the display. | String | `ugm3`: ug/m3 <br> `us-aqi`: USAQI | `{"pmStandard": "ugm3"}` |
| `ledBarMode` | Mode in which the led bar can be set. | String | `co2`: LED bar displays CO2 <br>`pm`: LED bar displays PM <br>`off`: Turn off LED bar | `{"ledBarMode": "off"}` |
| `displayBrightness` | Brightness of the Display. | Number | 0-100 | `{"displayBrightness": 50}` |
| `ledBarBrightness` | Brightness of the LEDBar. | Number | 0-100 | `{"ledBarBrightness": 40}` |
| `abcDays` | Number of days for CO2 automatic baseline calibration. | Number | Maximum 200 days. Default 8 days. | `{"abcDays": 8}` |
2025-04-02 16:26:07 +07:00
| `mqttBrokerUrl` | MQTT broker URL. | String | Maximum 255 characters. Set value to empty string to disable mqtt connection. | `{"mqttBrokerUrl": "mqtt://192.168.0.18:1883"}` |
| `httpDomain` | Domain name for http request. (version > 3.3.2) | String | Maximum 255 characters. Set value to empty string to set http domain to default airgradient | `{"httpDomain": "sub.domain.com"}` |
2024-09-21 13:06:01 +07:00
| `temperatureUnit` | Temperature unit shown on the display. | String | `c` or `C`: Degree Celsius °C <br>`f` or `F`: Degree Fahrenheit °F | `{"temperatureUnit": "c"}` |
| `configurationControl` | The configuration source of the device. | String | `both`: Accept local and cloud configuration <br>`local`: Accept only local configuration <br>`cloud`: Accept only cloud configuration | `{"configurationControl": "both"}` |
| `postDataToAirGradient` | Send data to AirGradient cloud. | Boolean | `true`: Enabled <br>`false`: Disabled | `{"postDataToAirGradient": true}` |
| `co2CalibrationRequested` | Can be set to trigger a calibration. | Boolean | `true`: CO2 calibration (400ppm) will be triggered | `{"co2CalibrationRequested": true}` |
| `ledBarTestRequested` | Can be set to trigger a test. | Boolean | `true` : LEDs will run test sequence | `{"ledBarTestRequested": true}` |
| `noxLearningOffset` | Set NOx learning gain offset. | Number | 0-720 (default 12) | `{"noxLearningOffset": 12}` |
| `tvocLearningOffset` | Set VOC learning gain offset. | Number | 0-720 (default 12) | `{"tvocLearningOffset": 12}` |
2025-04-02 16:26:07 +07:00
| `monitorDisplayCompensatedValues` | Set the display show the PM value with/without compensate value (only on 3.1.9) | Boolean | `false`: Without compensate (default) <br> `true`: with compensate | `{"monitorDisplayCompensatedValues": false }` |
| `corrections` | Sets correction options to display and measurement values on local server response. (version >= 3.1.11) | Object | _see corrections section_ | _see corrections section_ |
**Notes**
2025-02-05 10:43:56 +07:00
- `offlineMode` : the device will disable all network operation, and only show measurements on the display and ledbar; Read-Only; Change can be apply using reset button on boot.
2025-01-26 13:02:42 +07:00
- `disableCloudConnection` : disable every request to AirGradient server, means features like post data to AirGradient server, configuration from AirGradient server and automatic firmware updates are disabled. This configuration overrides `configurationControl` and `postDataToAirGradient`; Read-Only; Change can be apply from wifi setup webpage.
### Corrections
The `corrections` object allows configuring PM2.5, Temperature and Humidity correction algorithms and parameters locally. This affects both the display, local server response and open metrics values.
Example correction configuration:
```json
{
"corrections": {
"pm02": {
"correctionAlgorithm": "<Option In String>",
"slr": {
"intercept": 0,
"scalingFactor": 0,
"useEpa2021": false
}
},
"atmp": {
"correctionAlgorithm": "<Option In String>",
"slr": {
"intercept": 0,
"scalingFactor": 0
}
},
"rhum": {
"correctionAlgorithm": "<Option In String>",
"slr": {
"intercept": 0,
"scalingFactor": 0
}
},
}
}
```
#### PM 2.5
Field Name: `pm02`
| Algorithm | Value | Description | SLR required |
|------------|-------------|------|---------|
| Raw | `"none"` | No correction (default) | No |
| EPA 2021 | `"epa_2021"` | Use EPA 2021 correction factors on top of raw value | No |
| PMS5003_20240104 | `"slr_PMS5003_20240104"` | Correction for PMS5003 sensor batch 20240104| Yes |
| PMS5003_20231218 | `"slr_PMS5003_20231218"` | Correction for PMS5003 sensor batch 20231218| Yes |
| PMS5003_20231030 | `"slr_PMS5003_20231030"` | Correction for PMS5003 sensor batch 20231030| Yes |
**NOTES**:
- Set `useEpa2021` to `true` if want to apply EPA 2021 correction factors on top of SLR correction value, otherwise `false`
- `intercept` and `scalingFactor` values can be obtained from [this article](https://www.airgradient.com/blog/low-readings-from-pms5003/)
- If `configurationControl` is set to `local` (eg. when using Home Assistant), correction need to be set manually, see examples below
**Examples**:
- PMS5003_20231030
```bash
curl --location -X PUT 'http://airgradient_84fce612eff4.local/config' --header 'Content-Type: application/json' --data '{"corrections":{"pm02":{"correctionAlgorithm":"slr_PMS5003_20231030","slr":{"intercept":0,"scalingFactor":0.02838,"useEpa2021":true}}}}'
```
- PMS5003_20231218
```bash
curl --location -X PUT 'http://airgradient_84fce612eff4.local/config' --header 'Content-Type: application/json' --data '{"corrections":{"pm02":{"correctionAlgorithm":"slr_PMS5003_20231218","slr":{"intercept":0,"scalingFactor":0.03525,"useEpa2021":true}}}}'
```
- PMS5003_20240104
```bash
curl --location -X PUT 'http://airgradient_84fce612eff4.local/config' --header 'Content-Type: application/json' --data '{"corrections":{"pm02":{"correctionAlgorithm":"slr_PMS5003_20240104","slr":{"intercept":0,"scalingFactor":0.02896,"useEpa2021":true}}}}'
```
#### Temperature & Humidity
Field Name:
- Temperature: `atmp`
- Humidity: `rhum`
| Algorithm | Value | Description | SLR required |
|------------|-------------|------|---------|
| Raw | `"none"` | No correction (default) | No |
| AirGradient Standard Correction | `"ag_pms5003t_2024"` | Using standard airgradient correction (for outdoor monitor)| No |
| Custom | `"custom"` | custom corrections constant, set `intercept` and `scalingFactor` manually | Yes |
*Table above apply for both Temperature and Humidity*
**Example**
```bash
curl --location -X PUT 'http://airgradient_84fce612eff4.local/config' --header 'Content-Type: application/json' --data '{"corrections":{"atmp":{"correctionAlgorithm":"custom","slr":{"intercept":0.2,"scalingFactor":1.1}}}}'
```