Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button to shutdown toypad #152

Open
gaspopi opened this issue Sep 1, 2023 · 1 comment
Open

Add button to shutdown toypad #152

gaspopi opened this issue Sep 1, 2023 · 1 comment

Comments

@gaspopi
Copy link

gaspopi commented Sep 1, 2023

@Berny23 thanks for a great job with this.
If you allow me a suggestion, could you add a button to shutdown the toypad machine (debian)?
I try with this code and work for me:

Change in /index.js
// ---------------------Begin of shutdown----------------------------------------------------
// Importa el módulo 'child_process' para ejecutar comandos del sistema
const { exec } = require('child_process');

// ...

// Ruta para apagar el sistema
app.post('/shutdown', (request, response) => {
// Ejecuta el comando para apagar el sistema
exec('sudo shutdown -h now', (error, stdout, stderr) => {
if (error) {
console.error(Error al apagar el sistema: ${error.message});
response.status(500).send('Error al apagar el sistema');
return;
}
console.log(Sistema apagado: ${stdout});
response.send('El sistema se está apagando...');
});
});

// ---------------------End of shutdown----------------------------------------------------

Change in /server/index.html

Apagar el sistema

<style> #shutdownButton { background-color: red; color: white; animation: blink 1s infinite; } @Keyframes blink { 0% { opacity: 0; } 50% { opacity: 1; } 100% { opacity: 0; } } </style> <script> // Agrega el código JavaScript para enviar la solicitud POST al hacer clic en el botón document.getElementById('shutdownButton').addEventListener('click', function() { fetch('/shutdown', { method: 'POST' }) .then(response => response.text()) .then(message => { console.log(message); alert('El sistema se está apagando. Por favor, espere unos momentos antes de apagar físicamente.'); }) .catch(error => { console.error('Error al enviar la solicitud de apagado:', error); alert('Hubo un error al apagar el sistema.'); }); }); </script>

Again, thanks for all!
GASPOPI

@VladimirKuletski
Copy link
Contributor

Great idea.
I have to go to SSH shell to turn it off safely each time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants