One-to-one Communication in MQTT

0 votes

I need to set up an MQTT system for a project connecting many clients. These are all different type of clients with different functionalities. Some have information, like say temperature that is being published but at the same time, there are feature states that need to be set like switches, which can be set by other clients.

So, I used MQTT to achieve the following:

  • The client publishes information on the temperature it collects like so:
customer/group/device/temperature
  • To receive a state for the switch from different clients that it subscribes to, any client connects to a broker like so:
customer/group/device/switch

So far, I have only tried using a websocket based solution but now that MQTT has become such a famous protocol for IoT devices, I also wanted to know to implement one to one communications between clients using MQTT and this was how I tried doing it. 

Just, please take a look and correct me if I've made any mistakes.

Nov 23, 2018 in IoT (Internet of Things) by Bharani
• 4,660 points
1,057 views

1 answer to this question.

0 votes

Your solution seems to be a decent one. Let's say, for instance, client A publishes to client B by using topic customer/group/B/switch, then client B will reply to customer/group/A/switch.

Alternatively, client A could also publish to customer/group/B/switch and specify the topic where it expects any replies in its payload, like this:

{
    "data":"your message",
    "reply-to":"customer/group/A/segretreply-fromB-1345313"
}

That was just an example of JSON payload. You even can use timestamps, MACs or other unique sources to build the reply-to topic. Client A can subscribe to different reply-to topics for maintaining separate channels for every different client.

However, MQTT is not a one-to-one communication and each client can, potentially, subscribe to # and receive all messages. So, you'll need some sort of authorization in your broker to take a call on whether a client gets to publish/subscribe to a topic or not.

Give the following article a good read: MQTT Security Fundamentals: Authorization. You'll, then, be able to set up topics and authorization rules according to your requirements.

answered Nov 23, 2018 by nirvana
• 3,130 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer

Publishing commands to device in IBM IoT using MQTT in Java

If you are publishing from an application, ...READ MORE

answered Jul 27, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
1,306 views
0 votes
1 answer

How to read data from MQTT in Eclipse Paho?

You don't read data from a MQTT ...READ MORE

answered Aug 9, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
733 views
0 votes
1 answer

Faster communication between two ESP8266 in client-server setup

Try following. Server loop void loop() { // ...READ MORE

answered Jul 13, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
6,558 views
0 votes
1 answer

Send LoRa measures to Fiware IOT agent via MQTT

down vote I dont know if I understood ...READ MORE

answered Jul 13, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
1,424 views
0 votes
1 answer

Install MQTT on windows 10

hey @Greg, go to the following link ...READ MORE

answered Jul 9, 2019 in Others by Mahi
1,229 views
0 votes
1 answer

MQTT Maximum Message count / Maximum Topic count

Hello @ Dingsbums , The number of topics is going ...READ MORE

answered Jul 27, 2020 in IoT (Internet of Things) by Niroj
• 82,880 points
4,051 views
0 votes
1 answer

How to add https security for Node js?

You need to add the key and cert to the createServer function. const options ...READ MORE

answered Aug 10, 2018 in Blockchain by digger
• 26,740 points
515 views
0 votes
1 answer

MQTT pubish is slow to send with ESP8266 & NodeMCU

I think you're almost correct and on ...READ MORE

answered Aug 1, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
2,792 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP