Can MQTT broker send commands/messages back to publisher

386 views
Skip to first unread message

anil verma

unread,
Jul 16, 2020, 12:23:56 PM7/16/20
to MQTT
I am a newbie to MQTT so I guess this would sound like a silly question but here it goes.

I am implementing a MODBUS to MQTT (Publisher) which at frequent intervals transmits the telemetry coming to Modbus.  Here's how the flow looks

AC Cooler ----> Modbus ----> MQTT Publisher  (PIC MCU) --->  Ethernet controller (TCP/IP) --> MQTT Broker.

while the above setup works fine, the customer wants us to send commands back through the MQTT broker to my publisher which in turn parses a command back through Modbus to AC Cooler to change parameters such as fan speed, alarms...etc.  My MCU is perfectly capable of accepting commands through the TCP layer but I am not sure if the underlying MQTT API would be able to send commands from broker to publisher. Well considering it is a messaging protocol and publisher being able to broadcast topic to multiple broker/client I am assuming the MQTT does not allow point to point messaging from broker to client.

Please correct me if I am wrong and if there is a way to work this back communication.

Regards
Anil Verma B

Dustin Sallings

unread,
Jul 16, 2020, 12:36:10 PM7/16/20
to mq...@googlegroups.com
I'm not sure I'd think of "publisher" as a concept.  A client or a broker can publish.  A client can publish or subscribe.  When a client publishes to a broker, the broker gets to decide what that means.  It could process the messages as an internal-only thing, or, as a normal message, just send it on to any clients that have subscribed.  Similarly, a client can subscribe to paths that only have messages published by the broker itself (e.g., $SYS/#).

But in your case, your MCU would subscribe to whatever command structure makes sense.  Your MQTT client should have some sort of functionality for handling incoming messages.  You can have as many as you want and they will be processed whenever the client picks them up.  It's probably easier to think of these two things (publishing and subscribing) as different concepts, but you can reuse the same client for both parts.

--
To learn more about MQTT please visit http://mqtt.org
---
You received this message because you are subscribed to the Google Groups "MQTT" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mqtt+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mqtt/169fa198-f625-4860-994d-d1a45d5bad38o%40googlegroups.com.

anil verma

unread,
Jul 16, 2020, 2:00:52 PM7/16/20
to MQTT
So basically it goes both ways, so I just need to put in the code to listen to incomming MQTT data and process accordingly. Thanks for taking the time to respond...appreciate it.
To unsubscribe from this group and stop receiving emails from it, send an email to mq...@googlegroups.com.

Andy Stanford-Clark

unread,
Jul 16, 2020, 2:37:49 PM7/16/20
to 'Simon Walters' via MQTT
yes. Your client (the MCU) needs to “subscribe” to the topic(s) it wants to receive messages on (which will be the command topic the application “north” of the broker is sending them on, targeted at that specific device). You need to arrange a topic structure so the application can target a specific MODBUS device with a unique topic, for example by including the serial number or MAC address or something unique, of the device in the topic, and having the device look up its own serial number and construct the correct topic to subscribe to, so only that device receives the commands sent to it.

Andy

To unsubscribe from this group and stop receiving emails from it, send an email to mqtt+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mqtt/7c485602-1e23-44a2-91a6-0caf5f4dcc29o%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages