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

0 Members and 1 Guest are viewing this topic.

Offline Forever

  • Senior Contributor
  • ****
  • Posts: 209
Re: Purpleair PHP Retrieval script
« Reply #50 on: February 04, 2018, 12:33:57 AM »
I was not able to fix the bad data in channel b from Thingspeak.

I replaced the code to pull the PM1, PM2.5 and PM10 from the PurpleAir directly.

http://www.weathercat.net/wxaqi.php
« Last Edit: November 17, 2021, 06:11:48 PM by Forever »

Offline azchrisf

  • Cobra Weather Dominator Operator
  • Forecaster
  • *****
  • Posts: 455
Re: Purpleair PHP Retrieval script
« Reply #51 on: February 04, 2018, 12:43:15 AM »
I was not able to fix the bad data in channel b from Thingspeak.

I replaced the code to pull the PM1, PM2.5 and PM10 from the PurpleAir directly.

http://www.weathercat.net/wxpurpleair.php
Send me via PM the entire script, with your data filled out in it. Use the 1.4b I posted, please don't include any of your changes.

I will look and see whats going on.

Sent from my Pixel using Tapatalk

Davis Vantage Pro 2 Plus 6163 w/ 8 Transmitters!
Also doing Soil and Leaf 4x
WU: KAZGLEND106 CWOP: FW1398 (F1398) Purpleair: 98793/LAZGLEND8
My setup:
https://www.wxforum.net/index.php?topic=41867.0

Offline weatherbee

  • Senior Contributor
  • ****
  • Posts: 210
    • Sherman Ct. Weather
Re: Purpleair PHP Retrieval script
« Reply #52 on: February 04, 2018, 10:40:26 AM »
azchrisf,
I think what you've done on the PM10 looks good.
When I pull the info on PM10 channel B I am getting -1.
Tom

Offline Forever

  • Senior Contributor
  • ****
  • Posts: 209
Re: Purpleair PHP Retrieval script
« Reply #53 on: February 04, 2018, 11:21:29 AM »
azchrisf, I just sent you my file that will not pull PM10 channel b data and a file that simple pulls PM10 data to verify that the data is there.


Offline azchrisf

  • Cobra Weather Dominator Operator
  • Forecaster
  • *****
  • Posts: 455
Re: Purpleair PHP Retrieval script
« Reply #54 on: February 04, 2018, 11:26:06 AM »
OK I found the problem, 1.4c forthcoming.
Davis Vantage Pro 2 Plus 6163 w/ 8 Transmitters!
Also doing Soil and Leaf 4x
WU: KAZGLEND106 CWOP: FW1398 (F1398) Purpleair: 98793/LAZGLEND8
My setup:
https://www.wxforum.net/index.php?topic=41867.0

Offline azchrisf

  • Cobra Weather Dominator Operator
  • Forecaster
  • *****
  • Posts: 455
Re: Purpleair PHP Retrieval script
« Reply #55 on: February 04, 2018, 11:52:04 AM »
Okey dokey - posted 1.4c.

// Version 1.4c
// * Fixed bug with PM10 values
// * Added experinmental PM10 AQI function
// * Tuning of script
// * Other misc. changes
Davis Vantage Pro 2 Plus 6163 w/ 8 Transmitters!
Also doing Soil and Leaf 4x
WU: KAZGLEND106 CWOP: FW1398 (F1398) Purpleair: 98793/LAZGLEND8
My setup:
https://www.wxforum.net/index.php?topic=41867.0

Offline ConligWX

  • Forecaster
  • *****
  • Posts: 836
  • #conligwx
    • conligwx.org
Re: Purpleair PHP Retrieval script
« Reply #56 on: February 05, 2018, 05:58:52 PM »
Okey dokey - posted 1.4c.

// Version 1.4c
// * Fixed bug with PM10 values
// * Added experinmental PM10 AQI function
// * Tuning of script
// * Other misc. changes

is the same type of aqi values available locally?  http://ip.of.purple.air/json   ??
Regards Simon
Davis Vantage Pro2 Plus (6162UK) • Daytime FARS • WeatherLink Live • AirLink • PurpleAir PA-II-SD • CumulusMX •


