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

73 lines
3.0 KiB
PHP

<?php
session_start();
$page_title = "Connect to IoT Channel";
$page_description = "Connect your ThingSpeak-compatible IoT channel to start monitoring.";
$channel_id = $_SESSION['channel_id'] ?? '';
$api_key = $_SESSION['api_key'] ?? '';
$message = '';
$message_type = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$channel_id = trim($_POST['channel_id']);
$api_key = trim($_POST['api_key']);
if (!empty($channel_id) && !empty($api_key)) {
// For now, we just validate that they are not empty.
// In a real scenario, we would test the connection to ThingSpeak API.
$_SESSION['channel_id'] = $channel_id;
$_SESSION['api_key'] = $api_key;
$message = '<strong>Success!</strong> Your settings have been saved. You can now proceed to the dashboard.';
$message_type = 'success';
} else {
$message = '<strong>Error!</strong> Please provide a valid Channel ID and Read API Key.';
$message_type = 'danger';
}
}
include 'partials/header.php';
?>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-body p-5">
<h2 class="card-title text-center mb-4">Connect IoT Channel</h2>
<?php if ($message): ?>
<div class="alert alert-<?php echo $message_type; ?> alert-dismissible fade show" role="alert">
<?php echo $message; ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php endif; ?>
<form action="connect.php" method="POST" id="connectForm" novalidate>
<div class="mb-3">
<label for="channel_id" class="form-label">Channel ID</label>
<input type="text" class="form-control" id="channel_id" name="channel_id" value="<?php echo htmlspecialchars($channel_id); ?>" required>
<div class="invalid-feedback">
Please enter your ThingSpeak Channel ID.
</div>
</div>
<div class="mb-3">
<label for="api_key" class="form-label">Read API Key</label>
<input type="text" class="form-control" id="api_key" name="api_key" value="<?php echo htmlspecialchars($api_key); ?>" required>
<div class="invalid-feedback">
Please enter your Read API Key.
</div>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary btn-lg">Connect</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<?php include 'partials/footer.php'; ?>