Author Topic: Help converting JSOn from Winderground to Davis  (Read 805 times)

0 Members and 1 Guest are viewing this topic.

Offline silver_2000

  • Member
  • *
  • Posts: 4
    • 114th
Help converting JSOn from Winderground to Davis
« on: August 06, 2019, 12:41:30 PM »
Hi
Ive taken over a website that has used json data from Wunderground for years but the new limits are causing issues for us. We hit the API limit and the widget is broken till the limit resets

I want to convert our current widget  we have that parses the Wunderground API and start using the Davis API

Im no developer though.   Any suggestions on how to convert the code ?  The Davis API isnt very well documented

Here is the section of the header file that goes to get the data from API and then parse it and display just the temp, wind speed, wind direction and observation time

Im guessing the issue is with the authorization or postman token but I cant find any details on how that works
Im no Curl expert


Thanks in advance for your help and time

<div class="weather_topdata">
         <?php
       $curl = curl_init();
           //  wunderground  $url= "https://api.weather.com/v2/pws/observations/current?stationId=Kxx&format=json&units=e&apiKey=xxxxxxxxxxxx"; 
//davis URL           
 $url= "https://api.weatherlink.com/v1/NoaaExt.json?user=xxA&pass=xxher&apiToken=xxxxxxxxxx";      
               curl_setopt_array($curl, array(
           CURLOPT_URL => $url,
           CURLOPT_RETURNTRANSFER => true,
           CURLOPT_ENCODING => "",
           CURLOPT_MAXREDIRS => 10,
           CURLOPT_TIMEOUT => 30,
           CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
           CURLOPT_CUSTOMREQUEST => "GET",
           CURLOPT_POSTFIELDS => "",
           CURLOPT_HTTPHEADER => array(
            "authorization: Basic xxx6YWRtaW4=",
            "cache-control: no-cache",
            "content-type: application/x-www-form-urlencoded",
            "postman-token: xxx-1882-403a-xxxxx-xxxxx1e05"
           ),
         ));

         $response = curl_exec($curl);
         $err = curl_error($curl);

         curl_close($curl);

         if ($err) {
           echo "cURL Error #:" . $err;
         } else {
            $json_decode = json_decode($response);
         }
        // echo "<pre>";
         //print_r($json_decode);
      //   echo "</pre>";
         
         foreach ($json_decode as $key=>$val) {
          //$a = (object)$val; 
         
         // Wunderground API
                        /*  $temp_f=$val[0]->imperial->temp;
                         //$temp_f=$val[0]->imperial->tempHigh;
                         //$wind_speed=$val[0]->imperial->windspeedHigh;
                         $wind_speed=$val[0]->imperial->windSpeed;
                         $wind_high_gust=$val[0]->imperial->windGust;
                      $obs_time=$val[0]->obsTimeLocal;
                         $wind_dir=$val[0]->winddir;  */
                         
                         // davis weather link API
                         $temp_f=$val[0]->imperial->temp_f;   
                         $wind_speed=$val[0]->imperial->wind_mph;
                         $wind_dir=$val[0]->imperial->wind_dir;
                         $wind_deg=$val[0]->imperial->wind_degrees;
                         $wind_high_gust=$val[0]->imperial->wind_ten_min_gust_mph;
                         $obs_time=$val[0]->observation_time; 

            }


Online johnd

  • Forecaster
  • *****
  • Posts: 4852
    • www.weatherstations.co.uk
Re: Help converting JSOn from Winderground to Davis
« Reply #1 on: August 06, 2019, 12:48:24 PM »
TBH before you invest too much time in this it might be worth providing some metrics for your planned usage - you might find that hit some usage limits on the wl.com site too. eg

Is this just for one station (maybe your own) or for multiple stations - if so, how many?

How often are you expecting to refresh the reading(s)?
Prodata Weather Systems
Prodata's FAQ/support site for Davis stations
Includes many details on 6313 Weatherlink console.
UK Davis Premier Dealer - All Davis stations, accessories and spares
Cambridge UK

Sorry, but I don't usually have time to help with individual issues by email unless you are a Prodata customer. Please post your issue in the relevant forum section here & I will comment there if I have anything useful to add.

Offline silver_2000

  • Member
  • *
  • Posts: 4
    • 114th
Re: Help converting JSOn from Winderground to Davis
« Reply #2 on: August 06, 2019, 01:08:00 PM »
thanks for quick reply

it's just for our station - we use it to see the conditions at our property so we can decide whether to fly RC planes or not

Now it refreshes the data every time the page loads

site is only seeing about 200 visits a day - but they could be refreshing the pages

If we need to we can set limits on the refresh in the code
And yes we could do the same with wunderground but we have just had too many issues with wunderground to keep burning time on it.

we also run the weather station wordpress plugin that we could leverage and parse test from it ...

Online johnd

  • Forecaster
  • *****
  • Posts: 4852
    • www.weatherstations.co.uk
Re: Help converting JSOn from Winderground to Davis
« Reply #3 on: August 06, 2019, 01:15:57 PM »
That sounds OK, but why not just use the weatherlink.com embed from your station account via an iframe on your webpage? Wouldn't that be simpler? If you want an example then there's one on our website - see:

https://www.weatherstations.co.uk/weatherlink-live.htm

The embed is the rectangle headed ESN WLL about halfway down on the left. If you watch then it will auto-update every minute.
Prodata Weather Systems
Prodata's FAQ/support site for Davis stations
Includes many details on 6313 Weatherlink console.
UK Davis Premier Dealer - All Davis stations, accessories and spares
Cambridge UK

Sorry, but I don't usually have time to help with individual issues by email unless you are a Prodata customer. Please post your issue in the relevant forum section here & I will comment there if I have anything useful to add.

Offline silver_2000

  • Member
  • *
  • Posts: 4
    • 114th
Re: Help converting JSOn from Winderground to Davis
« Reply #4 on: August 06, 2019, 01:19:18 PM »
we dont have weather link live - not sure if its required

we are trying to create an interface that only shows the data we want

Online johnd

  • Forecaster
  • *****
  • Posts: 4852
    • www.weatherstations.co.uk
Re: Help converting JSOn from Winderground to Davis
« Reply #5 on: August 06, 2019, 01:26:23 PM »
The embeds are available for any upload device to wl.com. The WLL page was just an example.

Obviously up to you, but does it really matter if there are a couple of extra data items there? The embeds are really simple to set up. Anything else will need more work.

But if you want to pursue JSON then take a look at our online notes at:

https://www.manula.com/manuals/pws/davis-kb/1/en/topic/wl-com-2-0-data-handling

« Last Edit: August 06, 2019, 01:48:11 PM by johnd »
Prodata Weather Systems
Prodata's FAQ/support site for Davis stations
Includes many details on 6313 Weatherlink console.
UK Davis Premier Dealer - All Davis stations, accessories and spares
Cambridge UK

Sorry, but I don't usually have time to help with individual issues by email unless you are a Prodata customer. Please post your issue in the relevant forum section here & I will comment there if I have anything useful to add.

Offline silver_2000

  • Member
  • *
  • Posts: 4
    • 114th
Re: Help converting JSOn from Winderground to Davis
« Reply #6 on: August 07, 2019, 10:33:09 AM »
Its a design choice ...

Having a giant branded plugin is easy but not what Im going for