TP-Link Power over Ethernet Switch fernsteuern

Begonnen von Uhrheber, 22 September 2016, 19:43:52

Vorheriges Thema - Nächstes Thema

fl_Indigo


Wernieman

Zeig mal Dein Script ... ist mir momentan rätselhaft
- Bitte um Input für Output
- When there is a Shell, there is a Way
- Wann war Dein letztes Backup?

Wie man Fragen stellt: https://tty1.net/smart-questions_de.html

fl_Indigo


root@fhem:/opt/fhem# sudo su - fhem
fhem@fhem:~$ cd /opt/fhem
fhem@fhem:~$ ./poe.sh
spawn telnet 10.0.0.248
Trying 10.0.0.248...
Connected to 10.0.0.248.
Escape character is '^]'.

***************** User Access Login ********************

User:****
Password:


TL-SG2210P>enable

TL-SG2210P#configure

TL-SG2210P(config)#interface gigabitEthernet 1/0/2

TL-SG2210P(config-if)#power inline supply enable

TL-SG2210P(config-if)#exit

TL-SG2210P(config)##2018-04-18 14:43:32,[User]/3/Login the CLI by root on vty0 (10.0.0.201).
#2018-04-18 14:43:32,[PoE]/3/Power supply status of gigabitEthernet 1/0/2 changes from off to on.
#2018-04-18 14:43:42,[Link]/3/gigabitEthernet 1/0/2 changed state to up.
10.0.0.248
****
****
2
enable


das sh script

/usr/bin/expect /opt/fhem/poe_set.exp 10.0.0.248 **** **** 2 enable


das expect script

#!/usr/bin/expect -f

set host [lindex $argv 0]
set user [lindex $argv 1]
set pass [lindex $argv 2]
set port [lindex $argv 3]
set status [lindex $argv 4]

#if { $host == "" || $user == "" || $pass == "" || $port == "" || $status == "" }  {
#  puts "Usage: <host> <user> <password> <switchport> <POE enable/disable>\n"
#  exit 1
#}

spawn telnet $host
expect "User:"
send "$user\r"
expect "Password:"
send "$pass\r"

send "enable\r"
send "configure\r"
send "interface gigabitEthernet 1/0/$port\r"
send "power inline supply $status\r"

# Exit the telnet session, and wait for a special end-of-file character.
send "exit\r"
expect eof

puts "$host"
puts "$user"
puts "$pass"
puts "$port"
puts "$status"

Wernieman

Ich hatte Dir vorgeschlagen, mal das "/usr/bin/expect /opt/fhem/poe_set.exp 10.0.0.248 **** **** 2 enable" in ein eigenes Script zu pachen

ala (nur ein Ungetesteter Schnellschuß)
#!/bin/bash
IP=$1
PORT=$2
WIE=$3

echo "$IP $PORT $WIE"
/usr/bin/expect /opt/fhem/poe_set.exp $IP **** **** $PORT $WIE


Ich habe mit Absicht User/Passwort hier nicht per Parameter übergeben. Sollte doch eigentlich statisch sein?

Und dann in FHEM audrufen mit
"./paf/zum/tollen/scirpt/script.sh 10.0.0.248 2 enable"

Ist zwar dann erstmal ein schritt mehr als vorher, dafür kannst Du besser testen...
- Bitte um Input für Output
- When there is a Shell, there is a Way
- Wann war Dein letztes Backup?

Wie man Fragen stellt: https://tty1.net/smart-questions_de.html

fl_Indigo

hat nix geändert:

10.0.0.248 2 enable
spawn telnet 10.0.0.248
Trying 10.0.0.248...
Connected to 10.0.0.248.
Escape character is '^]'.

***************** User Access Login ********************

User:$$                                                                                                    $                                                                                                    $
Password:

Press any key to continue (Q to quit)
                                     
Login invalid.
Press any key to continue (Q to quit)
                                     
Press any key to continue (Q to quit)
                                     
***************** User Access Login ********************
Press any key to continue (Q to quit)
                                     

Press any key to continue (Q to quit)
                                     
User:$
Password:

Press any key to continue (Q to quit)
                                     
Login invalid.
Press any key to continue (Q to quit)
                                     
Press any key to continue (Q to quit)
                                     
***************** User Access Login ********************
Press any key to continue (Q to quit)
                                     

Press any key to continue (Q to quit)
                                     