Offline Forever

  • Senior Contributor
  • ****
  • Posts: 209
Re: Purpleair PHP Retrieval script
« Reply #57 on: February 05, 2018, 06:12:05 PM »
The PM data is there but it lacks the Running Averages.

Here is a little script that will pull data from your PurpleAir you can play with. Just change the IP in the script.

Offline Forever

  • Senior Contributor
  • ****
  • Posts: 209
Re: Purpleair PHP Retrieval script
« Reply #58 on: February 06, 2018, 04:26:18 PM »
I noticed that the script for my cell broke when the PM reached 0.09. I did not have change to check this script before it went back over 0.1 but I used the same code on my cell page.

Will this script handle PM vales below 0.1?

Nice air quality in Northern California today. :)

Offline azchrisf

  • Cobra Weather Dominator Operator
  • Forecaster
  • *****
  • Posts: 455
Re: Purpleair PHP Retrieval script
« Reply #59 on: February 07, 2018, 03:10:11 AM »
I substitued a made up value and it displayed fine.

 [ You are not allowed to view attachments ]
« Last Edit: February 07, 2018, 07:39:05 AM by azchrisf »
Davis Vantage Pro 2 Plus 6163 w/ 8 Transmitters!
Also doing Soil and Leaf 4x
WU: KAZGLEND106 CWOP: FW1398 (F1398) Purpleair: 98793/LAZGLEND8
My setup:
https://www.wxforum.net/index.php?topic=41867.0

Offline ConligWX

  • Forecaster
  • *****
  • Posts: 836
  • #conligwx
    • conligwx.org
Re: Purpleair PHP Retrieval script
« Reply #60 on: February 08, 2018, 08:00:05 AM »
Small change to mine template.

changing code "m3" to m³ to show the m3 as m³
Regards Simon
Davis Vantage Pro2 Plus (6162UK) • Daytime FARS • WeatherLink Live • AirLink • PurpleAir PA-II-SD • CumulusMX •


Offline azchrisf

  • Cobra Weather Dominator Operator
  • Forecaster
  • *****
  • Posts: 455
Re: Purpleair PHP Retrieval script
« Reply #61 on: February 12, 2018, 08:07:50 AM »
Just to let everyone know I'm working on some changes for the next iteration. It's becoming "all it can be", so development will be slowing to, well, nothing, unless someone finds a bug or wants a feature.

// Version 1.5
// * Fixed bug where if decimal point was turned off decimal point numbers would still show - now display 0 as originally intended
// * Added option to cache results for x seconds - this is useful if you have a high traffic site. PA doesn't like you doing many calls to it.
// * Removed the site up checking, it slows the script and is redundant since the script will return an error anyways if it fails.
// * Changed m/3 to proper HTML entity (thanks Toxic)
// * Added all the variables from other sensor items (PM 1.0, ug/m3 for 0.3mm, 5mm, etc. - these can be used as you like but won't appear in the script HTML)
// * Added "Very Low" value to GetPMMessage for values < 1.0
Davis Vantage Pro 2 Plus 6163 w/ 8 Transmitters!
Also doing Soil and Leaf 4x
WU: KAZGLEND106 CWOP: FW1398 (F1398) Purpleair: 98793/LAZGLEND8
My setup:
https://www.wxforum.net/index.php?topic=41867.0

Offline Forever

  • Senior Contributor
  • ****
  • Posts: 209
Re: Purpleair PHP Retrieval script
« Reply #62 on: February 14, 2018, 12:11:04 PM »
Has version 1.5 been released or are the changes listed being worked on still?

Offline azchrisf

  • Cobra Weather Dominator Operator
  • Forecaster
  • *****
  • Posts: 455
Re: Purpleair PHP Retrieval script
« Reply #63 on: February 14, 2018, 01:13:09 PM »
Still working on it.

Sent from my Pixel using Tapatalk

