Import temperatury z openweathermap.org do thingspeak.com
Opis: Skrypt umożliwia pobranie bieżącej temperatury z serwisu openweathermap.org i dodanie jej serwisu thingspeak.com, gdzie możemy zrobić analizę. Skrypt wywołujemy co 15 minut, przy użyciu serwisu cron-job.org.
Technologia: php
Skrypt:
<?php
function httpPost($url, $data)
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
$data = file_get_contents('https://api.openweathermap.org/data/2.5/weather?q=kwidzyn&appid={API_KEY}&units=metric');
$decodedData = json_decode($data, true);
$temp = $decodedData['main']['temp'];
$url = 'https://api.thingspeak.com/update?api_key={API_KEY}&field3='. $temp;
$data = '';
httpPost($url, $data);
?>