add post commands and reboot

This commit is contained in:
2025-09-10 12:32:12 +10:00
parent 5a21768b70
commit 2a0e9df0f3
3 changed files with 22 additions and 3 deletions

View File

@ -7,7 +7,7 @@ import { getCommands, getLatestGPS, DeviceCommand, TelemetryPost, DeviceCommandT
// Dynamically import the map component with SSR turned OFF to prevent "window is not defined" errors
const DeviceMap = dynamic(
() => import("~/components/DeviceMapClient").then((mod) => mod.DeviceMap),
() => import("~/_components/DeviceMapClient").then((mod) => mod.DeviceMap),
{
ssr: false,
loading: () => <p>Loading map...</p>,
@ -99,6 +99,7 @@ export default function Dashboard() {
<option value="camera">Camera On/Off</option>
<option value="sleep">Set Sleep Interval</option>
<option value="telemetry_sec">Set Telemetry Interval</option>
<option value="reboot">Reboot</option>
</select>
<textarea
className="p-2 text-white rounded-md bg-white/10"
@ -115,4 +116,21 @@ export default function Dashboard() {
</section>
</main>
);
const sendCommand = async () => {
try {
const parsedPayload = payload ? JSON.parse(payload) : {};
const response = await postCommand(selectedImei, {
type: commandType,
payload: parsedPayload,
});
console.log("Command sent successfully, ID:", response.command_id);
alert("Command sent successfully!");
setPayload(""); // Clear the input field
} catch (e) {
console.error("Failed to send command:", e);
alert(`Failed to send command: ${e instanceof Error ? e.message : String(e)}`);
}
};
}

View File

@ -10,7 +10,8 @@ export type DeviceCommandType =
| "ota"
| "ring_fence"
| "lights"
| "camera";
| "camera"
| "reboot";
export interface DeviceCommand {
id: number;
@ -116,4 +117,4 @@ export async function postCommand(
headers: { "Content-Type": "application/json" },
body: JSON.stringify(command),
});
}
}