2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

00_MQTT2_CLIENT.pm: add encoding unicode support

git-svn-id: https://svn.fhem.de/fhem/trunk@25700 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2022-02-18 17:07:09 +00:00
parent cb7641a1ba
commit 669f32a3d9
2 changed files with 15 additions and 3 deletions

View File

@ -500,6 +500,7 @@ MQTT2_CLIENT_Read($@)
$off += 2; $off += 2;
} }
$val = substr($pl, $off); $val = substr($pl, $off);
$val = Encode::decode('UTF-8', $val) if($unicodeEncoding);
MQTT2_CLIENT_send($hash, pack("CCnC*", 0x40, 2, $pid)) if($qos); # PUBACK MQTT2_CLIENT_send($hash, pack("CCnC*", 0x40, 2, $pid)) if($qos); # PUBACK
MQTT2_CLIENT_updateDisconnectTimer($hash); MQTT2_CLIENT_updateDisconnectTimer($hash);
@ -565,6 +566,11 @@ MQTT2_CLIENT_doPublish($@)
push(@{$hash->{qosQueue}}, [$topic,$val,$retain]); push(@{$hash->{qosQueue}}, [$topic,$val,$retain]);
$pi = pack("n",1+($hash->{qosCnt}++%65535)); # Packet Identifier, if QoS > 0 $pi = pack("n",1+($hash->{qosCnt}++%65535)); # Packet Identifier, if QoS > 0
} }
if($unicodeEncoding) {
$topic = Encode::encode('UTF-8', $topic);
$val = Encode::encode('UTF-8', $val);
}
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)+
length($pi)). length($pi)).
@ -660,7 +666,9 @@ MQTT2_CLIENT_getStr($$)
{ {
my ($in, $off) = @_; my ($in, $off) = @_;
my $l = unpack("n", substr($in, $off, 2)); my $l = unpack("n", substr($in, $off, 2));
return (substr($in, $off+2, $l), $off+2+$l); my $r = substr($in, $off+2, $l);
$r = Encode::decode('UTF-8', $r) if($unicodeEncoding);
return ($r, $off+2+$l);
} }
1; 1;

View File

@ -3862,8 +3862,12 @@ DoTrigger($$@)
my $event = $events->[$i]; my $event = $events->[$i];
my $t = (($ct && $ct->[$i]) ? $ct->[$i] : $tn); my $t = (($ct && $ct->[$i]) ? $ct->[$i] : $tn);
next if($re && !($dev =~ m/$re/ || "$dev:$event" =~ m/$re/)); next if($re && !($dev =~ m/$re/ || "$dev:$event" =~ m/$re/));
addToWritebuffer($dc,($inform{$c}{type} eq "timer" ? "$t " : "").
"$hash->{TYPE} $dev $event\n"); my $txt = ($inform{$c}{type} eq "timer" ? "$t " : "").
"$hash->{TYPE} $dev $event\n";
my $enc = $dc->{encoding} && $dc->{encoding} eq "latin1" ? "Latin1":"UTF-8";
$txt = Encode::encode($enc, $txt);
addToWritebuffer($dc, $txt);
} }
} }
} }