Davis Vantage Pro 2 Plus 6163 w/ 8 Transmitters!
Also doing Soil and Leaf 4x
WU: KAZGLEND106 CWOP: FW1398 (F1398) Purpleair: 98793/LAZGLEND8
My setup:
https://www.wxforum.net/index.php?topic=41867.0

Offline JupiterJoe

  • Senior Contributor
  • ****
  • Posts: 195
  • JupiterWX.com
    • Live Jupiter, FL Weather
Re: Purpleair PHP Retrieval script
« Reply #64 on: February 15, 2018, 12:33:33 PM »
Thank you for your script, it's nice being able to get the data visualized on my website. http://www.joe4speed.com/purple.php

I was wondering if you would perhaps know any way to use this data to control the AQI on the front page of the Alt. Dashboard? Currently, I am only able to display the AirNow.gov data from West Palm Beach, and their AQI is totally different than our local AQI. www.jupiterwx.com

Thank you for any advice. It may not be possible, but I thought there would be no harm in asking. :)

Offline Forever

  • Senior Contributor
  • ****
  • Posts: 209
Re: Purpleair PHP Retrieval script
« Reply #65 on: February 15, 2018, 06:00:06 PM »
Sure you can include the AQI from your PurpleAir if you know what code to change.

I'm not familiar with the dashboard you're using so I'll show you what I did for the one on my cell page and you should be able to see what is being done.

http://www.weathercat.net/cell.php

I have attached the file I changed to pull data directly from my PurpleAir. This will probably not work for you but it should get you pointed in the correct direction.

Offline JupiterJoe

  • Senior Contributor
  • ****
  • Posts: 195
  • JupiterWX.com
    • Live Jupiter, FL Weather
Re: Purpleair PHP Retrieval script
« Reply #66 on: February 15, 2018, 06:46:49 PM »

Hi Forever,
Thank you for that code. I use the Alt Ajax dashboard built off of the Saratoga template. It looks very similar to yours and uses the aqirss.php script similar to yours.
I will definitely check it out though. Thank you for your reply.

Sure you can include the AQI from your PurpleAir if you know what code to change.

I'm not familiar with the dashboard you're using so I'll show you what I did for the one on my cell page and you should be able to see what is being done.

http://www.weathercat.net/cell.php

I have attached the file I changed to pull data directly from my PurpleAir. This will probably not work for you but it should get you pointed in the correct direction.

Offline sjforster

  • Member
  • *
  • Posts: 14
    • WesterhopeWX
Re: Purpleair PHP Retrieval script
« Reply #67 on: February 17, 2018, 07:27:45 PM »
Hi azchrisf, Toxic and Forever,

Thanks for the script and developing this, it's been most usefull.  I've just got my purple air sensor up and running today and with the help of the script getting the data onto my website so thankyou very much.   =D&gt;

To contribute a small bit heres a tweak I've made to allow just the Air Quality index to be displayed on the main dashboard, by appending ?aqionly=true to the purpleair.php e.g. purpleair.php?aqionly=true.  Obviously you need to create a place within the dasboard to display the data i.e it won't do it automatically.

Hope it's of use and feel free to do with it what ever you want and thanks once again.

Regards,

Simon.


« Last Edit: February 17, 2018, 07:31:56 PM by sjforster »

Offline azchrisf

  • Cobra Weather Dominator Operator
  • Forecaster
  • *****
  • Posts: 455
Re: Purpleair PHP Retrieval script
« Reply #68 on: February 22, 2018, 11:10:14 AM »
Okey dokey, releasing the final version - 1.5.
Updated in the original post.

I'd like to thank Toxic, Weatherbee and Forever for all of their contributions to the script. Without them it wouldn't have progressed so good.

Enjoy!
Final Changelog:

