(Gelöst) SUB in HttpUtils_NonblockingGet

Begonnen von tgv_boost, 29 Mai 2020, 21:16:15

Vorheriges Thema - Nächstes Thema

tgv_boost

Hallo Forum,
gebt mir mal bitte einen kleinen Schubs ...
Folgende einfache Funktion versuche ich als callback eines HttpUtils_NonblockingGet zu verwenden.

#99_myUtils.pm

sub
CBF($$$)
{
my ($hash, $err, $data) = @_;
if($err eq "")
            {
Log 1, "AZ Tauf OK";
            } elsif($data ne "")   
          {
  Log 1, "AZ Tauf Error";
  Log 1, $err;
          }
}


Hier das notify dazu
define AZ_T2 notify JalousieAZ_T:.* {\
if (ReadingsVal("JalousieAZ_T","state","off") eq "off") {\
{HttpUtils_NonblockingGet({url=>"http://192.168.0.138:80/Tauf", callback=>\&CBF($$$)})};;\
}\
}


und hier der Logauszug mit der Fehlermeldung can't use string as a SCALAR ref while "strict refs" in use

2020.05.29 20:55:54 1: ERROR evaluating my $SELF='AZ_T2';my $EVTPART0='Auf';my $EVENT='Auf';my $TYPE='dummy';my $NAME='JalousieAZ_T';{
if (ReadingsVal("JalousieAZ_T","state","off") eq "off") {
{HttpUtils_NonblockingGet({url=>"http://192.168.0.138:80/Tauf", callback=>\&CBF($$$)})};
}
}: can't use string as a SCALAR ref while "strict refs" in use at (eval 63827) line 4.


das hier tut seinen Dienst

{HttpUtils_NonblockingGet( { url=>"http://192.168.0.138:80/Tauf", callback=>sub($$$) { my ($hash, $err, $data) = @_;; Log 1, "$data" } }) };;\

allerdings erschließt sich mir hier nicht wie ich $hash, $err, $data für weitere Aktionen nutzen kann und habs deshalb über eine Subroutine versucht.

Mit bestem Dank für Eure Tips im Voraus
Walter

(Gelöst) allerdings am SUB Thema mit 99_myUtils.pm vorbei

define AZF_01 notify JalousieAZ_F:.* {\
if (ReadingsVal("JalousieAZ_F","state","on") eq "on") {\
{ HttpUtils_NonblockingGet( { url=>"http://192.168.0.138:80/?=/Fab", incrementalTimout=>"1", callback=>sub($$$) { my ($hash, $err, $data) = @_;; {if ("$err" eq "") {Log 1, "Fab: ".("$data")}};; {if ("$err" ne "") {Log 1, "Err Fab: ".("$err") ;; {fhem("sleep 60 ;; set JalousieAZ_F on")}} }}} )};;\
}\
}



amenomade

mach die"($$$)" weg
- im notify
- in der sub
Pi 3B, Alexa, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, Debmatic und HM / HmIP Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus

tgv_boost

besten Dank für den Schubs :) gerade im Moment ist es mir auch wie Schuppen von den Augen gefallen. Nächste Herausforderung, Timer (+at) in der 99_myUtils.pm mit ...
sub
CBF_ROT_Fab($$$)
{
my ($hash, $err, $data) = @_;
if($data eq "")   
          {
  Log 1, "Fab: ".("$data")
  }
if($err ne "")   
          {
  { HttpUtils_NonblockingGet( { url=>"http://192.168.0.172:80/?=/Fab", incrementalTimout=>"1", callback=>sub($$$) { my ($hash, $err, $data) = @_;; {if ("$err" ne "") {Log 1, "ERR Fab: ".("$err")} } }} )}
                  }
 
}


amenomade

Verstehe die Frage nicht...
Aber vielleicht war es doch keine Frage?
Pi 3B, Alexa, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, Debmatic und HM / HmIP Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus

tgv_boost

verstehs einfach als Danke, und wenn Du eine Idee hast wie ich eine Verzögerung des Nonblocking umsetzen kann, erspare ich mir vielleicht Syntaxgebastel

amenomade

Ich weiss nicht, was Du genau machen willst, aber das gesamte Konstrukt wird langsam wackelig. Wenn Du NonBlockingGet in einem at packst (ich weiss überhaupt nicht, ob das geht...), dann wird die callback Funktion mit dem Hash des at zurückkommen. Und zwar schon in einer Callback Funktion vom NonBlockingGet im notify?  Wie Du das danach benutzen wirst......?..

Kann man das nicht irgendwie glätten?
Pi 3B, Alexa, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, Debmatic und HM / HmIP Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus

CoolTux

Laut
https://wiki.fhem.de/wiki/HttpUtils#HttpUtils_NonblockingGet

Muss es lauten
MyCallbackFn ( $param, $err, $data )

Also nicht $hash

Du musst also Deinen $param etwas besser zusammen setzen.


