GetFileFromURL mit Benutzeranmeldung

Begonnen von Dragonfly, 10 April 2013, 18:16:34

Vorheriges Thema - Nächstes Thema

Dragonfly

Folgender Code:
define Squeezebox_ntfy notify (Squeezebox:.*) {\
    my $v=Value("Squeezebox");;\
    my $server="http://usr:pwd@192.168.1.60:9002";;\
    my $player="&player=00:04:20:2B:5B:4E";;\
    GetFileFromURL "" . $server . "/status.html?p0=play" . $player . "" if ($v eq "on");;\
  }


Leider funktionierts nicht wegen dem @ in der Url (auch nicht mit 2) - weiß jemand wie man das umgehen kann?

Danke schonmal.

Rohan

Hallo Drachenfliege,

Zitat von: Dragonfly schrieb am Mi, 10 April 2013 18:16
    GetFileFromURL "" . $server . "/status.html?p0=play" . $player . "" if ($v eq "on");;\
  }


Warum setzt du das "if ($v..." ans Ende? Normalerweise sagt man doch: wenn, dann ...

also


if (...) {
  mache folgendes
}


Kann das der Grund sein?

Gruß
Thomas
Fhem auf Mini-ITX mit Celeron 2-Core, HMLAN (> 55 Devices), CUL (FS20 und EM), RFXtrx 433E, Arduino (einige DS18B20), RPi mit 1-Wire (DS2423 für S0-Signale, DS18B20+), RPi/Arduino mit MQ-5 und MQ-9 (CO- und CNG/LPG-Sensor), CO-20 IAQ Sensor

Dragonfly

Nö, das @ wird von FHEM nach "Squeezebox" übersetzt - das ist das Problem.
Ausgeführt wird richtig.

Trotzdem Danke...

Rohan

Schreib doch mal

my $server="http://usr:pwd".'@192.168.1.60:9002'

statt

my $server="http://usr:pwd@192.168.1.60:9002"

dann sollte (ungetestet) keine Ersetzung erfolgen (wobei ich davon ausgehe, dass "usr" und "pwd" nur Platzhalter für Variablen sind).

Gruß
Thomas
Fhem auf Mini-ITX mit Celeron 2-Core, HMLAN (> 55 Devices), CUL (FS20 und EM), RFXtrx 433E, Arduino (einige DS18B20), RPi mit 1-Wire (DS2423 für S0-Signale, DS18B20+), RPi/Arduino mit MQ-5 und MQ-9 (CO- und CNG/LPG-Sensor), CO-20 IAQ Sensor

Dragonfly

:-( leider nix...

"usr" und "pwd" sind Klartext.

Vielleicht fällt dir ja noch etwas ein?!

Rohan

Zitat von: Dragonfly schrieb am Do, 11 April 2013 08:29:-( leider nix...

wenig hilfreich. Man kann sich das dann auch ausgeben lassen, notfalls per log-Befehl.

ZitatVielleicht fällt dir ja noch etwas ein?!

Ja, wenn ich hier ein Test-(Fhem-)System vor mit hätte.

Gruß
Thomas
Fhem auf Mini-ITX mit Celeron 2-Core, HMLAN (> 55 Devices), CUL (FS20 und EM), RFXtrx 433E, Arduino (einige DS18B20), RPi mit 1-Wire (DS2423 für S0-Signale, DS18B20+), RPi/Arduino mit MQ-5 und MQ-9 (CO- und CNG/LPG-Sensor), CO-20 IAQ Sensor

Dragonfly

Naja, im Log steht nicht viel - @ wird immer übersetzt - mit deiner Version und "abgeänderter" Varianten von dieser ("syntax error" oder "malformed or unsupported URL").
Der einzige unterschied war bei @@ - da kam das raus:
http://usr:pwd.168.1.60:9002 anstatt von http://usr:pwdSqueezebox192.168.1.60:9002

LG Tom

Rohan

Versuch mal bitte

my $server="http://usr:pwd\@192.168.1.60:9002"

also mit Backslash vor dem "@".

Gruß
Thomas
Fhem auf Mini-ITX mit Celeron 2-Core, HMLAN (> 55 Devices), CUL (FS20 und EM), RFXtrx 433E, Arduino (einige DS18B20), RPi mit 1-Wire (DS2423 für S0-Signale, DS18B20+), RPi/Arduino mit MQ-5 und MQ-9 (CO- und CNG/LPG-Sensor), CO-20 IAQ Sensor

TeeVau

Hilft dir nicht die Änderung bezüglich @ und % zu $EVENT bzw. $NAME?
Guck mal in die commandref zu notify

Zitatin the command section you can access the event:
The variable $EVENT will contain the complete event, e.g. measured-temp: 21.7 (Celsius)
$EVTPART0,$EVTPART1,$EVTPART2,etc contain the space separated event parts (e.g. $EVTPART0="measured-temp:", $EVTPART1="21.7", $EVTPART2="(Celsius)". This data is available as a local variable in perl, as environment variable for shell scripts, and will be textually replaced for FHEM commands.
$NAME contains the device triggering the event, e.g. myFht
FHEM 5.8 dev (virtualisiert) / FBF 7390 (CUL 868MHz V 1.51 / panStick (AVR1))
FS20: fs20di,fs20pira,fs20sm8,fs20st2,fs20tfk,fs20ue1,fs20ws1
panStamp (AVR1): RGB Multi von ext23, 1W-DSxxxx, I/O Sketch, Spritzpumpe
Multimedia: Panasonic TV (VIERA), Kodi, Yamaha RX-V781, LMS
Sonstiges: XiaomiFlowerSen

Dragonfly

\@ bringt das gleiche wie @ alleine.

$server in $NAME zu ändern (my $NAME="http://usr:pwd@192.168.1.60:9002") hatte den selben Effekt wie @@ -> Ergebnis: http://usr:pwd.168.1.60:9002 also "@192" wird bei beiden Varianten entfernt.
Genauer einlesen kann ich mich da erst später...
... morgen kommt der Verputzer und ich darf noch vorbereiten :)

Danke nochmals für die Unterstützung.

Dragonfly

Naja, in der commandref steht:
ZitatTo use % or @ in the text itself, use the double mode (%% or @@).
beim E-Mail funktionierts ja auch einwandfrei?!

Rohan

Fuktioniert denn:

define Squeezebox_ntfy notify (Squeezebox:.*) {\
    my $v=Value("Squeezebox");;\
    my $player="&player=00:04:20:2B:5B:4E";;\
    GetFileFromURL "" . 'http://usr:pwd@192.168.1.60:9002' . "/status.html?p0=play" . $player . "" if ($v eq "on");;\
  }


oder

define Squeezebox_ntfy notify (Squeezebox:.*) {\
    my $v=Value("Squeezebox");;\
    my $player="&player=00:04:20:2B:5B:4E";;\
    GetFileFromURL "" . "http://usr:pwd@@192.168.1.60:9002" . "/status.html?p0=play" . $player . "" if ($v eq "on");;\
  }


Ansonsten bliebe noch die Auslagerung in eine sub in 99_myUtils, da hat dann Fhem weniger "Einfluss" auf den Code. So wie in deinem define ist es zwar auch Perl-Code, der aber von Fhem vorgefiltert an Perl übergeben/durchgereicht wird.

Ich warte immer noch auf einen Perl-Meister, der irgendwann ein Erbarmen mit uns Novizen hat ;)

Edith ergänzt dazu:


my $foo = "Foo";
my $bar = "Bar";
my $str = $foo.$bar;

print $str;
print "\n";
 
=> Ergibt: FooBar

my $foo = "Fo\@o";
my $bar = "Bar";
my $str = $foo.$bar;

print $str;
print "\n";
 
=> Ergibt: Fo@oBar

my $foo = "Fo@o";
my $bar = "Bar";
my $str = $foo.$bar;

print $str;
print "\n";
 
=> Ergibt: FoBar

my $foo = 'Fo@o';
my $bar = "Bar";
my $str = $foo.$bar;

print $str;
print "\n";
 
=> Ergibt: Fo@oBar


Gruß
Thomas
Fhem auf Mini-ITX mit Celeron 2-Core, HMLAN (> 55 Devices), CUL (FS20 und EM), RFXtrx 433E, Arduino (einige DS18B20), RPi mit 1-Wire (DS2423 für S0-Signale, DS18B20+), RPi/Arduino mit MQ-5 und MQ-9 (CO- und CNG/LPG-Sensor), CO-20 IAQ Sensor

Dragonfly

bei der 1. Variante wird überstzt, bei der 2. abgeschnitten.


my $foo = 'Fo@o';
my $bar = "Bar";
my $str = $foo.$bar;

print $str;
print "\n";
 
=> Ergibt: Fo@oBar

sollte ja dann so sein:
define Squeezebox_ntfy notify (Squeezebox:.*) {\
    my $v=Value("Squeezebox");;\
    my $server='http://usr:pwd@192.168.1.60:9002';;\
    my $player="&player=00:04:20:2B:5B:4E";;\
    if ($v eq "on") {GetFileFromURL "" . $server . "/status.html?p0=play" . $player . ""};;\
    }

Was schon wieder eine Übersetzung bewirkt.

Wobei
define Squeezebox_ntfy notify (Squeezebox:.*) {\
    my $v=Value("Squeezebox");;\
    my $server='http://usr:pwd@192.168.1.60:9002';;\
    my $player="&player=00:04:20:2B:5B:4E";;\
    if ($v eq "on") {GetFileFromURL "' . $server . '/status.html?p0=play" . $player . ""};;\
    }

die Url verhaut.

Da hilft nur eins - Ruuudi !
Das kann ich recht gut - mein Mechaniker und sogar der Tischler von mir heißen so - und die wissen immer Rat!

;)

