Paqueuc
Posts: 24
Joined: Fri Jan 25, 2013 11:55 pm

Shut down via a smart home controler via telnet

Sun Aug 04, 2013 9:33 pm

Hello,

Using 5 Rpi as squeezeboxes via Squeezeplug distribution (Debian), I want to shut them down at night (even if they use small power).

I use a smarthome controler (Loxone) that theorically allows me to do it via telnet command (I installed the telnet package on the Rpis to allow connection). The trouble is that I just don't manage to do it. I used a different controler before and had the same trouble. The Rpis just don't shut down.

When I log in with a terminal such as Putty, I perfectly can shut them down with simple command "sudo halt" (after loging in with pi / raspberry).

Can anyone give me a clue of why I manually can do this simple operation with Putty and why when I ask a smarthome program to do this exact same operation it fails ? I verified countless times, the loxone code, the adress, id, pwd...

Do the Rpis have an internal limitation / protection / incompatibility / whatever that makes this simple operation impossible ? On old smarthome controler, It looked like the connection was lost after loging in. At the time I thought it was a bug of the controler but now, I doubt as it is not more succesfull with new controler...

Anyone could have an idea to solve the trouble ? Or another idea (via the GPio or with installation of another package ?) to allow this simple operation please ?

Thanks for your help, I really struggle.

Paqueuc.

itimpi
Posts: 1090
Joined: Sun Sep 25, 2011 11:44 am
Location: Potters Bar, United Kingdom
Contact: Website

Re: Shut down via a smart home controler via telnet

Mon Aug 05, 2013 8:07 am

Exactly what makes you think it is failing?

A point to note is that the Pi can not fully power down (so the red power light goes off) - it can only close the OS and put the Pi into a halt state that needs power on/off to restart. In that mode it is still consuming some power (although slightly less than when fully running). If you want a full power off then you need a device external to the Pi that can switch off the power (ideally after a delay to give the Pi time to stop the OS tidily to avoid SD card corruption).

You may decide that the minimal power saving of setting up what is required for a full power off is not worth the effort?

sprinkmeier
Posts: 410
Joined: Mon Feb 04, 2013 10:48 am
Contact: Website

Re: Shut down via a smart home controler via telnet

Mon Aug 05, 2013 8:24 am

I take it the Loxone is supposed to telnet to the Pi and tell it to shut down.

I assume you've telnet-ed in from another pi and verified that it works handraulically?

try running

Code: Select all

sudo tcpdump -npi any tcp port telnet -w loxone.pcap
on the pi, then get to Loxone to do it's thing.
CNTRL-C the tcpdump and run

Code: Select all

wireshark loxone.pcap
Right-click on one of the packets and Follow TCP stream.

With any luck you'll have a nice dump of the telnet session.

Paqueuc
Posts: 24
Joined: Fri Jan 25, 2013 11:55 pm

Re: Shut down via a smart home controler via telnet

Mon Aug 05, 2013 8:59 am

Hello,

Thanks itimpi for your reply. More than power, another reason to shut the Rpis down is that squeezeplug distribution just can't stand staying on a long time (idle) without being used. If you don't use them for 24h, then they don't answer to request anymore (even if they still appear on squeezebox interface. They're just "away"). You have to reboot them.

