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

0 Members and 1 Guest are viewing this topic.

Offline 92merc

  • BismarckWeather.net
  • Forecaster
  • *****
  • Posts: 1314
  • BismarckWeather.net
    • BismarckWeather.net
Re: Purpleair PHP Retrieval script
« Reply #100 on: May 19, 2022, 08:53:58 AM »
OK, more info:
https://community.purpleair.com/t/purpleair-data-migration-to-bigquery-and-a-new-api/295/3?fbclid=IwAR2YXj-WjhvW6s6lnovqjGKYvXtms1lZW1lnEvGhF6dMlK3Pdq_4WfD66Ng

"The current API used to access real-time data will not be affected. Instead, we will be adding a new endpoint for historical data. We want to keep backward compatibility as much as possible, and if significant changes need to be made, a new version will be released rather than updating the existing systems."
« Last Edit: May 19, 2022, 10:11:54 AM by 92merc »
https://www.BismarckWeather.net
Davis VP2, Cumulus, WeatherDisplay, Blitzortung, Saratoga Scripts, NOAA Stream via PI

Offline Forever

  • Senior Contributor
  • ****
  • Posts: 211
Re: Purpleair PHP Retrieval script
« Reply #101 on: May 27, 2022, 12:55:48 PM »
It looks like the script no longer works and will need to be redone to work with the API keys. I just requested my API keys.
« Last Edit: May 27, 2022, 02:44:00 PM by Forever »

Offline 92merc

  • BismarckWeather.net
  • Forecaster
  • *****
  • Posts: 1314
  • BismarckWeather.net
    • BismarckWeather.net
Re: Purpleair PHP Retrieval script
« Reply #102 on: May 27, 2022, 01:33:58 PM »
Wow, they didn't take long to kill the old script.  Sounded like they were going to leave it running longer than that.
https://www.BismarckWeather.net
Davis VP2, Cumulus, WeatherDisplay, Blitzortung, Saratoga Scripts, NOAA Stream via PI

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Purpleair PHP Retrieval script
« Reply #103 on: May 27, 2022, 02:28:21 PM »
Yep, requested my keys also...
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 mexbound

  • Senior Member
  • **
  • Posts: 66
Re: Purpleair PHP Retrieval script
« Reply #104 on: May 28, 2022, 08:25:24 AM »
I had to comment out my include:

// include_once('get-aqi-rss.php');        // get AQI index value for dashboard display

in ajaxdashboard6.php.

It was causing a huge time delay on my main page that made my site look like it was down. It wasn't. It was just waiting on Purpleair.

How (and or where) did you request API keys?

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Purpleair PHP Retrieval script
« Reply #105 on: May 28, 2022, 10:14:44 AM »
That script doesn't use Purpleair -- it uses feeds.enviroflash.info for data -- it's not related to the Purpleair API change.

Your webserver is likely having a connectivity issue with feeds.enviroflash.info, and that's the cause of the delays.
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 mexbound

  • Senior Member
  • **
  • Posts: 66
Re: Purpleair PHP Retrieval script
« Reply #106 on: May 28, 2022, 10:26:12 AM »
Here is my get-aqi-rss.php script. No references to feeds.enviroflash.info

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Purpleair PHP Retrieval script
« Reply #107 on: May 28, 2022, 10:49:35 AM »
That's not the get-aqi-rss.php distributed with the alternative dashboard .. I'd not seen your script before.

It would have to be changed like I showed in the purpleair-inc.txt file above (and an API key acquired) to work again .. the old feed is no longer valid.
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 mexbound

  • Senior Member
  • **
  • Posts: 66
Re: Purpleair PHP Retrieval script
« Reply #108 on: May 28, 2022, 10:55:30 AM »
Ya, not sure where I got that script from. I got a purpleair device about a year ago and added the info to my site. I just asked purpleair for my API keys. When I get them I will update my script from the one you posted. Probably rename it from get-aqi-rss.php to get back in sync ...

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Purpleair PHP Retrieval script
« Reply #109 on: May 28, 2022, 11:50:28 AM »
When you get your API key, plug this into the updated script below (also renamed to get-purpleair-aqi to not interfere with the one in the alternative dashboard).
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 mexbound

  • Senior Member
  • **
  • Posts: 66
