00_MQTT2_CLIENT.pm: "dynamic" packet identifier (Forum #91304)

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@22280 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2020-06-27 09:14:04 +00:00
parent f4d9bb8dc4
commit 767da87ba2

View File

@ -258,6 +258,7 @@ MQTT2_CLIENT_Attr(@)
return "qosMaxQueueLength must be an integer" if($param[0] !~ m/^\d+$/); return "qosMaxQueueLength must be an integer" if($param[0] !~ m/^\d+$/);
$hash->{qosMaxQueueLength} = $param[0]; $hash->{qosMaxQueueLength} = $param[0];
$hash->{qosQueue} = []; $hash->{qosQueue} = [];
$hash->{qosCnt} = 0;
} else { } else {
delete $hash->{qosQueue}; delete $hash->{qosQueue};
delete $hash->{qosMaxQueueLength}; delete $hash->{qosMaxQueueLength};
@ -424,6 +425,7 @@ MQTT2_CLIENT_Read($@)
###################################### ######################################
# send topic to client if its subscriptions matches the topic # send topic to client if its subscriptions matches the topic
sub sub
MQTT2_CLIENT_doPublish($@) MQTT2_CLIENT_doPublish($@)
{ {
@ -439,7 +441,7 @@ MQTT2_CLIENT_doPublish($@)
@{$hash->{qosQueue}} < $hash->{qosMaxQueueLength}) { @{$hash->{qosQueue}} < $hash->{qosMaxQueueLength}) {
$hdr += 2; # QoS:1 $hdr += 2; # QoS:1
push(@{$hash->{qosQueue}}, [$topic,$val,$retain]); push(@{$hash->{qosQueue}}, [$topic,$val,$retain]);
$pi = "FM"; # Packet Identifier, if QoS > 0 $pi = pack("n",1+($hash->{qosCnt}++%65535)); # Packet Identifier, if QoS > 0
} }
my $msg = pack("C", $hdr). my $msg = pack("C", $hdr).
MQTT2_CLIENT_calcRemainingLength(2+length($topic)+length($val)+ MQTT2_CLIENT_calcRemainingLength(2+length($topic)+length($val)+
@ -468,7 +470,7 @@ MQTT2_CLIENT_send($$;$$)
if($immediate) { if($immediate) {
DevIo_SimpleWrite($hash, $msg, 0); DevIo_SimpleWrite($hash, $msg, 0);
} else { } else {
addToWritebuffer($hash, $msg); addToWritebuffer($hash, $msg, undef, 1); # nolimit
} }
} }