User:$$                                                                                                    $                                                                                                    $                                                                                                    $                                                                                                    $                                                                                                    $                                                                                                    $                                                                                                    $                                                                                                    $                                                                                                    $                                                                                                    $                                                                                                    $                                                                                                    $                                                                                                    $                                                                                                    $                                                                                                    $                                                                                                    $                                                                                                    $                                                                                                    $                                                                                                    $                                                                                                    $                                                                                                    $                                                                                                    $                                                                                                    $                                                                                                    $

Press any key to continue (Q to quit)
                                     
Login invalid.
Press any key to continue (Q to quit)
                                     
Connection closed by foreign host.
2018.04.19 06:54:32 3: n_PoE_Port_2_on return value: -1


mich würds brennend interessieren wie der threadersteller das damals scheinbar erfolgreich implementiert hat...

Wernieman

Mit was für einem Editor hast Du es bearbeitet??

Da  Script funktioniert aus der Konsole, aber nicht aus FHEM??
- Bitte um Input für Output
- When there is a Shell, there is a Way
- Wann war Dein letztes Backup?

Wie man Fragen stellt: https://tty1.net/smart-questions_de.html

fl_Indigo

scripte mit nano erstellt und ausführbar gemacht, laufen unter allen benutzern einwandfrei in der console durch...

Wernieman

Komisch .. kann ich mir nicht erklären ...

Kannst DU mal mit den "Lang" Einstellungen rumspielen?
Bzw. Dir ausgeben?
- Bitte um Input für Output
- When there is a Shell, there is a Way
- Wann war Dein letztes Backup?

Wie man Fragen stellt: https://tty1.net/smart-questions_de.html

fl_Indigo


Wernieman

Sorry, dachte Du hast schon in der Richtugn gearbeitet ...
http://linuxwiki.de/locale

also einfach mal reinsetzen:
LC_ALL=de_DE.UTF-8
LANG=de_DE.UTF-8


Bzw vorher einfach mal ausgeben lassen:
echo $LC_ALL
echo $LANG


Dann eventuell mal mit dem Parameter de_DE.UTF-8 spielen...

Edit:
Die auf dem System verfügbaren anzeigen:
locale -a
- Bitte um Input für Output
- When there is a Shell, there is a Way
- Wann war Dein letztes Backup?

Wie man Fragen stellt: https://tty1.net/smart-questions_de.html

fl_Indigo

alle möglichen de und en varianten durchprobiert, es verändert sich nix... ich gebs auf...

Wernieman

da ich hier so einen switch nicht habe, kann ich Dir leider nicht weiterhelfen ....
- Bitte um Input für Output
- When there is a Shell, there is a Way
- Wann war Dein letztes Backup?

Wie man Fragen stellt: https://tty1.net/smart-questions_de.html

fl_Indigo

danke trotzdem für deine inputs! :thumbsup:

Wernieman

Was mich wundert, das es auf der Konsole geht, aber beim Aufruf durch FHEM nicht.
- Bitte um Input für Output
- When there is a Shell, there is a Way
- Wann war Dein letztes Backup?

Wie man Fragen stellt: https://tty1.net/smart-questions_de.html

fl_Indigo

habs jetzt in perl gelöst

folgende routine in die myutils

sub poeswitch {
my ($port, $status) = @_;

use Net::Telnet;
my $remote;
$remote = new Net::Telnet (Timeout => 10,
                     Errmode => 'die');

$remote->open("10.0.0.248");
$remote->waitfor('/User:/');
$remote->print("user") ;
$remote->waitfor('/Password:/');
$remote->print("password") ;

$remote->waitfor('/TL-SG2210P/');
$remote->print("\n");
$remote->print("enable\n");
$remote->waitfor('/TL-SG2210P/');
$remote->print("configure\n");
$remote->waitfor('/TL-SG2210P/');
$remote->print("interface gigabitEthernet 1/0/$port\n");
$remote->waitfor('/TL-SG2210P/');
$remote->print("power inline supply $status\n");
$remote->waitfor('/TL-SG2210P/');
}

eventuell muss auf dem ausführenden system NET::Telnet via cpan oder libnet-telnet-perl via packagemanager nachinstalliert werden

danach klappt der aufruf von

define n_PoE_Port_2_on notify PoE_Port_2_Switch:on {poeswitch("2","enable")};;
define n_PoE_Port_2_off notify PoE_Port_2_Switch:off {poeswitch("2","disable")};;

und der switch schaltet den angegebenen port

vielleicht hilfts ja nochmal jemandem :)