Author Topic: Enter Weather Data On Webcam  (Read 705 times)

0 Members and 1 Guest are viewing this topic.

Offline gianvi97

  • Member
  • *
  • Posts: 4
Enter Weather Data On Webcam
« on: November 30, 2021, 01:21:19 PM »
Hi,
I have a weather station connected to wunderground that generates at this address

https://api.weather.com/v2/pws/observations/current?stationId=IMATER7&format=json&numericPrecision=decimal&units=m&apiKey=MIAAPIKEY

a string like this:

Code: [Select]
{"observations":[{"stationID":"IMATER7","obsTimeUtc":"2021-11-30T17:34:06Z","obsTimeLocal":"2021-11-30 18:34:06","neighborhood":"Matera","softwareType":null,"country":"IT","solarRadiation":null,"lon":16.614463,"realtimeFrequency":null,"epoch":1638293646,"lat":40.742697,"uv":null,"winddir":292,"humidity":79.0,"qcStatus":1,"metric":{"temp":3.8,"heatIndex":3.8,"dewpt":0.5,"windChill":2.0,"windSpeed":7.1,"windGust":7.1,"pressure":1018.96,"precipRate":0.00,"precipTotal":0.00,"elev":395.0}}]}
I want to use something, a script or other that sends this data (txt file) on my FTP in order to print it on the webcam.
For the webcam I have a php script on FTP to manage the shots from my Foscam and to print some writings that it takes from a txt file. The same script could take the txt file with the always updated weather data and put them on the last shot.
I don't know if anyone has tried this in the past and already uses something. Is it possible to do such a thing without having a PC running 24 hours a day?

Thanks

Offline davidmc36

  • He who dies with the most toys wins!
  • Forecaster
  • *****
  • Posts: 996
  • FN25ie61jw
    • MorewoodW34
Re: Enter Weather Data On Webcam
« Reply #1 on: November 30, 2021, 05:23:57 PM »
Mine is done with the Meteobridge.

See DATA CAM in my sig

Lots of people on here know how to do it with scripts and the like on RPi and such.

Offline davidmc36

  • He who dies with the most toys wins!
  • Forecaster
  • *****
  • Posts: 996
  • FN25ie61jw
    • MorewoodW34
Re: Enter Weather Data On Webcam
« Reply #2 on: November 30, 2021, 05:29:58 PM »
Just enter the string. Easy because I have not learned other methods. [ You are not allowed to view attachments ]  [ You are not allowed to view attachments ]
« Last Edit: November 30, 2021, 05:32:10 PM by davidmc36 »

Offline Daali

  • weather n00b
  • Senior Contributor
  • ****
  • Posts: 177
    • The weather in Jefferson, GA
Re: Enter Weather Data On Webcam
« Reply #3 on: November 30, 2021, 09:18:49 PM »
Hi,
I have a weather station connected to wunderground that generates at this address

https://api.weather.com/v2/pws/observations/current?stationId=IMATER7&format=json&numericPrecision=decimal&units=m&apiKey=MIAAPIKEY

a string like this:

Code: [Select]
{"observations":[{"stationID":"IMATER7","obsTimeUtc":"2021-11-30T17:34:06Z","obsTimeLocal":"2021-11-30 18:34:06","neighborhood":"Matera","softwareType":null,"country":"IT","solarRadiation":null,"lon":16.614463,"realtimeFrequency":null,"epoch":1638293646,"lat":40.742697,"uv":null,"winddir":292,"humidity":79.0,"qcStatus":1,"metric":{"temp":3.8,"heatIndex":3.8,"dewpt":0.5,"windChill":2.0,"windSpeed":7.1,"windGust":7.1,"pressure":1018.96,"precipRate":0.00,"precipTotal":0.00,"elev":395.0}}]}
I want to use something, a script or other that sends this data (txt file) on my FTP in order to print it on the webcam.
For the webcam I have a php script on FTP to manage the shots from my Foscam and to print some writings that it takes from a txt file. The same script could take the txt file with the always updated weather data and put them on the last shot.
I don't know if anyone has tried this in the past and already uses something. Is it possible to do such a thing without having a PC running 24 hours a day?

Thanks

https://cron-job.org/en/ would work for your script without having a pc up.

Offline gianvi97

  • Member
  • *
  • Posts: 4
Re: Enter Weather Data On Webcam
« Reply #4 on: December 01, 2021, 06:24:45 AM »
Mine is done with the Meteobridge.

See DATA CAM in my sig

Lots of people on here know how to do it with scripts and the like on RPi and such.

I know meteobridge but I would not like to use it.

Offline gianvi97

  • Member
  • *
  • Posts: 4
Re: Enter Weather Data On Webcam
« Reply #5 on: December 01, 2021, 06:27:48 AM »
Hi,
I have a weather station connected to wunderground that generates at this address