// Version 1.5 FINAL RELEASE
// * Fixed bug where if decimal point was turned off decimal point numbers would still show - now display 0 as originally intended
// * Added option to cache results - this is useful if you have a high traffic site. PA doesn't like you doing many calls to it.
// * Removed the site up checking, it slows the script and is redundant since the script will return an error anyways if it fails.
// * Changed m/3 to proper HTML entity (thanks Toxic)
// * Added "Very Low" value to GetPMMessage for values < 1.0
// * Added additional levels to GetPMComment
// * Added GetAQIExMessage - returns extended EPA recommendations for the AQI passed to it
// * Added options to turn on/off the Title and Timestamps
Davis Vantage Pro 2 Plus 6163 w/ 8 Transmitters!
Also doing Soil and Leaf 4x
WU: KAZGLEND106 CWOP: FW1398 (F1398) Purpleair: 98793/LAZGLEND8
My setup:
https://www.wxforum.net/index.php?topic=41867.0

Offline ConligWX

  • Forecaster
  • *****
  • Posts: 836
  • #conligwx
    • conligwx.org
Re: Purpleair PHP Retrieval script
« Reply #69 on: March 07, 2018, 05:01:30 PM »
Okey dokey, releasing the final version - 1.5.

Hi I have been cleaning up scripts since moving to PHP 7.2.x

looking at my Apache error  logs I see the following:

Quote
[Wed Mar 07 21:51:04.631870 2018] [php7:notice] [pid 5162:tid 140706869860096] [client xx.xx.188.229:58420] PHP Notice:  Undefined index: version in /htdocs/weather/purpleair.php on line 143
[Wed Mar 07 21:51:06.498380 2018] [php7:notice] [pid 5162:tid 140706869860096] [client xx.xx.188.229:58420] PHP Notice:  Undefined variable: showtitle in /htdocs/weather/purpleair.php on line 969
[Wed Mar 07 21:51:06.498440 2018] [php7:notice] [pid 5162:tid 140706869860096] [client xx.xx.188.229:58420] PHP Notice:  Undefined variable: sensorstamp in /htdocs/weather/purpleair.php on line 979

Can you tell me whats needed to fix this? As the Variables are not defined, why are they there?
Regards Simon
Davis Vantage Pro2 Plus (6162UK) • Daytime FARS • WeatherLink Live • AirLink • PurpleAir PA-II-SD • CumulusMX •


Offline jeffm5690

  • Forecaster
  • *****
  • Posts: 310
    • Long Island New York Weather
Re: Purpleair PHP Retrieval script
« Reply #70 on: March 11, 2018, 01:10:52 PM »
Thanks for the script.  I've incorporated it with my AQI block.
You can see at www.shermanctweather.org.
Tom

Would you be willing to share how you did this?  I would love to actually have a separate tab on the menu to have a page with this.

Offline Forever

  • Senior Contributor
  • ****
  • Posts: 209
Re: Purpleair PHP Retrieval script
« Reply #71 on: March 11, 2018, 03:37:52 PM »
Is the PurpleAir server having issues today? I'm not pulling data today for some reason.

http://www.weathercat.net/wxaqi.php
« Last Edit: November 17, 2021, 06:13:31 PM by Forever »

Offline giordolo

  • Member
  • *
  • Posts: 5
Re: Purpleair PHP Retrieval script
« Reply #72 on: March 11, 2018, 03:40:11 PM »
I'm bored by that
"No data from Purpleair servers for the script to process (Sensor A). Possibly PA site is down or incorrect sensor IDs."
Im a purpleair owner, why don't build a script that retrieve data directly from the sensor?
PA seems up. what is the role of thingspeak? who is really down?
giordolo

Offline ConligWX

  • Forecaster
  • *****
  • Posts: 836
  • #conligwx
    • conligwx.org
Re: Purpleair PHP Retrieval script
« Reply #73 on: March 11, 2018, 03:49:09 PM »
It's working here fine. so perhaps route from your server to purpleair.com is broken.

Sent from my ONEPLUS 5T using Tapatalk
Regards Simon
Davis Vantage Pro2 Plus (6162UK) • Daytime FARS • WeatherLink Live • AirLink • PurpleAir PA-II-SD • CumulusMX •


Offline giordolo

  • Member
  • *
  • Posts: 5
Re: Purpleair PHP Retrieval script
« Reply #74 on: March 11, 2018, 03:50:21 PM »
mmmm
looking to purpleair (json or map) is all fine
ty