const handleSendResume = async (command) => {
try {
const response = await fetch(`/api/commands/send`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
deviceId,
type: command,
}),
});
if (!response.ok) {
throw new Error('Falha ao enviar Comando');
}
showSnackbar('Desbloqueio', 'Comando enviado com sucesso!', 'success');
} catch (error) {
showSnackbar('Aviso', 'Comando não enviado!', 'warning');
}
};
Abaixo da funçãoresponse utilize o body e defina o device.id
pq nao mandou no whats kkkk, mas agora eu entendi, deu certo valew
I created a button on the statuscard (padlock icon) to lock and unlock the engine, on the same button, but there is an error when sending the command, I don't know what I'm doing wrong, can anyone help?
This is the relevant part of the code
const handleLockUnlockClick = async () => { const command = isEngineBlocked ? 'engineResume' : 'engineStop'; // Alterna o comando const response = await fetch('/api/commands/send', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ command }), }); if (response.ok) { setIsEngineBlocked(!isEngineBlocked); // Alterna o estado setSnackbarMessage(isEngineBlocked ? 'Motor bloqueado' : 'Motor desbloqueado'); // Corrigido setSnackbarSeverity('success'); } else { setSnackbarMessage('Erro ao enviar comando'); setSnackbarSeverity('error'); } setSnackbarOpen(true); };