mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 12:49:34 +00:00
MQTT: implement retain
git-svn-id: https://svn.fhem.de/fhem/trunk@6710 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
de665f1995
commit
32003c87bf
@ -433,6 +433,7 @@ sub Client_Define($$) {
|
||||
|
||||
$client->{NOTIFYDEV} = $client->{DEF} if $client->{DEF};
|
||||
$client->{qos} = MQTT_QOS_AT_MOST_ONCE;
|
||||
$client->{retain} = 0;
|
||||
$client->{subscribe} = [];
|
||||
$client->{subscribeExpr} = [];
|
||||
|
||||
@ -459,6 +460,14 @@ sub client_attr($$$$$) {
|
||||
}
|
||||
last;
|
||||
};
|
||||
$attribute eq "retain" and do {
|
||||
if ($command eq "set") {
|
||||
$client->{retain} = $value;
|
||||
} else {
|
||||
$client->{retain} = 0;
|
||||
}
|
||||
last;
|
||||
};
|
||||
$attribute eq "IODev" and do {
|
||||
if ($main::init_done) {
|
||||
if ($command eq "set") {
|
||||
|
@ -48,6 +48,7 @@ sub MQTT_BRIDGE_Initialize($) {
|
||||
$hash->{AttrList} =
|
||||
"IODev ".
|
||||
"qos:".join(",",keys %MQTT::qos)." ".
|
||||
"retain:0,1 ".
|
||||
"publish-topic-base ".
|
||||
"publishState ".
|
||||
"publishReading_.* ".
|
||||
@ -108,12 +109,12 @@ sub Notify() {
|
||||
my $msgid;
|
||||
if (defined $3 and $3 ne "") {
|
||||
if (defined $hash->{publishReadings}->{$1}) {
|
||||
$msgid = send_publish($hash->{IODev}, topic => $hash->{publishReadings}->{$1}, message => $3, qos => $hash->{qos});
|
||||
$msgid = send_publish($hash->{IODev}, topic => $hash->{publishReadings}->{$1}, message => $3, qos => $hash->{qos}, retain => $hash->{retain});
|
||||
readingsSingleUpdate($hash,"transmission-state","outgoing publish sent",1);
|
||||
}
|
||||
} else {
|
||||
if (defined $hash->{publishState}) {
|
||||
$msgid = send_publish($hash->{IODev}, topic => $hash->{publishState}, message => $1, qos => $hash->{qos});
|
||||
$msgid = send_publish($hash->{IODev}, topic => $hash->{publishState}, message => $1, qos => $hash->{qos}, retain => $hash->{retain});
|
||||
readingsSingleUpdate($hash,"transmission-state","outgoing publish sent",1);
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ sub MQTT_DEVICE_Initialize($) {
|
||||
$hash->{AttrList} =
|
||||
"IODev ".
|
||||
"qos:".join(",",keys %MQTT::qos)." ".
|
||||
"retain:0,1 ".
|
||||
"publishSet ".
|
||||
"publishSet_.* ".
|
||||
"subscribeReading_.* ".
|
||||
@ -83,10 +84,10 @@ sub Set($@) {
|
||||
my $value = $a[2];
|
||||
my $msgid;
|
||||
if (defined $value) {
|
||||
$msgid = send_publish($hash->{IODev}, topic => $hash->{publishSets}->{$command}->{topic}, message => $value, qos => $hash->{qos});
|
||||
$msgid = send_publish($hash->{IODev}, topic => $hash->{publishSets}->{$command}->{topic}, message => $value, qos => $hash->{qos}, retain => $hash->{retain});
|
||||
readingsSingleUpdate($hash,$command,$value,1);
|
||||
} else {
|
||||
$msgid = send_publish($hash->{IODev}, topic => $hash->{publishSets}->{""}->{topic}, message => $command, qos => $hash->{qos});
|
||||
$msgid = send_publish($hash->{IODev}, topic => $hash->{publishSets}->{""}->{topic}, message => $command, qos => $hash->{qos}, retain => $hash->{retain});
|
||||
readingsSingleUpdate($hash,"state",$command,1);
|
||||
}
|
||||
$hash->{message_ids}->{$msgid}++ if defined $msgid;
|
||||
|
Loading…
Reference in New Issue
Block a user