Re: Purpleair PHP Retrieval script
« Reply #110 on: May 28, 2022, 12:03:44 PM »
Thanks Ken. Will do.

Offline zeppline

  • Senior Member
  • **
  • Posts: 66
    • Las Vegas Weather Guy
Re: Purpleair PHP Retrieval script
« Reply #111 on: May 31, 2022, 02:54:35 PM »
Ken I have the two programs purpleair-inc.php and wxpurpleair1.php I had to add a 1 because I have wxpurpleair already. When I run it I get error (No sensor ID entered in Script source!) but I added it where the nnnn is two places. ID is 19455. I am missing something do I need the get-purpleair-aqi.php.  Thanks Joe

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Purpleair PHP Retrieval script
« Reply #112 on: May 31, 2022, 03:53:11 PM »
Hi Joe,
You just need to put in the script the replacements for
Code: [Select]
$sensorid = "nnnn";
// Insert your api.purpleair.com READ api key below
$PurpleAirAPI = '-read-api-key-here-';
and that should work.  I'm assuming you have a api.purpleair.com READ API key from them to use.

if you get "No sensor ID entered in Script source!" then it's not seeing your $sensorid value.  Make sure you're using the updated script I posted above and that you've configured and uploaded it to your website.
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 meteohila

  • Member
  • *
  • Posts: 2
Re: Purpleair PHP Retrieval script
« Reply #113 on: June 02, 2022, 09:40:50 AM »
Hello,
I am writing to you from Spain, sorry for my bad English. I am contacting you about the purpleair script, I would like to add it to my website and these days I am watching this forum.
I have downloaded the file wxpurpleair.php and the new one to replace it get-purpleair-aqi.php from Saratoga weather, but I can't get it to work for me, I guess it must be easy, I don't know if I have a problem with hosting or permissions..
could you help me?
my website is: http://meteohila.esy.es/pronostico/wxpurpleair.php
but the script doesn't work for me...
I attach the files in case you see something wrong, the truth is that I have started to tweak to see if it could work but I have not been successful.
Thanks in advance and greetings

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Purpleair PHP Retrieval script
« Reply #114 on: June 02, 2022, 10:21:56 AM »
The wxpurpleair.php needs purpleair-inc.php for display.  The get-purpleair-aqi.php script wasn't the correct script.

For the page display, use the attached (after customization of purpleair-inc.php)
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 mexbound

  • Senior Member
  • **
  • Posts: 66
Re: Purpleair PHP Retrieval script
« Reply #115 on: June 02, 2022, 10:34:01 AM »
Thanks for the scripts Ken.  They work for me.  I wonder when we will hear from the WD developer about fixing the "flatlined" WD graph. I currently have taken it off my AQI web page until it gets fixed.  Thanks for all your support.

Offline meteohila

  • Member
  • *
  • Posts: 2
Re: Purpleair PHP Retrieval script
« Reply #116 on: June 02, 2022, 11:09:40 AM »
Ok, thank you for the answer Ken !!!
After having reloaded the new files and put the id of my purpleair and my api key it still doesn't work.
Now in the wxpurpleair.php file I get a black page
http://meteohila.esy.es/pronostico/wxpurpleair.php
  :???:

Offline mexbound

  • Senior Member
  • **
  • Posts: 66
Re: Purpleair PHP Retrieval script
« Reply #117 on: June 02, 2022, 11:19:21 AM »
Hi Ken, Using the scripts you just posted here is what I get back. (see attached image).