What makes me think it is failling is that I still can access the rpis via Putty even after asking to make a shut down via the smarthome interface. In that interface (Loxone), I unfortunately only have the log of what is sent to the Rpis. I don't have the answer from the Rpis. I'm blind here (if you have a clue to allow this vision, I'm interested too). On my previous smarthome interface (OpenRemote) I had a more complete log that showed a certain success because I could enter login and password but immediately after logging in connection was lost. I just could send the "sudo halt" command. At that time I thought of a bug with OpenRemote program. But now, I wonder as I have not more success with new Loxone interface.

Otherwise, I have a home automation system for phisically switching on / off power.

The thing works this way :
1/ I switch the power on with a button (or smarthome interface on any kind of pad) via home automation (KNX protocol and Loxone) => That switches the Rpis on (and the amps, too).
2/ The squeezeboxes are up and running after 45 s. No need to log on to start playing music. It works fine.
3/ When I want to turn the music off, I just click a button (or tablet, again) and there, the Rpis should shut down and after 2 mn the system completely switches the power off.

All the automation part works fine. My only struggle is to shut those Rpis down in a clean manner so I don't get my SDCard corrupted every 5 mn.

I focused on this way to do it but maybe there are other way, easier or more efficient to have the same result. I just don't see them. So if you have any idea, I'm interested.

Thanks,

Paqueuc
Posts: 24
Joined: Fri Jan 25, 2013 11:55 pm

Re: Shut down via a smart home controler via telnet

Mon Aug 05, 2013 9:20 am

Hello Sprinkmeier,

Thanks for your reply.
sprinkmeier wrote:I take it the Loxone is supposed to telnet to the Pi and tell it to shut down.
Yes. Exactly.
sprinkmeier wrote:I assume you've telnet-ed in from another pi and verified that it works handraulically?
No, I didn't. Unfortunately, my knowledge at this level is limited.
sprinkmeier wrote:try running

Code: Select all

sudo tcpdump -npi any tcp port telnet -w loxone.pcap
on the pi,
OK. I'll try. To be sure, not to make a mistake, I translate it my way :
Ip address of the first Rpi : 192.168.1.41 (telnet port : 23)
IP address of the second Rpi : 192.168.1.16 (telnet port : 23)
IP address of the Loxone : 192.168.1.99

On the first pi, I enter the command :

Code: Select all

sudo tcpdump -192.168.1.16:23 -w 192.168.1.99.pcap
Is that correct ?
sprinkmeier wrote:then get to Loxone to do it's thing.
CNTRL-C the tcpdump
The result of what I got on the first Pi ? One or two lines, I imagine...
sprinkmeier wrote: and run

Code: Select all

wireshark loxone.pcap
Translated, is it this way ?

Code: Select all

wireshark 192.168.1.99.pcap
I just don't get what is "loxone.pcap" in your explanation. I mean, how the system knows what is Loxone. It only is an Ip address, not the name of the machine on the network. If I "ping Loxone" I will have no result. I don't know if I could set-it up a name... I have to check. If you can just clarify this point, please...
sprinkmeier wrote:Right-click on one of the packets and Follow TCP stream.

With any luck you'll have a nice dump of the telnet session.
Hopefully I'll see something in the log interface. But Loxone uses a proprietary software to program its tool and the log system is included in this soft. The OS of the Loxone (LoxOS) is even not built on a Linux base. So my check possibilities might be limited even by some kind of Putty interface (though I didn't try yet)... But I'll let you know.

Thanks,

sprinkmeier
Posts: 410
Joined: Mon Feb 04, 2013 10:48 am
Contact: Website

Re: Shut down via a smart home controler via telnet

Mon Aug 05, 2013 9:31 am

Paqueuc wrote:
sprinkmeier wrote:I assume you've telnet-ed in from another pi and verified that it works handraulically?
No, I didn't. Unfortunately, my knowledge at this level is limited.
just run telnet 192.168.1.41 on another computer/pi and check that you can log on using the credentials you supplied to the Loxone.
then run the shutdown command to check that it works.
sprinkmeier wrote:try running

Code: Select all

sudo tcpdump -npi any tcp port telnet -w loxone.pcap
on the pi,
OK. I'll try. To be sure, not to make a mistake, I translate it my way :
Ip address of the first Rpi : 192.168.1.41 (telnet port : 23)
IP address of the second Rpi : 192.168.1.16 (telnet port : 23)
IP address of the Loxone : 192.168.1.99
not quite...
-npi any are parameters, (numeric, non-promiscuous, use interface "any", i.e. all of them)
tcp port telnet tells it to snoop on the TCP/IP port used by telnet
-w loxon.pcap tells it the name of the file to write to

Paqueuc
Posts: 24
Joined: Fri Jan 25, 2013 11:55 pm

Re: Shut down via a smart home controler via telnet

Mon Aug 05, 2013 9:41 am

