Max2Play Home › Forums › Max2Play as Squeezebox (Player / Server) › Max2play setup with two or more servers – how to switch server ? › Reply To: Max2play setup with two or more servers – how to switch server ?
Hi Mario!
Thank you very much for your Help !
I’v managed that tonight!
If it can help someone :
I’ve had to create a shell script that I’ll name runTelnetCommand.sh
#!/bin/bash
if [ $1 == "connect" ]
then
echo "Send to $4:9090 to connect Player $2 on server $3"
printf "$2 connect $3\nexit\n" | nc $4 9090 2>/dev/null | cut "-d " -f 3
echo "Done"
else
echo "Unknown command $1"
fi
I’ve put this script on my openHab volume on path /openhab/userdata/etc/scripts/runTelnetCommand.sh (i’m using a dockerized openhab)
You just have to put this script somewhere openHab can access it.
Check it’s runnable with
chmod +x /openhab/userdata/etc/scripts/runTelnetCommand.sh
On my docker container I’ve had to install nc which is not packaged
Connect manually to the container :
docker exec -it <containerId> /bin/bash
Install netCat to send telnet commands
apt-get update && apt-get install -y netcat
Within my ECMA javascript action for my openHab trigger script I’ve add a exec
var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
var Exec = Java.type("org.openhab.core.model.script.actions.Exec");
var Duration = Java.type("java.time.Duration");
var serverScriptPath = '/openhab/userdata/etc/scripts/runTelnetCommand.sh';
var serverScriptCommand = 'connect';
var mac_room1 = 'aa:bb:cc:dd:ee:ff';
var mac_room2 = 'ff:ee:dd:cc:bb:aa';
var firstServerIp = '192.168.1.15';
var secondServerIp = '192.168.1.16';
logger.info("Result connection room1: " + Exec.executeCommandLine(Duration.ofSeconds(20), serverScriptPath, serverScriptCommand, mac_room1, firstServerIp, secondServerIp));
logger.info("Result connection room2: " + Exec.executeCommandLine(Duration.ofSeconds(20), serverScriptPath, serverScriptCommand, mac_room2, firstServerIp, secondServerIp));
It’s important to send commands to IP’s because DNS names does not seems to work.
Having those function I can switch players mac_room1 and mac_room2 from server 1 to server 2
I hope this will help 😉
- This reply was modified 1 year, 9 months ago by Jack Bauer.