https://api.weather.com/v2/pws/observations/current?stationId=IMATER7&format=json&numericPrecision=decimal&units=m&apiKey=MIAAPIKEY

a string like this:

Code: [Select]
{"observations":[{"stationID":"IMATER7","obsTimeUtc":"2021-11-30T17:34:06Z","obsTimeLocal":"2021-11-30 18:34:06","neighborhood":"Matera","softwareType":null,"country":"IT","solarRadiation":null,"lon":16.614463,"realtimeFrequency":null,"epoch":1638293646,"lat":40.742697,"uv":null,"winddir":292,"humidity":79.0,"qcStatus":1,"metric":{"temp":3.8,"heatIndex":3.8,"dewpt":0.5,"windChill":2.0,"windSpeed":7.1,"windGust":7.1,"pressure":1018.96,"precipRate":0.00,"precipTotal":0.00,"elev":395.0}}]}
I want to use something, a script or other that sends this data (txt file) on my FTP in order to print it on the webcam.
For the webcam I have a php script on FTP to manage the shots from my Foscam and to print some writings that it takes from a txt file. The same script could take the txt file with the always updated weather data and put them on the last shot.
I don't know if anyone has tried this in the past and already uses something. Is it possible to do such a thing without having a PC running 24 hours a day?

Thanks

https://cron-job.org/en/ would work for your script without having a pc up.

I already use the cronjob. However, I would like a hand with the creation of the script. I made a draft which is this but it doesn't work ...

Code: [Select]
<?php
    header
("Refresh: 120; url=data.php")

$url "https://api.weather.com/v2/pws/observations/current?stationId=IMATER7&format=json&numericPrecision=decimal&units=m&apiKey=mykey";
$parts parse_url($url);
$output = [];
parse_str($parts['query'], $output);
echo 
$output['page'];

$file fopen("file.txt""w");
fwrite($file$output['page']);
fclose($file);
?>

I think the json format creates problems, maybe I should create arrays. I could get the data from the url like this:

Code: [Select]
$json=fetchPageFromURL('myurl');
$data=json_decode($json,true);
print_r($data);

The curl function might be fine too but I don't know how to set it up.

Offline davidefa

  • Forecaster
  • *****
  • Posts: 320
Re: Enter Weather Data On Webcam
« Reply #6 on: December 01, 2021, 08:52:09 AM »
You can try something like this
Code: [Select]
<?php
$url 
"https://api.weather.com/v2/pws/observations/current?stationId=IMATER7&format=json&numericPrecision=decimal&units=m&apiKey=YOURAPIKEY";
$outFileName "current.txt";
$debug "1";

$json file_get_contents($url);
$data json_decode($json);
file_put_contents($outFileName$data->observations[0]->obsTimeLocal."\n"); // first line without APPEND flag
file_put_contents($outFileName$data->observations[0]->metric->temp."\n"FILE_APPEND); // subsequent lines with APPEND flag
file_put_contents($outFileName$data->observations[0]->humidity."\n"FILE_APPEND);
// extend as required

/* available fields:
$data->observations[0]->obsTimeUtc
$data->observations[0]->obsTimeLocal
$data->observations[0]->solarRadiation
$data->observations[0]->uv
$data->observations[0]->windDir
$data->observations[0]->humidity
$data->observations[0]->metric->temp
$data->observations[0]->metric->heatIndex
$data->observations[0]->metric->dewpt
$data->observations[0]->metric->windChill
$data->observations[0]->metric->windSpeed
$data->observations[0]->metric->windGust
$data->observations[0]->metric->pressure
$data->observations[0]->metric->precipRate
$data->observations[0]->metric->precipTotal
*/

if ($debug)
   {
   
// only for testing ( prints to video )
   
print_r($data); echo "<br>";
   echo 
$data->observations[0]->obsTimeLocal."<br>";
   echo 
$data->observations[0]->metric->temp."<br>";
   echo 
$data->observations[0]->humidity."<br>";
   }
?>

Offline gianvi97

  • Member
  • *
  • Posts: 4
Re: Enter Weather Data On Webcam
« Reply #7 on: December 01, 2021, 10:22:23 AM »
You can try something like this
Code: [Select]
<?php
$url 
"https://api.weather.com/v2/pws/observations/current?stationId=IMATER7&format=json&numericPrecision=decimal&units=m&apiKey=YOURAPIKEY";
$outFileName "current.txt";
$debug "1";

$json file_get_contents($url);
$data json_decode($json);
file_put_contents($outFileName$data->observations[0]->obsTimeLocal."\n"); // first line without APPEND flag
file_put_contents($outFileName$data->observations[0]->metric->temp."\n"FILE_APPEND); // subsequent lines with APPEND flag
file_put_contents($outFileName$data->observations[0]->humidity."\n"FILE_APPEND);
// extend as required