sprinkmeier wrote:
Paqueuc wrote:
sprinkmeier wrote:I assume you've telnet-ed in from another pi and verified that it works handraulically?
No, I didn't. Unfortunately, my knowledge at this level is limited.
just run telnet 192.168.1.41 on another computer/pi and check that you can log on using the credentials you supplied to the Loxone.
then run the shutdown command to check that it works.
OK. I will from one Pi to another using the telnet command. Currently, from a PC with Putty to whatever Pi, it works. I obviously provide the same credentials to the Loxone.
sprinkmeier wrote:try running

Code: Select all

sudo tcpdump -npi any tcp port telnet -w loxone.pcap
on the pi,
OK. I'll try. To be sure, not to make a mistake, I translate it my way :
Ip address of the first Rpi : 192.168.1.41 (telnet port : 23)
IP address of the second Rpi : 192.168.1.16 (telnet port : 23)
IP address of the Loxone : 192.168.1.99
not quite...
-npi any are parameters, (numeric, non-promiscuous, use interface "any", i.e. all of them)
tcp port telnet tells it to snoop on the TCP/IP port used by telnet
-w loxon.pcap tells it the name of the file to write to[/quote]

:D
Sorry. I'm quite bad when it goes further than quite basic command lines...

Thanks and I let you know.

Paqueuc
Posts: 24
Joined: Fri Jan 25, 2013 11:55 pm

Re: Shut down via a smart home controler via telnet

Tue Aug 06, 2013 10:24 am

Hello,

So I have some results. I post some printscreens and the loxone.pcap file (in a zip file loxone.zip) for complete analysis. More printscreeen are available, if needed.

I made different tests and it looks like there is a communication. Unfortunately, I'm not able to analyse it. But at the end no result.

Do you see something to be corrected ?

Thanks for your help.
Attachments
Loxone-wireshark-3B.JPG
Loxone-wireshark-3B.JPG (49.08 KiB) Viewed 4243 times
Loxone-wireshark-1B.JPG
Loxone-wireshark-1B.JPG (59.22 KiB) Viewed 4243 times
loxone.zip
(7.46 KiB) Downloaded 99 times

User avatar
RaTTuS
Posts: 10514
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Shut down via a smart home controler via telnet

Tue Aug 06, 2013 10:42 am

it does not look like it's conencted
telnet in again from a PC
then
ls -l
does that produce an output as expected ?
...


personally I'd use ssh for connections but not sure about your phone
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

sprinkmeier
Posts: 410
Joined: Mon Feb 04, 2013 10:48 am
Contact: Website

Re: Shut down via a smart home controler via telnet

Tue Aug 06, 2013 12:20 pm

Assuming you're not worried about security just add something like this:

Code: Select all

nc -l -p 23 ; /sbin/poweroff &
to /etc/rc.local

Any attempt to telnet to the Pi should shut it down :-)

Paqueuc
Posts: 24
Joined: Fri Jan 25, 2013 11:55 pm

Re: Shut down via a smart home controler via telnet

Tue Aug 06, 2013 1:44 pm

Hello,

Thanks both of you. I'll test the 2 options and let you know.
sprinkmeier wrote:Assuming you're not worried about security just add something like this:

Code: Select all

nc -l -p 23 ; /sbin/poweroff &
to /etc/rc.local

