What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Working (and easy) weather icon in maps

Votes:

5

Hi all,

I found a lot of threads about placing a weather icon in maps (or create a sensor to monitor it) but nothing worked well for me so I did one by myself.

Admin Note:
Requires an secondary web-server capable of processing php scripts.


1. Create a page called weather.php and copy/paste this:

<?
$request = 'http://api.openweathermap.org/data/2.5/weather?q='. $_GET["location"] .'&lang=en';
    $response  = file_get_contents($request);
    $jsonobj  = json_decode($response);
?>
<div style="border: 1px solid black; width: 85px; text-align: center;">
<p style="margin: 0px; font-family: Verdana; font-size: 10px"><?echo $jsonobj->{'weather'}[0]->{'description'}?></p>
<img src="http://openweathermap.org/img/w/<?echo $jsonobj->{'weather'}[0]->{'icon'}?>.png">
</div>

Save weather.php on your web server.

2. Add in your map a custom HTML object and copy this code in the html-after:

<iframe src="http://yourwebserver/weather.php?location=London,uk" allowtransparency="true" frameborder="0"></iframe>

I hope that this could help you :)

custom-html maps php prtg weather

Created on Aug 25, 2015 10:24:42 AM

Last change on Aug 25, 2015 1:59:39 PM by  Luciano Lingnau [Paessler]



Best Answer

Accepted Answer

Votes:

6

If someone's getting an error with the file_get_content you could use this code: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://api.openweathermap.org/data/2.5/weather?q='. $_GET["location"] .'&lang=it&units=metric&APPID=XXXXXXXXXXXXXXXXXX'); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_HEADER, false); $response = curl_exec($ch); curl_close($ch);

instead of this one: $request = 'http://api.openweathermap.org/data/2.5/weather?q='. $_GET["location"] .'&lang=en'; $response = file_get_contents($request);

You've to replace the XXXXXXXXXXXXXXXXXX string with the appid that you receive once you register a username in the openweather site .

Created on Oct 9, 2015 12:30:30 PM



2 Replies

Votes:

1

Greetings AndreaM,
we appreciate your contribution. Thank you.

Best Regards,

Created on Aug 25, 2015 1:57:23 PM by  Luciano Lingnau [Paessler]



Accepted Answer

Votes:

6

If someone's getting an error with the file_get_content you could use this code: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://api.openweathermap.org/data/2.5/weather?q='. $_GET["location"] .'&lang=it&units=metric&APPID=XXXXXXXXXXXXXXXXXX'); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_HEADER, false); $response = curl_exec($ch); curl_close($ch);

instead of this one: $request = 'http://api.openweathermap.org/data/2.5/weather?q='. $_GET["location"] .'&lang=en'; $response = file_get_contents($request);

You've to replace the XXXXXXXXXXXXXXXXXX string with the appid that you receive once you register a username in the openweather site .

Created on Oct 9, 2015 12:30:30 PM




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.