Author Topic: Purpleair PHP Retrieval script  (Read 27023 times)

0 Members and 1 Guest are viewing this topic.

Offline staccermaccer

  • Senior Member
  • **
  • Posts: 72
    • Weather in Ekeren and Port of Antwerp
Re: Purpleair PHP Retrieval script
« Reply #125 on: July 13, 2022, 01:09:08 AM »
Hi Ken,

Yes it works also with a JSON-file, i will include a screenshot!

Marc,

PS: THX for giving it a stab!
« Last Edit: July 13, 2022, 05:19:32 AM by staccermaccer »

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9176
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Purpleair PHP Retrieval script
« Reply #126 on: July 13, 2022, 10:46:32 AM »
I'm not sure that JSON has enough details to use.. I see SDS_P1 and SDS_P2 values (along with temperature, humidity), but I don't know if either SDS_P1 or SDS_P2 is a PM2.5 value that the script needs.

Looking more into it .. the SDS_P1 is the PM10 reading and SDS_P2 is the PM2.5 reading.  The firmware JSON return only returns the instantaneous value at the time of the local query -- no trending/historical data such as returned by the PurpleAir JSON query, so I think the PurpleAir script is not directly adaptable to the Luftdaten due to lack of extra data needed by the script.  Sorry...
« Last Edit: July 13, 2022, 11:07:40 AM by saratogaWX »
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline Scobey

  • Member
  • *
  • Posts: 26
    • Scobey's Weather
Re: Purpleair PHP Retrieval script
« Reply #127 on: August 26, 2023, 10:47:29 AM »
I guess I'm a bonehead. Can't find this script here.

Offline 92merc

  • BismarckWeather.net
  • Forecaster
  • *****
  • Posts: 1300
  • BismarckWeather.net
    • BismarckWeather.net
Re: Purpleair PHP Retrieval script
« Reply #128 on: August 26, 2023, 11:59:29 AM »
I think this is what you're looking for.  Just a page back...

https://www.wxforum.net/index.php?topic=33482.msg447542#msg447542
https://www.BismarckWeather.net
Davis VP2, Cumulus, WeatherDisplay, Blitzortung, Saratoga Scripts, NOAA Stream via PI

Offline Vasco

  • Forecaster
  • *****
  • Posts: 301
    • PWS
Re: Purpleair PHP Retrieval script
« Reply #129 on: August 27, 2023, 01:15:22 PM »
I've just started to use these scripts, but I'm puzzled by the fact that purpleair-inc.php seems to have two identical file_get_contents() calls to the API on lines 41 and 62:

Code: [Select]
$pajson = file_get_contents("https://api.purpleair.com/v1/sensors/$sensorid?api_key=$PurpleAirAPI",0,$STRcontext);
and a $fname location (line 61) when there is no caching that I can see.

Now that newcomers have to pay for PurpleAir API calls a cache might be useful: see here (you don't have to run the cron every 5 minutes)  :-)

But I would probably cache at

Code: [Select]
$fname = './cache/purpleair-'.$sensorid.'.json';
for a standard Saratoga setup.
« Last Edit: August 27, 2023, 01:36:00 PM by Vasco »
Oregon Scientific WMR200 + Weather Display in Windows 10

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9176
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Purpleair PHP Retrieval script
« Reply #130 on: August 27, 2023, 04:06:23 PM »
Yes, silly me.. delete the one at line 62.  Only one pull on the API was needed.
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

 

anything