Any attempt to telnet to the Pi should shut it down :-)
Not worried about security effectively. But the squeezeboxes are managed by phone application (iPeng or Logitech squeezebox) or http requests (and I wonder if there isn't a bit of telnet, possibly. I have to check). Will it still be compatible with this probably efficient solution but maybe a bit radical :) ? Anyway I'll test and let you know.

Thanks,

Paqueuc
Posts: 24
Joined: Fri Jan 25, 2013 11:55 pm

Re: Shut down via a smart home controler via telnet

Tue Aug 06, 2013 8:23 pm

RaTTuS wrote:it does not look like it's conencted
telnet in again from a PC
then
ls -l
does that produce an output as expected ?
...

Here is the print screen of this test. Does it tell you anything ?
RaTTuS wrote:personally I'd use ssh for connections but not sure about your phone
If I could, I would. But the soft I use is proprietarry and only includes telnet protocol. No SSH, unfortunately.

Thanks for your analysis.
Attachments
Rpi-1.JPG
Rpi-1.JPG (35.52 KiB) Viewed 4184 times

Paqueuc
Posts: 24
Joined: Fri Jan 25, 2013 11:55 pm

Re: Shut down via a smart home controler via telnet

Tue Aug 06, 2013 8:32 pm

Hello,

Unfortunately, no result with :

Code: Select all

     nc -l -p 23 ; /sbin/poweroff & 
Here is the printscreen enclosed. I can telnet the Pi via putty or loxone, it doesn't shutdown. Did I do it well ?

I enclose a few more tests with tcpdump and wireshark, just in case.

Thanks for more ideas, if possible.
Attachments
Loxone2.zip
(4.21 KiB) Downloaded 83 times
Rpi-2.JPG
Rpi-2.JPG (51.46 KiB) Viewed 4180 times

sprinkmeier
Posts: 410
Joined: Mon Feb 04, 2013 10:48 am
Contact: Website

Re: Shut down via a smart home controler via telnet

Tue Aug 06, 2013 8:49 pm

did you reboot to allow rc.local to run?
failing that, just run the command from a root shell for testing.

Paqueuc
Posts: 24
Joined: Fri Jan 25, 2013 11:55 pm

Re: Shut down via a smart home controler via telnet

Tue Aug 06, 2013 9:06 pm

Unfortunately, I did. Several times... :cry:

I still can access the pi with putty (telnet, no SSH) and it doesn't shut down.

Sorry for resisting this hard.

sprinkmeier
Posts: 410
Joined: Mon Feb 04, 2013 10:48 am
Contact: Website

Re: Shut down via a smart home controler via telnet

Tue Aug 06, 2013 10:22 pm

add the full path to the commands.
ssh in and run

Code: Select all

$ which nc poweroff
/bin/nc
/sbin/poweroff
$ sudo -i
# /bin/nc -l -p 23 ; /sbin/poweroff
then try the loxon telnet thing and see what happens

Paqueuc
Posts: 24
Joined: Fri Jan 25, 2013 11:55 pm

Re: Shut down via a smart home controler via telnet

Wed Aug 07, 2013 7:21 pm

Hello Sprinkmeyer,

Here is the printscreen of what I did. Is it correct ? I did a reboot and unfortunately, no result.

Thanks for your answer.
Attachments
Rpi-3.JPG
Rpi-3.JPG (61.72 KiB) Viewed 4102 times

sprinkmeier
Posts: 410
Joined: Mon Feb 04, 2013 10:48 am
Contact: Website

Re: Shut down via a smart home controler via telnet

Wed Aug 07, 2013 10:12 pm

Not quite what I had in mind...

I was suggesting you run the which ... command from a terminal logged on as pi
non-superuser prompts usually include a $, so

Code: Select all

$ someCommand
is short-cut for
"run someCommand on a terminal as non-root user"
the sudo -i command elevates you to root, where the prompt usually includes a #
run
/bin/nc -l -p 23 ; /sbin/poweroff
from a root session (make sure the paths match those 'which' provided) and try the telnet thing.

once that works, put that command in rc.local _AFTER_ the mount -a and followed by a &
the & allows the rest of the rc.local to finish by puting your command in the background.

screenshots are OK, but can just cut-and-paste the text (inside a code block). smaller and more useful.

User avatar
RaTTuS
Posts: 10514
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Shut down via a smart home controler via telnet

Thu Aug 08, 2013 7:49 am

Paqueuc wrote:
RaTTuS wrote:it does not look like it's conencted
telnet in again from a PC
then
ls -l
does that produce an output as expected ?
...

Here is the print screen of this test. Does it tell you anything ?

.....
yes it show me you are not logged into the raspberry pi
you are wanting to telent into the RPI and shut it down
then you should telnet into the rpi and shut it down not the squeesze box
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

Paqueuc
Posts: 24
Joined: Fri Jan 25, 2013 11:55 pm

Re: Shut down via a smart home controler via telnet

Thu Aug 08, 2013 8:05 am

Hello Sprinkmeyer,

Thanks, there is a great progress. Logged as an admin in SSH via putty, The pi respond to the command :

Code: Select all

/bin/nc -l -p 23 ; /sbin/poweroff
But too quickly as it immediately answers : nc: Address already in use
and then shuts down. It doesn't wait for the telnet thing.

I understood to come back to this simple code line in the /etc/rc.local file such as :

Code: Select all

mount -a

/bin/nc -l -p 23 ; /sbin/poweroff &

exit 0
Is that correct ?

Thanks Sprinkmeyer

Paqueuc
Posts: 24
Joined: Fri Jan 25, 2013 11:55 pm

Re: Shut down via a smart home controler via telnet

Thu Aug 08, 2013 8:21 am

RaTTuS wrote:yes it show me you are not logged into the raspberry pi
you are wanting to telent into the RPI and shut it down
then you should telnet into the rpi and shut it down not the squeesze box
I'm not sure to understand. The IP address is the one of the Pi. Sure, it also is the one of the squeezebox but before installing the squeezebox I made a few settings on this precise IP adress and I was talking to the Pi, not to the squeezebox. We do agree on the fact that I want to shut the pi down, not the squeezebox. The squeezebox can be telneted but for very restricted functions such as play / pause / volume up... But as it comes to the network related part (title song, to which squeezebox send the data, favourites...) we communicate with it by http requests (and all telnet part could be managed by http request).

Thanks RaTTuS

sprinkmeier
Posts: 410
Joined: Mon Feb 04, 2013 10:48 am
Contact: Website

Re: Shut down via a smart home controler via telnet

Thu Aug 08, 2013 10:16 am

Paqueuc wrote:But too quickly as it immediately answers : nc: Address already in use
and then shuts down. It doesn't wait for the telnet thing.
Is that correct ?

Thanks Sprinkmeier
remove the lines from rc.local that start nc.

Paqueuc
Posts: 24
Joined: Fri Jan 25, 2013 11:55 pm

Re: Shut down via a smart home controler via telnet

Thu Aug 08, 2013 12:36 pm

So I assume my rc.local looks like this :

Code: Select all

mount -a

/sbin/poweroff &

exit 0
It works "too well". The Pi starts and after 2 or 3 mn, comes back to halt mode (deducted by the led). I can't reach it anymore in any manner (I didn't put a screen to see what was happening but I will, if needed). I stopped the Logitech Squeezebox server (on a Synology NAS) so it doesn't send any request to the Pi but this isn't better.

