22 lines
610 B
PHP
22 lines
610 B
PHP
<?php
|
|
session_start();
|
|
header('Content-Type: application/json');
|
|
|
|
require_once __DIR__ . '/../includes/thingspeak.php';
|
|
|
|
$channel_id = $_SESSION['channel_id'] ?? null;
|
|
$api_key = $_SESSION['api_key'] ?? null;
|
|
|
|
if (!$channel_id || !$api_key) {
|
|
echo json_encode(['error' => 'Not connected. Please set Channel ID and API Key.']);
|
|
exit;
|
|
}
|
|
|
|
$data = fetch_thingspeak_data($channel_id, $api_key, 50); // Fetch more points for better clustering
|
|
|
|
if ($data && !empty($data['feeds'])) {
|
|
echo json_encode($data['feeds']);
|
|
} else {
|
|
echo json_encode(['error' => 'Failed to fetch data from ThingSpeak.']);
|
|
}
|