TeeVau

Zitat von: Dragonfly schrieb am Do, 11 April 2013 10:41Naja, in der commandref steht:
ZitatTo use % or @ in the text itself, use the double mode (%% or @@).
beim E-Mail funktionierts ja auch einwandfrei?!


Das mag ja sein, dass das drin steht. Hilft aber augenscheinlich nicht. Und ich denke mal, du möchtest fertig werden, oder? :-)

In der commandref steht auch:
ZitatNote: the following is deprecated and will be removed in a future release. The described replacement is attempted if none of the above variables ($NAME/$EVENT/etc) found in the command.
@ und % wird, irgendwann mal, abgeschafft. Mit $EVENT und $NAME wärst du also etwas Zukunftssicherer. Die Entscheidung bleibt natürlich bei dir.
FHEM 5.8 dev (virtualisiert) / FBF 7390 (CUL 868MHz V 1.51 / panStick (AVR1))
FS20: fs20di,fs20pira,fs20sm8,fs20st2,fs20tfk,fs20ue1,fs20ws1
panStamp (AVR1): RGB Multi von ext23, 1W-DSxxxx, I/O Sketch, Spritzpumpe
Multimedia: Panasonic TV (VIERA), Kodi, Yamaha RX-V781, LMS
Sonstiges: XiaomiFlowerSen

Rohan

Aber $Event & Co. bringt ihn doch nicht weiter, weil er doch genau das "@"-Zeichen braucht für eine gültige URL.

Gruß
Thomas
Fhem auf Mini-ITX mit Celeron 2-Core, HMLAN (> 55 Devices), CUL (FS20 und EM), RFXtrx 433E, Arduino (einige DS18B20), RPi mit 1-Wire (DS2423 für S0-Signale, DS18B20+), RPi/Arduino mit MQ-5 und MQ-9 (CO- und CNG/LPG-Sensor), CO-20 IAQ Sensor