I currently pull the real-time, PM1, PM2.5 and PM10 data directly from my PurpleAir.
The problem is the short-term, 30 minute, 1 hour, 6 hours and other reading are not on the PurpleAir device. The values are calculated on the PurpleAir servers and then made available. The only way to get this kind of data would be to store it in sql and calculate the vales.
Like azchrisf said this is not an easy task.
I can provide a small script to pull just the current value from the local PurpleAir so that people can play around with it.
<?php
//Get the sensor data via JSON
$pajsona = @file_get_contents('http://192.168.1.103/json');
$json_resulta=json_decode($pajsona, true);
//Create our variables for different Sensor results
$pm25a = $json_resulta['pm2_5_cf_1'];
$pm25b = $json_resulta['pm2_5_cf_1_b'];
$aqia = aqiFromPM($pm25a);
$aqib = aqiFromPM($pm25b);
$AQI = round(($aqia + $aqib)/2);
//Function to get AQI number from PPM reading
function aqiFromPM ($pm) {
if (is_nan($pm)) {
return "-";
}
if (isset($pm) == false) {
return "Error: No value";
}
if ($pm < 0.0) {
return $pm;
}
if ($pm > 1000.0) {
return "-";
}
if ($pm > 350.5) {
return calcAQI($pm, 500.0, 401.0, 500.0, 350.5);
} else if ($pm > 250.5) {
return calcAQI($pm, 400.0, 301.0, 350.4, 250.5);
} else if ($pm > 150.5) {
return calcAQI($pm, 300.0, 201.0, 250.4, 150.5);
} else if ($pm > 55.5) {
return calcAQI($pm, 200.0, 151.0, 150.4, 55.5);
} else if ($pm > 35.5) {
return calcAQI($pm, 150.0, 101.0, 55.4, 35.5);
} else if ($pm > 12.1) {
return calcAQI($pm, 100.0, 51.0, 35.4, 12.1);
} else if ($pm >= 0.0) {
return calcAQI($pm, 50.0, 0.0, 12.0, 0.0);
} else {
return "-";
}
}
//Function that actually calculates the AQI number
function calcAQI($Cp, $Ih, $Il, $BPh, $BPl) {
$a = ($Ih - $Il);
$b = ($BPh - $BPl);
$c = ($Cp - $BPl);
return round(($a/$b) * $c + $Il);
}
//Function that gets the AQI's description
function getAQIDescription($aqinum) {
if ($aqinum >= 401) {
return 'Hazardous';
} else if ($aqinum >= 301) {
return 'Hazardous';
} else if ($aqinum >= 201) {
return 'Very Unhealthy';
} else if ($aqinum >= 151) {
return 'Unhealthy';
} else if ($aqinum >= 101) {
return 'Unhealthy for Sensitive Groups';
} else if ($aqinum >= 51) {
return 'Moderate';
} else if ($aqinum >= 0) {
return 'Good';
} else {
return 'Unknown';
}
}
?>
Thinking about this a little more this may not work for others, my server is on my local network so it has access to my PurpleAir.