add post commands and reboot
This commit is contained in:
@ -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
|
// Dynamically import the map component with SSR turned OFF to prevent "window is not defined" errors
|
||||||
const DeviceMap = dynamic(
|
const DeviceMap = dynamic(
|
||||||
() => import("~/components/DeviceMapClient").then((mod) => mod.DeviceMap),
|
() => import("~/_components/DeviceMapClient").then((mod) => mod.DeviceMap),
|
||||||
{
|
{
|
||||||
ssr: false,
|
ssr: false,
|
||||||
loading: () => <p>Loading map...</p>,
|
loading: () => <p>Loading map...</p>,
|
||||||
@ -99,6 +99,7 @@ export default function Dashboard() {
|
|||||||
<option value="camera">Camera On/Off</option>
|
<option value="camera">Camera On/Off</option>
|
||||||
<option value="sleep">Set Sleep Interval</option>
|
<option value="sleep">Set Sleep Interval</option>
|
||||||
<option value="telemetry_sec">Set Telemetry Interval</option>
|
<option value="telemetry_sec">Set Telemetry Interval</option>
|
||||||
|
<option value="reboot">Reboot</option>
|
||||||
</select>
|
</select>
|
||||||
<textarea
|
<textarea
|
||||||
className="p-2 text-white rounded-md bg-white/10"
|
className="p-2 text-white rounded-md bg-white/10"
|
||||||
@ -115,4 +116,21 @@ export default function Dashboard() {
|
|||||||
</section>
|
</section>
|
||||||
</main>
|
</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)}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,8 @@ export type DeviceCommandType =
|
|||||||
| "ota"
|
| "ota"
|
||||||
| "ring_fence"
|
| "ring_fence"
|
||||||
| "lights"
|
| "lights"
|
||||||
| "camera";
|
| "camera"
|
||||||
|
| "reboot";
|
||||||
|
|
||||||
export interface DeviceCommand {
|
export interface DeviceCommand {
|
||||||
id: number;
|
id: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user