/* available fields:
$data->observations[0]->obsTimeUtc
$data->observations[0]->obsTimeLocal
$data->observations[0]->solarRadiation
$data->observations[0]->uv
$data->observations[0]->windDir
$data->observations[0]->humidity
$data->observations[0]->metric->temp
$data->observations[0]->metric->heatIndex
$data->observations[0]->metric->dewpt
$data->observations[0]->metric->windChill
$data->observations[0]->metric->windSpeed
$data->observations[0]->metric->windGust
$data->observations[0]->metric->pressure
$data->observations[0]->metric->precipRate
$data->observations[0]->metric->precipTotal
*/

if ($debug)
   {
   
// only for testing ( prints to video )
   
print_r($data); echo "<br>";
   echo 
$data->observations[0]->obsTimeLocal."<br>";
   echo 
$data->observations[0]->metric->temp."<br>";
   echo 
$data->observations[0]->humidity."<br>";
   }
?>
Thank you very much.

Works well.

I tried putting a header to update it but it doesn't work. Maybe I need to use a cronjob?

Also in the txt file I would need to insert a space between the various data and what they refer to for example 11.4, I want to see: temperatures 11.4 C etc. and all on one line without the date. I tried to remove the line:

"file_put_contents ($ outFileName, $ data-> observations
  • -> obsTimeLocal." \ n ");"


but it does not work

Code: [Select]
<?php
header("Refresh: 120; url=script.php")
$url "https://api.weather.com/v2/pws/observations/current?stationId=IMATER7&format=json&numericPrecision=decimal&units=m&apiKey=mykey";
$outFileName "current.txt";
$debug "1";

$json file_get_contents($url);
$data json_decode($json);
file_put_contents($outFileName$data->observations[0]->obsTimeLocal); // first line without APPEND flag
file_put_contents($outFileName$data->observations[0]->metric->temp."C"FILE_APPEND); // subsequent lines with APPEND flag
file_put_contents($outFileName$data->observations[0]->humidity."%"FILE_APPEND);


// extend as required

/* available fields:
$data->observations[0]->obsTimeUtc
$data->observations[0]->obsTimeLocal
$data->observations[0]->solarRadiation
$data->observations[0]->uv
$data->observations[0]->windDir
$data->observations[0]->humidity
$data->observations[0]->metric->temp
$data->observations[0]->metric->heatIndex
$data->observations[0]->metric->dewpt
$data->observations[0]->metric->windChill
$data->observations[0]->metric->windSpeed
$data->observations[0]->metric->windGust
$data->observations[0]->metric->pressure
$data->observations[0]->metric->precipRate
$data->observations[0]->metric->precipTotal
*/

if ($debug)
   {
   
// only for testing ( prints to video )
   
print_r($data); echo "<br>";
   echo 
$data->observations[0]->metric->temp."<br>";
   echo 
$data->observations[0]->humidity."<br>";
   }
?>
« Last Edit: December 01, 2021, 10:27:02 AM by gianvi97 »

Offline davidefa

  • Forecaster
  • *****
  • Posts: 320
Re: Enter Weather Data On Webcam
« Reply #8 on: December 01, 2021, 12:39:31 PM »
This will create a 'one line' text file.
You have to call this script from your overlay script ( just put a require_once("wuCurrent.php"); ad the beginning of the overlay script, considering you called this script wuCurrent.php )

Code: (php) [Select]
<?php
$url 
"https://api.weather.com/v2/pws/observations/current?stationId=IMATER7&format=json&numericPrecision=decimal&units=m&apiKey=YOURAPIKEY";
$outFileName "current.txt";
$debug "1";

$json file_get_contents($url);
$data json_decode($json);
file_put_contents($outFileName"temperature " $data->observations[0]->metric->temp "C  "); // first line without APPEND flag
file_put_contents($outFileName"humidity "    $data->observations[0]->humidity     "%  "FILE_APPEND); // subsequent lines with APPEND flag
// extend as required

/* available fields:
$data->observations[0]->obsTimeUtc
$data->observations[0]->obsTimeLocal
$data->observations[0]->solarRadiation
$data->observations[0]->uv
$data->observations[0]->windDir
$data->observations[0]->humidity
$data->observations[0]->metric->temp
$data->observations[0]->metric->heatIndex
$data->observations[0]->metric->dewpt
$data->observations[0]->metric->windChill
$data->observations[0]->metric->windSpeed
$data->observations[0]->metric->windGust
$data->observations[0]->metric->pressure
$data->observations[0]->metric->precipRate
$data->observations[0]->metric->precipTotal
*/

if ($debug)
   {
   
// only for testing ( prints to video )
   
print_r($data); echo "<br>";
   echo 
$data->observations[0]->metric->temp."<br>";
   echo 
$data->observations[0]->humidity."<br>";
   }
?>

 

anything