diff --git a/fhem/FHEM/00_MQTT2_CLIENT.pm b/fhem/FHEM/00_MQTT2_CLIENT.pm index 21cc28ae0..00532ce5b 100644 --- a/fhem/FHEM/00_MQTT2_CLIENT.pm +++ b/fhem/FHEM/00_MQTT2_CLIENT.pm @@ -43,6 +43,7 @@ MQTT2_CLIENT_Initialize($) disable:1,0 disabledForIntervals disconnectAfter + httpHeader ignoreRegexp lwt lwtRetain @@ -107,6 +108,10 @@ MQTT2_CLIENT_connect($) $hash->{connecting} = 1 if($disco && !$hash->{connecting}); $hash->{nextOpenDelay} = 5; $hash->{BUF}=""; + if($hash->{DeviceName} =~ m/^wss?:/) { + $hash->{binary} = 1; + $hash->{header}{"Sec-WebSocket-Protocol"} = "mqtt"; + } return DevIo_OpenDev($hash, $disco, "MQTT2_CLIENT_doinit", sub(){}) if($hash->{connecting}); } @@ -314,6 +319,14 @@ MQTT2_CLIENT_Attr(@) } } + if($attrName eq "httpHeader") { + $hash->{header} = {}; + for my $kv (split(" ",$param[0])) { + my ($k, $v) = split(":", $kv, 2); + $hash->{header}{$k} = $v; + } + } + my %h = (clientId=>1,lwt=>1,lwtRetain=>1,subscriptions=>1,SSL=>1,username=>1); if($init_done && $h{$attrName}) { delete($hash->{authError}); @@ -874,6 +887,13 @@ MQTT2_CLIENT_feedTheList($$$) inactivity, and will be automatically reopened when sending a command.
+ +
  • header
    + a list of space separated tuples of key:value, used to set the HTTP + header when MQTT is used over websocket. +

  • + +
  • ignoreRegexp
    if $topic:$message matches ignoreRegexp, then it will be silently ignored. diff --git a/fhem/FHEM/DevIo.pm b/fhem/FHEM/DevIo.pm index d7bc388f1..99f6cfce0 100644 --- a/fhem/FHEM/DevIo.pm +++ b/fhem/FHEM/DevIo.pm @@ -280,8 +280,9 @@ DevIo_SimpleWrite($$$;$) } elsif($hash->{TCPDev}) { if($hash->{WEBSOCKET}) { - $msg = Encode::encode('UTF-8', $msg) if($unicodeEncoding && !$hash->{binary}); - $msg = DevIo_MaskWS($hash->{binary} ? 0x2:0x1, $msg) + $msg = Encode::encode('UTF-8', $msg) + if($unicodeEncoding && !$hash->{binary}); + $msg = DevIo_MaskWS($hash->{binary} ? 0x2:0x1, $msg); } syswrite($hash->{TCPDev}, $msg);