36028-vm/includes/thingspeak.php
Flatlogic Bot c38ec08c48 1.00
2025-11-22 18:25:54 +00:00

18 lines
512 B
PHP

<?php
function fetch_thingspeak_data($channel_id, $api_key, $results = 10) {
$url = "https://api.thingspeak.com/channels/{$channel_id}/feeds.json?api_key={$api_key}&results={$results}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code == 200) {
return json_decode($output, true);
}
return null;
}
?>