From eed0b1fed631c4e0602a0434f7740fe7d8dd986a Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Sun, 20 Jan 2019 10:12:04 +0000 Subject: [PATCH] 00_MQTT2_SERVER.pm: add the rePublish attribute (Forum #95341) git-svn-id: https://svn.fhem.de/fhem/trunk@18349 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/00_MQTT2_SERVER.pm | 53 ++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/fhem/FHEM/00_MQTT2_SERVER.pm b/fhem/FHEM/00_MQTT2_SERVER.pm index b7c24298e..9f4ddd4cb 100644 --- a/fhem/FHEM/00_MQTT2_SERVER.pm +++ b/fhem/FHEM/00_MQTT2_SERVER.pm @@ -44,6 +44,7 @@ MQTT2_SERVER_Initialize($) disable:0,1 disabledForIntervals keepaliveFactor + rePublish rawEvents sslVersion sslCertPrefix @@ -392,36 +393,40 @@ MQTT2_SERVER_Read($@) ###################################### # Call sendto for all clients + Dispatch + dotrigger if rawEvents is set -# tgt is the "accept" server, src is the connection generating the data +# server is the "accept" server, src is the connection generating the data sub MQTT2_SERVER_doPublish($$$$;$) { - my ($src, $tgt, $tp, $val, $retain) = @_; + my ($src, $server, $tp, $val, $retain) = @_; $val = "" if(!defined($val)); - $src = $tgt if(!defined($src)); + $src = $server if(!defined($src)); if($retain) { my $now = gettimeofday(); my %h = ( ts=>$now, val=>$val ); - $tgt->{retain}{$tp} = \%h; + $server->{retain}{$tp} = \%h; # Save it - my %nots = map { $_ => $tgt->{retain}{$_}{val} } keys %{$tgt->{retain}}; - setReadingsVal($tgt, "RETAIN", toJSON(\%nots), FmtDateTime(gettimeofday())); + my %nots = map { $_ => $server->{retain}{$_}{val} } + keys %{$server->{retain}}; + setReadingsVal($server,"RETAIN",toJSON(\%nots),FmtDateTime(gettimeofday())); } - foreach my $clName (keys %{$tgt->{clients}}) { - MQTT2_SERVER_sendto($tgt, $defs{$clName}, $tp, $val) + foreach my $clName (keys %{$server->{clients}}) { + MQTT2_SERVER_sendto($server, $defs{$clName}, $tp, $val) if($src->{NAME} ne $clName); } - if(defined($src->{cid})) { # "real" MQTT client - my $cid = $src->{cid}; + my $serverName = $server->{NAME}; + my $cid = $src->{cid}; + if(defined($cid) || # "real" MQTT client + AttrVal($serverName, "rePublish", undef)) { + $cid = $src->{NAME} if(!defined($cid)); $cid =~ s,[^a-z0-9._],_,gi; - my $ac = AttrVal($tgt->{NAME}, "autocreate", 1) ? "autocreate:":""; - Dispatch($tgt, "$ac$cid:$tp:$val", undef, !$ac); - my $re = AttrVal($tgt->{NAME}, "rawEvents", undef); - DoTrigger($tgt->{NAME}, "$tp:$val") if($re && $tp =~ m/$re/); + my $ac = AttrVal($serverName, "autocreate", 1) ? "autocreate:":""; + Dispatch($server, "$ac$cid:$tp:$val", undef, !$ac); + my $re = AttrVal($serverName, "rawEvents", undef); + DoTrigger($server->{NAME}, "$tp:$val") if($re && $tp =~ m/$re/); } } @@ -579,12 +584,6 @@ MQTT2_SERVER_getStr($$) messages, but not forward them.
- -
  • rawEvents <topic-regexp>
    - Send all messages as events attributed to this MQTT2_SERVER instance. - Should only be used, if there is no MQTT2_DEVICE to process the topic. -

  • -
  • keepaliveFactor
    the oasis spec requires a disconnect, if after 1.5 times the client @@ -597,6 +596,20 @@ MQTT2_SERVER_getStr($$)
  • + +
  • rawEvents <topic-regexp>
    + Send all messages as events attributed to this MQTT2_SERVER instance. + Should only be used, if there is no MQTT2_DEVICE to process the topic. +

  • + + +
  • rePublish
    + if a topic is published from a source inside of FHEM (e.g. MQTT2_DEVICE), + it is only sent to real MQTT clients, and it will not internally + republished. By setting this attribute the topic will also be dispatched + to the FHEM internal clients. +

  • +
  • SSL
    Enable SSL (i.e. TLS)