my $param = {
                url      => "http://192.168.0.172:80/?=/Fab",
                timeout  => 30,
                hash     => $hash,
                method   => 'GET',
                callback => \&CBF,
            };

HttpUtils_NonblockingGet($param);


Und dann halt Deine CallbackFunktion


sub
CBF {
my ($hash, $err, $data) = @_;
        my $hash      = $param->{hash};
if($err eq "")
            {
Log 1, "AZ Tauf OK";
            } elsif($data ne "")   
          {
  Log 1, "AZ Tauf Error";
  Log 1, $err;
          }
}
Du musst nicht wissen wie es geht! Du musst nur wissen wo es steht, wie es geht.
Support me to buy new test hardware for development: https://www.paypal.com/paypalme/MOldenburg
My FHEM Git: https://git.cooltux.net/FHEM/
Das TuxNet Wiki:
https://www.cooltux.net

tgv_boost

Zitat von: amenomade am 15 Juni 2020, 00:47:07
Ich weiss nicht, was Du genau machen willst, aber das gesamte Konstrukt wird langsam wackelig. Wenn Du NonBlockingGet in einem at packst (ich weiss überhaupt nicht, ob das geht...), dann wird die callback Funktion mit dem Hash des at zurückkommen. Und zwar schon in einer Callback Funktion vom NonBlockingGet im notify?  Wie Du das danach benutzen wirst......?..

Kann man das nicht irgendwie glätten?

was ich machen will klingt eigentlich einfach, eigentlich ...

hiermit ohne SUB in 99_myUtils.pm ...
{ HttpUtils_NonblockingGet( { url=>"http://192.168.0.172:80/?=/Fab", incrementalTimout=>"1", callback=>sub($$$) { my ($hash, $err, $data) = @_;; {if ("$err" eq "") {Log 1, "Fab: ".("$data")} };; {if ("$err" ne "") {Log 1, "Fab: ".("$err")} } }} )};;\
Fab})};;\

steuere ich einen ESP8266, alles gut, bis auf die gelegentlichen WiFi Aussetzer, die ich mittels einer Fehlerroutine auffangen möchte.

Die Idee also, ist diese Alternative:
if (ReadingsVal("JalousieROT","state","on") eq "on") {HttpUtils_NonblockingGet({url=>"http://192.168.0.172:80/Fab", incrementalTimout=>"1", callback=>\&CBF_ROT_Fab})};;\
wobei ich dann in der Subroutine im Fehlerfall (if($err ne "")) das Kommando "http://192.168.0.138:80/?=/Fab" nach einer gewissen Zeit nochmal schicken möchte.


@CoolTux: wo/wie in dem Kontext oben definiere ich das?
my $param = {
                url      => "http://192.168.0.172:80/?=/Fab",
                timeout  => 30,
                hash     => $hash,
                method   => 'GET',
                callback => \&CBF,
            }


Jede Hilfe und Idee ist herzlich willkommen


CoolTux

Das definierst Du in der Funktion in der Du das HttpUtils_NonblockingGet aufrufen willst. Schließlich musst Du das $param ja der Funktion übergeben. Es ist das selbe als wenn Du
HttpUtils_NonblockingGet({url=>"http://192.168.0.172:80/Fab", incrementalTimout=>"1", callback=>\&CBF_ROT_Fab})
auf rufst nur das Du den Hash
{url=>"http://192.168.0.172:80/Fab", incrementalTimout=>"1", callback=>\&CBF_ROT_Fab}
vorher füllst als $param
Du musst nicht wissen wie es geht! Du musst nur wissen wo es steht, wie es geht.
Support me to buy new test hardware for development: https://www.paypal.com/paypalme/MOldenburg
My FHEM Git: https://git.cooltux.net/FHEM/
Das TuxNet Wiki:
https://www.cooltux.net

tgv_boost

Danke für die Tipps ... ich versuchs jetzt mal mit einer sehr klammerhaltigen Lösung

define AZF_01 notify JalousieAZ_F:.* {\
if (ReadingsVal("JalousieAZ_F","state","on") eq "on") {\
{ HttpUtils_NonblockingGet( { url=>"http://192.168.0.138:80/?=/Fab", incrementalTimout=>"1", callback=>sub($$$) { my ($hash, $err, $data) = @_;; {if ("$err" eq "") {Log 1, "Fab: ".("$data")}};; {if ("$err" ne "") {Log 1, "Err Fab: ".("$err") ;; {fhem("sleep 30 ;; set JalousieAZ_F on")}} }}} )};;\
}\
}


Im Fehlerfall ruft Nonblocking den ursprünglichen Trigger für das Notify mit einer Verzögerung (FHEM sleep mit nachfolgenden Befehl sollte OK sein) nochmal auf, und das Spiel geht solange, bis das Ergebnis OK ist. Da wäre sicher noch über ein Maximum an Versuchen nachzudenken. Aber jetzt geb ich erstmal dieser Lösung eine Chance, ausser ihr seht grobe Fehler
Danke nochmal