Is there a way to simply bypass the id / pwd of the telnet process to simply send the "sudo halt" command (or whatever else indeed) ? I'm not worried about security aspect, there is nothing on those Pis except squeezebox software.

User avatar
RaTTuS
Posts: 10514
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Shut down via a smart home controler via telnet

Thu Aug 08, 2013 12:41 pm

Paqueuc wrote:So I assume my rc.local looks like this :

Code: Select all

mount -a

/sbin/poweroff &

exit 0
It works "too well". The Pi starts and after 2 or 3 mn, comes back to halt mode (deducted by the led). I can't reach it anymore in any manner (I didn't put a screen to see what was happening but I will, if needed). I stopped the Logitech Squeezebox server (on a Synology NAS) so it doesn't send any request to the Pi but this isn't better.

Is there a way to simply bypass the id / pwd of the telnet process to simply send the "sudo halt" command (or whatever else indeed) ? I'm not worried about security aspect, there is nothing on those Pis except squeezebox software.
yeah you dont want that as
soon as the RPI boots up it will power down via that command
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

User avatar
RaTTuS
Posts: 10514
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Shut down via a smart home controler via telnet

Thu Aug 08, 2013 12:45 pm

also re-reading of the thread ...

if you can telnet into the box
and then you should be able to do
sudo /sbin/poweroff
now this requires you to do the password thing unless your account has that disabled
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

Return to “General discussion”