Skip to content

Commit

Permalink
[467096] Fix incorrect bridge notification.
Browse files Browse the repository at this point in the history
If a custom notification topic was used, the bridge status would be set
to 1 before a connection was attempted, this has been fixed.

Initial updates to the status topic are now only set once, when the
broker starts, rather than each time the bridge attempts to reconnect.

Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=467096
  • Loading branch information
ralight committed May 16, 2015
1 parent 2bacb34 commit a6827df
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.txt
@@ -1,3 +1,5 @@
- Fix incorrect bridge notification on initial connection. Closes #467096.

1.4.2 - 20150507
================

Expand Down
14 changes: 10 additions & 4 deletions src/bridge.c
Expand Up @@ -175,8 +175,11 @@ int mqtt3_bridge_connect(struct mosquitto_db *db, struct mosquitto *context)

if(context->bridge->notifications){
if(context->bridge->notification_topic){
notification_payload = '1';
mqtt3_db_messages_easy_queue(db, context, context->bridge->notification_topic, 1, 1, &notification_payload, 1);
if(!context->bridge->initial_notification_done){
notification_payload = '0';
mqtt3_db_messages_easy_queue(db, context, context->bridge->notification_topic, 1, 1, &notification_payload, 1);
context->bridge->initial_notification_done = true;
}
notification_payload = '0';
rc = _mosquitto_will_set(context, context->bridge->notification_topic, 1, &notification_payload, 1, true);
if(rc != MOSQ_ERR_SUCCESS){
Expand All @@ -189,8 +192,11 @@ int mqtt3_bridge_connect(struct mosquitto_db *db, struct mosquitto *context)

snprintf(notification_topic, notification_topic_len+1, "$SYS/broker/connection/%s/state", context->bridge->remote_clientid);

notification_payload = '0';
mqtt3_db_messages_easy_queue(db, context, notification_topic, 1, 1, &notification_payload, 1);
if(!context->bridge->initial_notification_done){
notification_payload = '0';
mqtt3_db_messages_easy_queue(db, context, notification_topic, 1, 1, &notification_payload, 1);
context->bridge->initial_notification_done = true;
}

notification_payload = '0';
rc = _mosquitto_will_set(context, notification_topic, 1, &notification_payload, 1, true);
Expand Down
1 change: 1 addition & 0 deletions src/mosquitto_broker.h
Expand Up @@ -306,6 +306,7 @@ struct _mqtt3_bridge{
int threshold;
bool lazy_reconnect;
bool attempt_unsubscribe;
bool initial_notification_done;
#ifdef WITH_TLS
char *tls_cafile;
char *tls_capath;
Expand Down

0 comments on commit a6827df

Please sign in to comment.