Hallo HTTPMOD Spezialisten
Ich habe ein Problem mit den Feller Zeptrion Air 2K Wlan Modulen bei Aktionen ausführen.
Die Geräte lassen sich über http ansteuern. Status Abfragen gehen über GET, jedoch Status ändern muss über POST gemacht werden.
Aktion Rolladen hoch/runterlassen muss über
POST http://<zeptrion-air-2k-wlan-module>/zrap/chctrl/
Content-Type: text/plain
cmd1=dim_down
-- response --
302 Found
Server: ZunZun/1.0.3
Content-Length: 0
Connection: keep-alive
Date: Wed, 13 Jul 2016 08:56:39 +0200
getätigt werden.
Wenn ich diese Aktion ausführe, macht der Rolladen die richtige Aktion; jedoch mit dem 302 found folgt ein weiterer Request (durchgeführt durch das httputils), der dann in einem 400er endet.
2016.07.13 09:06:03 5: wohnzimmmer_storen_mitte: set called with aktion down
2016.07.13 09:06:03 5: wohnzimmmer_storen_mitte: set found option aktion in attribute set01Name
2016.07.13 09:06:03 5: wohnzimmmer_storen_mitte: set found down in rmap and converted to dim_down
2016.07.13 09:06:03 4: wohnzimmmer_storen_mitte: set will now set aktion -> dim_down
2016.07.13 09:06:03 5: wohnzimmmer_storen_mitte: AddToQueue called, initial send queue length : 0
2016.07.13 09:06:03 5: wohnzimmmer_storen_mitte: AddToQueue adds type Set01 to URL http://<zeptrion-air-2k-wlan-module>/zrap/chctrl, data cmd1=dim_down, header Accept: */*
2016.07.13 09:06:03 5: wohnzimmmer_storen_mitte: HandleSendQueue called, qlen = 1
2016.07.13 09:06:03 4: wohnzimmmer_storen_mitte: HandleSendQueue sends request type Set01 to URL http://<zeptrion-air-2k-wlan-module>/zrap/chctrl, data cmd1=dim_down, header Accept: */*, timeout 2
2016.07.13 09:06:03 4: HttpUtils url=http://<zeptrion-air-2k-wlan-module>/zrap/chctrl
2016.07.13 09:06:03 4: http://<zeptrion-air-2k-wlan-module>/zrap/chctrl: HTTP response code 302
2016.07.13 09:06:03 1: PERL WARNING: Use of uninitialized value $ra in pattern match (m//) at FHEM/HttpUtils.pm line 471.
2016.07.13 09:06:03 1: PERL WARNING: Use of uninitialized value $ra in concatenation (.) or string at FHEM/HttpUtils.pm line 471.
2016.07.13 09:06:03 4: HttpUtils http://<zeptrion-air-2k-wlan-module>/zrap/chctrl Redirect to http://<zeptrion-air-2k-wlan-module>:80/
2016.07.13 09:06:03 4: HttpUtils url=http://<zeptrion-air-2k-wlan-module>:80/
2016.07.13 09:06:03 4: http://<zeptrion-air-2k-wlan-module>:80& HTTP response code 400
2016.07.13 09:06:03 4: HttpUtils http://<zeptrion-air-2k-wlan-module>:80/ Got data, length: 213
2016.07.13 09:06:03 5: wohnzimmmer_storen_mitte: Read Callback: Request type was Set01,
header: HTTP/1.1 400 Bad Request
Server: ZunZun/1.0.3
Content-Type: text/html
Content-Length: 213
Content-Encoding: gzip
Connection: close
Date: Wed, 13 Jul 2016 09:06:02 +0200,
Was mache ich falsch und/oder was fehlt mir in der Config?
Wie kann ich den 302er abfangen, damit das httputils dann nicht einen weiteren Request macht.
define wohnzimmmer_storen_mitte HTTPMOD none 0
attr wohnzimmmer_storen_mitte userattr devStateIcon icon requestData requestHeader1 set01Data set01Map set01Name set01URL setHeader1 verbose
attr wohnzimmmer_storen_mitte room Wohnzimmer
attr wohnzimmmer_storen_mitte set01Name aktion
attr wohnzimmmer_storen_mitte set01Map dim_down:down, dim_up:up
attr wohnzimmmer_storen_mitte requestHeader1 Content-Type: text/plain
attr wohnzimmmer_storen_mitte setHeader1 Accept: */*
attr wohnzimmmer_storen_mitte set01URL http://<zeptrion-air-2k-wlan-module>/zrap/chctrl
attr wohnzimmmer_storen_mitte set01Data cmd1=$val
attr wohnzimmmer_storen_mitte verbose 5
attr wohnzimmmer_storen_mitte requestData
Vielen Dank für Feedback.
Grüsse Michael
Ich habe nun einen anderen Ansatz verfolgt.
cpan[1]> install REST::Client
99_zeptrion.pm
package main;
use strict;
use warnings;
use POSIX;
use REST::Client;
use MIME::Base64;
sub
zeptrion_Initialize($$)
{
my ($hash) = @_;
}
#post zeptrion air storen/markise channel on/off/dim_up/dim_down/dim_level/recall_sX
#------------------------------------------------------------------------------------
sub za_action_storen($$$$){
my ($mydevice, $myhost, $mychannel, $mycommand) = @_;
# $mycommand = "on:off:dim_up:dim_down:recall_sX";
# on: rauf / off: runter
my $mystatus = 0;
my $mydestination = "http://".$myhost."/zrap/chctrl";
my $myaction= "cmd".$mychannel."=".$mycommand;
my $client = REST::Client->new();
if ($mycommand eq "dim_up") {
$client->POST ($mydestination,"cmd".$mychannel."=dim_up");
#timings 0.5 sec
select(undef, undef, undef, 0.5);
$client->POST ($mydestination,"cmd".$mychannel."=stop");
if ($client->responseCode() == 302) {
my $mystatus+=0;
} else {
my $mystatus +=1;
}
} elsif ($mycommand eq "dim_down") {
$client->POST ($mydestination,"cmd".$mychannel."=dim_down");
#timings 0.5 sec
select(undef, undef, undef, 0.5);
$client->POST ($mydestination,"cmd".$mychannel."=stop");
if ($client->responseCode() == 302) {
my $mystatus+=0;
} else {
my $mystatus +=1;
}
} elsif ($mycommand eq "on" or $mycommand eq "off" or $mycommand eq "stop" or $mycommand eq "recall_s1" or $mycommand eq "recall_s2" or $mycommand eq "recall_s3" or $mycommand eq "recall_s4" ) {
$client->POST ($mydestination,$myaction);
if ($client->responseCode() == 302) {
my $mystatus +=0;
} else {
my $mystatus +=1;
}
} else {
my $mystatus +=1;
}
}
#post zeptrion air licht channel on/off/dim_up/dim_down/dim_level/recall_sX
#------------------------------------------------------------------------------------
sub za_action_licht($$$$){
my ($mydevice, $myhost, $mychannel, $mycommand) = @_;
# $mycommand = "on:off:dim_up:dim_down:recall_sX";
my $mystatus = 0;
my $mydestination = "http://".$myhost."/zrap/chctrl";
my $myaction= "cmd".$mychannel."=".$mycommand;
my $client = REST::Client->new();
if ($mycommand eq "dim_up") {
$client->POST ($mydestination,"cmd".$mychannel."=off");
#timings 1 sec
select(undef, undef, undef, 1.0);
$client->POST ($mydestination,"cmd".$mychannel."=dim_up");
#timings 0.5 sec
select(undef, undef, undef, 0.5);
$client->POST ($mydestination,"cmd".$mychannel."=stop");
if ($client->responseCode() == 302) {
my $mystatus+=0;
} else {
my $mystatus +=1;
}
} elsif ($mycommand eq "dim_down") {
$client->POST ($mydestination,"cmd".$mychannel."=on");
#timings 10 secs
select(undef, undef, undef, 10.0);
$client->POST ($mydestination,"cmd".$mychannel."=dim_down");
#timings 3.5 secs
select(undef, undef, undef, 3.5);
$client->POST ($mydestination,"cmd".$mychannel."=stop");
if ($client->responseCode() == 302) {
my $mystatus+=0;
} else {
my $mystatus +=1;
}
} elsif ($mycommand eq "on" or $mycommand eq "off" or $mycommand eq "stop" or $mycommand eq "recall_s1" or $mycommand eq "recall_s2" or $mycommand eq "recall_s3" or $mycommand eq "recall_s4" ) {
$client->POST ($mydestination,$myaction);
if ($client->responseCode() == 302) {
my $mystatus +=0;
} else {
my $mystatus +=1;
}
} else {
my $mystatus +=1;
}
}
#end of zeptrion_Initialize
1;
in fhem.cfg:
define n_objekt notify objekt {za_action_storen("$NAME","<ip or fqhn>",<channel1 or channel2 or channel3 or channel4>,$EVENT)};;
define n_objekt notify objekt {za_action_licht("$NAME","<ip or fqhn>",<channel1 or channel2 or channel3 or channel4>,$EVENT)};;
define eg_wohnzimmer_storen_front dummy
attr eg_wohnzimmer_storen_front room Wohnzimmer
attr eg_wohnzimmer_storen_front devStateIcon on:fts_shutter_up@black off:fts_shutter_100@green dim_down:fts_shutter_updown@orange dim_up:fts_shutter_updown@orange recall_.*:fts_shutter_automatic@blue
attr eg_wohnzimmer_storen_front eventMap down:off up:on szene1:recall_s1 szene2:recall_s2 szene3:recall_s3 szene4:recall_s4
attr eg_wohnzimmer_storen_front webCmd up:down:dim_down:dim_up:szene1:szene2:szene3:szene4
attr eg_wohnzimmer_storen_front verbose 5
define n_eg_wohnzimmer_storen_front notify eg_wohnzimmer_storen_front {za_action_storen("$NAME","<ip or fqhn>",1,$EVENT)};;
define eg_wohnzimmer_markise dummy
attr eg_wohnzimmer_markise room Terrasse
attr eg_wohnzimmer_markise devStateIcon on:fts_sunblind_0@black off:fts_sunblind_100@green stop:fts_sunblind@yellow recall_.*:fts_sunblind@blue
attr eg_wohnzimmer_markise eventMap down:recall_s1 up:on szene1:recall_s1 szene2:recall_s2 szene3:recall_s3 szene4:recall_s4
attr eg_wohnzimmer_markise webCmd up:down:stop:szene1:szene2:szene3:szene4
attr eg_wohnzimmer_markise verbose 5
define n_eg_wohnzimmer_markise notify eg_wohnzimmer_markise {za_action_storen("$NAME","<ip or fqhn>",1,$EVENT)};;
#dimmbar
define eg_wohnzmmer_licht_sofa_rechts dummy
attr eg_wohnzmmer_licht_sofa_rechts room Wohnzimmer
attr eg_wohnzmmer_licht_sofa_rechts devStateIcon on:FS20.on off:FS20.off dim_down:dimdown@orange dim_up:dimup@orange recall_.*:FS20@blue
attr eg_wohnzmmer_licht_sofa_rechts eventMap on off szene1:recall_s1 szene2:recall_s2 szene3:recall_s3 szene4:recall_s4
attr eg_wohnzmmer_licht_sofa_rechts webCmd on:off:dim_down:dim_up:szene1:szene2:szene3:szene4
attr eg_wohnzmmer_licht_sofa_rechts verbose 5
define n_eg_wohnzmmer_licht_sofa_rechts notify eg_wohnzmmer_licht_sofa_rechts {za_action_licht("$NAME","<ip or fqhn>",2,$EVENT)};;
#on off
define ug_garten_licht dummy
attr ug_garten_licht room Terrasse
attr ug_garten_licht devStateIcon on:FS20.on off:FS20.off recall_.*:FS20@blue
attr ug_garten_licht eventMap on off szene1:recall_s1 szene2:recall_s2 szene3:recall_s3 szene4:recall_s4
attr ug_garten_licht webCmd on:off:szene1:szene2:szene3:szene4
attr ug_garten_licht verbose 5
define n_ug_garten_licht notify ug_garten_licht {za_action_licht("$NAME","<ip or fqhn>",2,$EVENT)};;
Szene stuff
#-----------
define g_Beschattung dummy
attr g_Beschattung room Szenen
attr g_Beschattung devStateIcon off:fts_shutter_10@black on:fts_shutter_automatic@blue
attr g_Beschattung eventMap on off
attr g_Beschattung webCmd on:off
define n_g_Beschattung notify g_Beschattung {\
if ($EVENT ne "off") {\
fhem("set eg_kueche_storen szene1 ;; set eg_esszimmer_storen_links szene1")\
}else {\
fhem("set eg_kueche_storen on ;; set eg_esszimmer_storen_links on")\
}\
}
Grüsse Michael