Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [mosquitto-dev] Automatic Subscription

Hi Patrick,

Try the attached patch, it should give you the right idea at least.
Cheers,

Roger



On 29 Nov 2016 12:11 a.m., "Patrick Collins" <normalbloke@xxxxxxxxx> wrote:
Would you be able to provide some clues as to how to implement this. I'm not familiar with the Mosquitto source code but could write something given some direction from the members of this distribution list. What I need to achieve is to subscribe a client to automatically subscribe certain clients of a Mosquitto MQTT broker to nominated topics when the client connects and wthout any action by the client.

On 28 November 2016 at 23:38, ನಾಗೇಶ್ ಸುಬ್ರಹ್ಮಣ್ಯ (Nagesh S) <nageshblore@xxxxxxxxx> wrote:

Connect and subscribe are two different messages in mqtt protocol. So, both messages must be exchanged.

A wrapper can be developed to give an appearance of single message.

Or, implement a new message altogether- say, CONNSUB. :)

Pardon brevity, typos and grammar mistakes. Sent from phone.


On 28 Nov 2016 17:58, "Patrick Collins" <normalbloke@xxxxxxxxx> wrote:
Would it be possible for the mosquitto broker to automatically subscribe clients to a topic on connection. This is to work with the Telit HE910 modules that expect this behavior.

Regards.

Paddy

_______________________________________________
mosquitto-dev mailing list
mosquitto-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/mosquitto-dev


_______________________________________________
mosquitto-dev mailing list
mosquitto-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/mosquitto-dev


_______________________________________________
mosquitto-dev mailing list
mosquitto-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/mosquitto-dev
diff --git a/src/read_handle_server.c b/src/read_handle_server.c
index 14f72d7..915e9d3 100644
--- a/src/read_handle_server.c
+++ b/src/read_handle_server.c
@@ -574,6 +574,13 @@ int mqtt3_handle_connect(struct mosquitto_db *db, struct mosquitto *context)
 	}
 #endif
 	context->state = mosq_cs_connected;
+
+	rc = mqtt3_sub_add(db, context, "your/sub/string", 0 /* Your QoS*/, &db->subs);
+	/* If you want to send retained messages as well, you need mqtt3_retain_queue(). */
+	if(rc == MOSQ_ERR_SUCCESS){
+		mqtt3_retain_queue(db, context, "your/sub/string", 0 /* Your QoS */);
+	}
+
 	return _mosquitto_send_connack(context, connect_ack, CONNACK_ACCEPTED);
 
 handle_connect_error:

Back to the top