I have two questions:
1. What does "Page Load" mean under the real time sensor icons?
2. What variable would I change in purple-inc.php to increase the description font size?




Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Purpleair PHP Retrieval script
« Reply #118 on: June 02, 2022, 11:22:52 AM »
The problem may be caused by two things:
1) your PHP is  5.3.29 which is WAY out-of-date.  The templates need at least PHP 5.6+ (preferably PHP 7.4 or 8.1) to work correctly.
2) you have a lot of scripts to update with your installation ( http://meteohila.esy.es/pronostico/check-fetch-times.php?show=versions )

The wxpurpleair.php page seems to be stopping after the top.php is included, so there is likely a PHP fatal error (syntax error?) somewhere below the include_once("top.php"); statement.  I tried a view-source:http://meteohila.esy.es/pronostico/purpleair-inc.php and that seems to be the stopping point.. it's returning no data or HTML comments.  There may be a PHP syntax error in your specification of the sourceid or API key (missing closing quote or semicolon) causing a fatal PHP error.  Or.. the PHP 5.3 json_decode() function is blowing up .. PHP 5.6 fixed most of those json_decode() errors.

When you do update your PHP version past 5.6, you'll need to change header.php
Code: [Select]
$tuom = split('°',$temperature);  // extract units to
Code: [Select]
$tuom = explode('°',$temperature);  // extract units as the split() function is removed from PHP in PHP 7.4+
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 saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Purpleair PHP Retrieval script
« Reply #119 on: June 02, 2022, 11:31:04 AM »
Hi Ken, Using the scripts you just posted here is what I get back. (see attached image).

I have two questions:
1. What does "Page Load" mean under the real time sensor icons?
2. What variable would I change in purple-inc.php to increase the description font size?

"Page Load" is the current date/time from the server that the page was loaded.. as 'realtime' as can be.

The font sizes can be adjusted in the script by changing the built-in CSS  .. the description is displayed with
Code: [Select]
<td class="auto-style9" style="width: 85%"><strong>' . $Description . '</strong><br/> , but the auto-style9 is used in multiple places, so I'd change that line to have an inline style like
Code: [Select]
<td class="auto-style9" style="width: 85%;font-size:100%;"><strong>' . $Description . '</strong><br/>
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 ALITTLEweird1

  • Mark
  • Global Moderator
  • Forecaster
  • *****
  • Posts: 923
    • North Bend Weather
Re: Purpleair PHP Retrieval script
« Reply #120 on: June 10, 2022, 06:46:22 PM »
I can't find where you request an API key. Anyone have that link by chance? Thanks
"Nature can do without man, but man cannot do without nature."


Software: WeatherDisplay
Hardware: Davis VP2 + VP2 Solar + VP2 UV + Lightning Detector + Logitech Webcam + Soil temp + Soil Moisture

Offline Forever

  • Senior Contributor
  • ****
  • Posts: 211
Re: Purpleair PHP Retrieval script
« Reply #121 on: June 10, 2022, 07:18:53 PM »
Just ask them for one at contact@purpleair.com.

Offline txweather.org

  • Forecaster
  • *****
  • Posts: 1597
    • Texas Weather
Re: Purpleair PHP Retrieval script
« Reply #122 on: July 01, 2022, 11:29:12 PM »
As always, a million thanks @Ken. @Forever purpleair was quick to send me the key.

----
Davis Vantage Pro2 Plus +FARS|Meteobridge Nano SD|Meteohub|Meteobridge MR-3020|WU KTXSPRIN75/PWS JRARGWX75/CWOP EW2972/WBB TXWDVUE75/Blitzortung ID: 1142|AWEKAS: 12095
Donations are welcome: https://paypal.me/ffuentesb

Offline staccermaccer

  • Senior Member
  • **
  • Posts: 72
    • Weather in Ekeren and Port of Antwerp
Re: Purpleair PHP Retrieval script
« Reply #123 on: July 12, 2022, 01:45:15 PM »
Hi, all

Maybe a stupid question but is this script adaptable for "luftdaten" data, i know it is configurable in WD where it works and give readings but i can't display it on my dashboard or i must have missed something?

Would be great if someone could help me out here!

Thanks in advance for any help provided...

Staccermaccer AKA Marc,


Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Purpleair PHP Retrieval script
« Reply #124 on: July 12, 2022, 06:48:16 PM »
Hi Marc,
The script *may* be adaptable to Luftdaten if they also have a JSON query for values present in their firmware.  I don't have a Luftdaten sensor, so don't know.   If you have one, take a snapshot of the JSON query (in text) and post it -- I'll take a look.
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