Shutdown Raspi4/Volumio3, remote Batch

Hello, everyone,
I want to shut down the Raspi4/Volumio3 from Debian.
The whole thing should happen via the Websocket.Client by batch.
socket.io-client is installed locally.

The batch comes with:

node down.js

started, I get no reaction, also no error message.

Content of the batch:

#!/usr/bin/node
var io = require('socket.io-client');
var socket = io.connect('http://192.168.51.33:3000');

socket.on('shutdown', function () {
	return self.commandRouter.shutdown();
	process.exit();
});
process.exit();

What do I have to do to make it work?

Try

#!/usr/bin/node
var io = require(‘socket.io-client’);
var socket = io.connect(‘http://192.168.51.33:3000’);

socket.emit("shutdown")

PS: Not everyone here can understand Deutsch, try a translator like Google/Microsoft translator next time! :slight_smile:

Thanks. I get no result, not even when I start the .js directly on the Raspi. socket.io-client is installed.
Pause, play, volume don’t work either. The Index.js is installed on the Raspi/Volumio.
I’m out of ideas.

If the node script is running on the pi, change the host to localhost
From other devices in your network, you need to confirm that you have the right IP address of the device you want to control.

I did that of course. Locally and also externally.
it looks like the websocket is not running on the volumio. But all functions there are ok.

If you can access the UI normally, then the websocket is running.

Try opening the console with journalctl -f and then run your node script and see if the socket is being registered.

#!/usr/bin/node
var io = require(‘socket.io-client’);
var socket = io.connect(‘http://192.168.51.33:3000’);

socket.emit('shutdown', '')

Try with this. Socket.io requires both emit and payload. Also don’t forget port 3000

Let us know

#!/usr/bin/node
console.log("Start Programm")
var io = require('socket.io');
var socket = io.connect('http://localhost:3000',{secure: false});
socket.emit('reboot','');
console.log("Programm Ende")
process.exit();
/volumio$ node down.js
Start Programm
/volumio/down.js:4
var socket = io.connect('http://localhost:3000',{secure: false});
                ^

TypeError: io.connect is not a function
    at Object.<anonymous> (/volumio/down.js:4:17)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47

Sorry, I’m still learning :slight_smile:
What now ?

I would take the code that is given. You have created an object socket.io instead of socket.io-client.
socket.io doesn’t has a function connect, hence the error.

Try

#!/usr/bin/node
console.log("Start Programm")
var io = require('/volumio/node_modules/socket.io-client');
var socket = io.connect('http://localhost:3000');
socket.emit('reboot','');
console.log("Programm Ende")
process.exit();

#!/usr/bin/node
console.log(“Start Programm”)
var io = require(‘socket.io-client’);
var socket = io.connect(‘http://localhost:3000’);
socket.emit(‘reboot’,’’);
console.log(“Programm Ende”)
process.exit();


socket.io-client@4.4.1 socket.io@4.4.1 NODE v14.15.4 Is installed.

New realization.
I entered each line of code one by one in the NODE console:

var io = require(‘socket.io-client’);

var socket = io.connect(‘http://localhost:3000’);

journalctl -f says:

Feb 23 20:04:01 volumio volumio[25445]: verbose: New Socket.io Connection to localhost:3000 from 127.0.0.1 UA: node-XMLHttpRequest Total Clients: 8

socket.emit(‘reboot’,’’);

journalctl -f says:

Feb 23 20:04:01 volumio volumio[25445]: verbose: New Socket.io Connection to localhost:3000 from 127.0.0.1 UA: node-XMLHttpRequest Total Clients: 8

Node-Console says:

<ref *1> Socket {
connected: false,
disconnected: true,
receiveBuffer: ,
sendBuffer: [ { type: 2, data: [Array], options: [Object] } ],
ids: 0,
acks: {},
flags: {},
io: Manager {
nsps: { ‘/’: [Circular *1] },
subs: [ [Function: subDestroy] ],
opts: {
path: ‘/socket.io’,
hostname: ‘localhost’,
secure: false,
port: ‘3000’
},
setTimeoutFn: [Function: bound setTimeout],
clearTimeoutFn: [Function: bound clearTimeout],
_reconnection: true,
_reconnectionAttempts: Infinity,
_reconnectionDelay: 1000,
_reconnectionDelayMax: 5000,
_randomizationFactor: 0.5,
backoff: Backoff {
ms: 1000,
max: 5000,
factor: 2,
jitter: 0.5,
attempts: 14
},
_timeout: 20000,
_readyState: ‘closed’,
uri: ‘http://localhost:3000’,
encoder: Encoder {},
decoder: Decoder {},
_autoConnect: true,
engine: Socket {
setTimeoutFn: [Function: bound setTimeout],
clearTimeoutFn: [Function: bound clearTimeout],
secure: false,
hostname: ‘localhost’,
port: ‘3000’,
transports: [Array],
readyState: ‘closed’,
writeBuffer: ,
prevBufferLen: 0,
opts: [Object],
id: null,
upgrades: null,
pingInterval: null,
pingTimeout: null,
pingTimeoutTimer: null,
transport: [XHR],
_callbacks: {}
},
skipReconnect: false,
_callbacks: {
‘$open’: [Array],
‘$packet’: [Array],
‘$error’: [Array],
‘$close’: [Array]
},
_reconnecting: true
},
nsp: ‘/’,
subs: [
[Function: subDestroy],
[Function: subDestroy],
[Function: subDestroy],
[Function: subDestroy]
],
_callbacks: {}
}

Does that give us more info?

Unfortunately, that is a version that is not compatible with current volumio. You need an older version.
Something in the 2.x range IIRC.

You can check from /volumio/package.json

It works. :slight_smile:
The socket.io-client@2.4.0 must be installed on Volumio3.

Thank you to everyone who has helped me here.

Stay healthy.