2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-28 11:01:59 +00:00

00_MQTT2_SERVER.pm/00_MQTT2_CLIENT.pm: add ignoreRegexp (Forum #103737)

git-svn-id: https://svn.fhem.de/fhem/trunk@21625 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2020-04-08 10:15:11 +00:00
parent 1c403e8821
commit c7d1d34c62
3 changed files with 61 additions and 21 deletions

View File

@ -40,6 +40,7 @@ MQTT2_CLIENT_Initialize($)
clientId clientId
disable:1,0 disable:1,0
disabledForIntervals disabledForIntervals
ignoreRegexp
lwt lwt
lwtRetain lwtRetain
keepaliveTimeout keepaliveTimeout
@ -207,8 +208,16 @@ MQTT2_CLIENT_Attr(@)
$hash->{SSL} = $param[0] ? $param[0] : 1; $hash->{SSL} = $param[0] ? $param[0] : 1;
} }
if($type eq "set" && $attrName eq "ignoreRegexp") {
my $re = join(" ",@param);
return "bad $devName ignoreRegexp: $re" if($re eq "1" || $re =~ m/^\*/);
eval { "Hallo" =~ m/$re/ };
return "bad $devName ignoreRegexp: $re: $@" if($@);
}
if($attrName eq "clientId") { if($attrName eq "clientId") {
$hash->{clientId} = $param[0]; delete($hash->{clientId});
$hash->{clientId} = $param[0] if($type eq "set");
} }
if($attrName eq "sslargs") { if($attrName eq "sslargs") {
@ -362,6 +371,10 @@ MQTT2_CLIENT_Read($@)
if(!IsDisabled($name)) { if(!IsDisabled($name)) {
$val = "" if(!defined($val)); $val = "" if(!defined($val));
my $ir = AttrVal($name, "ignoreRegexp", undef);
next if(defined($ir) && "$tp:$val" =~ m/$ir/);
my $ac = AttrVal($name, "autocreate", "no"); my $ac = AttrVal($name, "autocreate", "no");
$ac = $ac eq "1" ? "simple" : ($ac eq "0" ? "no" : $ac); # backward comp. $ac = $ac eq "1" ? "simple" : ($ac eq "0" ? "no" : $ac); # backward comp.
@ -537,7 +550,7 @@ MQTT2_CLIENT_getStr($$)
<b>Attributes</b> <b>Attributes</b>
<ul> <ul>
<a name="autocreate"></a> <a name="MQTT_CLIENTautocreate"></a>
<li>autocreate [no|simple|complex]<br> <li>autocreate [no|simple|complex]<br>
if set to simple/complex, at least one MQTT2_DEVICE will be created, and if set to simple/complex, at least one MQTT2_DEVICE will be created, and
its readingsList will be expanded upon reception of published messages. its readingsList will be expanded upon reception of published messages.
@ -555,7 +568,7 @@ MQTT2_CLIENT_getStr($$)
attribute it is not really useful. attribute it is not really useful.
</li></br> </li></br>
<a name="clientId"></a> <a name="MQTT_CLIENTclientId"></a>
<li>clientId &lt;name&gt;<br> <li>clientId &lt;name&gt;<br>
set the MQTT clientId. If not set, the name of the MQTT2_CLIENT instance set the MQTT clientId. If not set, the name of the MQTT2_CLIENT instance
is used, after deleting everything outside 0-9a-zA-Z is used, after deleting everything outside 0-9a-zA-Z
@ -566,65 +579,70 @@ MQTT2_CLIENT_getStr($$)
disable dispatching of messages. disable dispatching of messages.
</li><br> </li><br>
<a name="lwt"></a> <a name="MQTT2_CLIENTignoreRegexp"></a>
<li>ignoreRegexp<br>
if $topic:$message matches ignoreRegexp, then it will be silently ignored.
</li>
<a name="MQTT_CLIENTlwt"></a>
<li>lwt &lt;topic&gt; &lt;message&gt; <br> <li>lwt &lt;topic&gt; &lt;message&gt; <br>
set the LWT (last will and testament) topic and message, default is empty. set the LWT (last will and testament) topic and message, default is empty.
</li></br> </li></br>
<a name="keepaliveTimeout"></a> <a name="MQTT_CLIENTkeepaliveTimeout"></a>
<li>keepaliveTimeout &lt;seconds;&gt;<br> <li>keepaliveTimeout &lt;seconds;&gt;<br>
number of seconds for sending keepalive messages, 0 disables it. number of seconds for sending keepalive messages, 0 disables it.
The broker will disconnect, if there were no messages for The broker will disconnect, if there were no messages for
1.5 * keepaliveTimeout seconds. 1.5 * keepaliveTimeout seconds.
</li></br> </li></br>
<a name="lwtRetain"></a> <a name="MQTT_CLIENTlwtRetain"></a>
<li>lwtRetain<br> <li>lwtRetain<br>
if set, the lwt retain flag is set if set, the lwt retain flag is set
</li></br> </li></br>
<a name="mqttVersion"></a> <a name="MQTT_CLIENTmqttVersion"></a>
<li>mqttVersion 3.1,3.1.1<br> <li>mqttVersion 3.1,3.1.1<br>
set the MQTT protocol version in the CONNECT header, default is 3.1 set the MQTT protocol version in the CONNECT header, default is 3.1
</li></br> </li></br>
<a name="msgAfterConnect"></a> <a name="MQTT_CLIENTmsgAfterConnect"></a>
<li>msgAfterConnect [-r] topic message<br> <li>msgAfterConnect [-r] topic message<br>
publish the topic after each connect or reconnect.<br> publish the topic after each connect or reconnect.<br>
If the optional -r is specified, then the publish sets the retain flag. If the optional -r is specified, then the publish sets the retain flag.
</li></br> </li></br>
<a name="msgBeforeDisconnect"></a> <a name="MQTT_CLIENTmsgBeforeDisconnect"></a>
<li>msgBeforeDisconnect [-r] topic message<br> <li>msgBeforeDisconnect [-r] topic message<br>
publish the topic bofore each disconnect.<br> publish the topic bofore each disconnect.<br>
If the optional -r is specified, then the publish sets the retain flag. If the optional -r is specified, then the publish sets the retain flag.
</li></br> </li></br>
<a name="rawEvents"></a> <a name="MQTT_CLIENTrawEvents"></a>
<li>rawEvents &lt;topic-regexp&gt;<br> <li>rawEvents &lt;topic-regexp&gt;<br>
send all messages as events attributed to this MQTT2_CLIENT instance. send all messages as events attributed to this MQTT2_CLIENT instance.
Should only be used, if there is no MQTT2_DEVICE to process the topic. Should only be used, if there is no MQTT2_DEVICE to process the topic.
</li><br> </li><br>
<a name="subscriptions"></a> <a name="MQTT_CLIENTsubscriptions"></a>
<li>subscriptions &lt;subscriptions&gt;<br> <li>subscriptions &lt;subscriptions&gt;<br>
space separated list of MQTT subscriptions, default is #<br> space separated list of MQTT subscriptions, default is #<br>
Note: if the value is the literal setByTheProgram, then the value sent by Note: if the value is the literal setByTheProgram, then the value sent by
the client (e.g. MQTT_GENERIC_BRIDGE) is used. the client (e.g. MQTT_GENERIC_BRIDGE) is used.
</li><br> </li><br>
<a name="SSL"></a> <a name="MQTT_CLIENTSSL"></a>
<li>SSL<br> <li>SSL<br>
Enable SSL (i.e. TLS) Enable SSL (i.e. TLS)
</li><br> </li><br>
<a name="sslargs"></a> <a name="MQTT_CLIENTsslargs"></a>
<li>sslargs<br> <li>sslargs<br>
a list of space separated tuples of key:value, where key is one of the a list of space separated tuples of key:value, where key is one of the
possible options documented in perldoc IO::Socket::SSL possible options documented in perldoc IO::Socket::SSL
</li><br> </li><br>
<a name="username"></a> <a name="MQTT_CLIENTusername"></a>
<li>username &lt;username&gt;<br> <li>username &lt;username&gt;<br>
set the username. The password is set via the set command, and is stored set the username. The password is set via the set command, and is stored
separately, see above. separately, see above.

View File

@ -42,6 +42,7 @@ MQTT2_SERVER_Initialize($)
clientId clientId
disable:1,0 disable:1,0
disabledForIntervals disabledForIntervals
ignoreRegexp
keepaliveFactor keepaliveFactor
rePublish:1,0 rePublish:1,0
rawEvents rawEvents
@ -137,6 +138,14 @@ MQTT2_SERVER_Attr(@)
if($type eq "set" && $attrName eq "SSL") { if($type eq "set" && $attrName eq "SSL") {
InternalTimer(1, "TcpServer_SetSSL", $hash, 0); # Wait for sslCertPrefix InternalTimer(1, "TcpServer_SetSSL", $hash, 0); # Wait for sslCertPrefix
} }
if($type eq "set" && $attrName eq "ignoreRegexp") {
my $re = join(" ",@param);
return "bad $devName ignoreRegexp: $re" if($re eq "1" || $re =~ m/^\*/);
eval { "Hallo" =~ m/$re/ };
return "bad $devName ignoreRegexp: $re: $@" if($@);
}
return undef; return undef;
} }
@ -443,6 +452,9 @@ MQTT2_SERVER_doPublish($$$$;$)
} }
my $serverName = $server->{NAME}; my $serverName = $server->{NAME};
my $ir = AttrVal($serverName, "ignoreRegexp", undef);
next if(defined($ir) && "$tp:$val" =~ m/$ir/);
my $cid = $src->{cid}; my $cid = $src->{cid};
$tp =~ s/:/_/g; # 96608 $tp =~ s/:/_/g; # 96608
if(defined($cid) || # "real" MQTT client if(defined($cid) || # "real" MQTT client
@ -614,7 +626,7 @@ MQTT2_SERVER_ReadDebug($$)
<b>Attributes</b> <b>Attributes</b>
<ul> <ul>
<a name="clientId"></a> <a name="MQTT2_SERVERclientId"></a>
<li>clientId &lt;name&gt;<br> <li>clientId &lt;name&gt;<br>
set the MQTT clientId for all connections, for setups with clients set the MQTT clientId for all connections, for setups with clients
creating a different MQTT-ID for each connection. The autocreate creating a different MQTT-ID for each connection. The autocreate
@ -629,7 +641,12 @@ MQTT2_SERVER_ReadDebug($$)
messages, but not forward them. messages, but not forward them.
</li><br> </li><br>
<a name="keepaliveFactor"></a> <a name="MQTT2_SERVERignoreRegexp"></a>
<li>ignoreRegexp<br>
if $topic:$message matches ignoreRegexp, then it will be silently ignored.
</li>
<a name="MQTT2_SERVERkeepaliveFactor"></a>
<li>keepaliveFactor<br> <li>keepaliveFactor<br>
the oasis spec requires a disconnect, if after 1.5 times the client the oasis spec requires a disconnect, if after 1.5 times the client
supplied keepalive no data or PINGREQ is sent. With this attribute you supplied keepalive no data or PINGREQ is sent. With this attribute you
@ -641,13 +658,13 @@ MQTT2_SERVER_ReadDebug($$)
</ul> </ul>
</li> </li>
<a name="rawEvents"></a> <a name="MQTT2_SERVERrawEvents"></a>
<li>rawEvents &lt;topic-regexp&gt;<br> <li>rawEvents &lt;topic-regexp&gt;<br>
Send all messages as events attributed to this MQTT2_SERVER instance. 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. Should only be used, if there is no MQTT2_DEVICE to process the topic.
</li><br> </li><br>
<a name="rePublish"></a> <a name="MQTT2_SERVERrePublish"></a>
<li>rePublish<br> <li>rePublish<br>
if a topic is published from a source inside of FHEM (e.g. MQTT2_DEVICE), 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 it is only sent to real MQTT clients, and it will not internally
@ -655,7 +672,7 @@ MQTT2_SERVER_ReadDebug($$)
to the FHEM internal clients. to the FHEM internal clients.
</li><br> </li><br>
<a name="SSL"></a> <a name="MQTT2_SERVERSSL"></a>
<li>SSL<br> <li>SSL<br>
Enable SSL (i.e. TLS). Enable SSL (i.e. TLS).
</li><br> </li><br>
@ -669,7 +686,7 @@ MQTT2_SERVER_ReadDebug($$)
also the SSL attribute. also the SSL attribute.
</li><br> </li><br>
<a name="autocreate"></a> <a name="MQTT2_SERVERautocreate"></a>
<li>autocreate [no|simple|complex]<br> <li>autocreate [no|simple|complex]<br>
MQTT2_DEVICES will be automatically created upon receiving an MQTT2_DEVICES will be automatically created upon receiving an
unknown message. Set this value to no to disable autocreating, the unknown message. Set this value to no to disable autocreating, the

View File

@ -306,7 +306,12 @@ FW_jqueryReadyFn()
$("#content") $("#content")
.append("<div id='workbench' style='display:none'></div>"); .append("<div id='workbench' style='display:none'></div>");
$("#content > #workbench").html(data); $("#content > #workbench").html(data);
var aTag = $("#content > #workbench").find("a[name="+val+"]");
var mtype = $("#content > #workbench a[name]").attr("name"), aTag;
if(mtype)
aTag = $("#content > #workbench").find("a[name="+mtype+val+"]");
if(!$(aTag).length) // old style syntax without type
aTag = $("#content > #workbench").find("a[name="+val+"]");
if($(aTag).length) { if($(aTag).length) {
var liTag = $(aTag).next("li"); var liTag = $(aTag).next("li");
if(!$(liTag).length) if(!$(liTag).length)