Subscribe and publish


#1

I have Esp32 device and I want to subscribe to a variable and publish to another variable in the same code. how can I do this by (mqtt)??


#2

Greetings, you just have to call both subscribe() and publish() method of the PAHO library in your actual routine. You can reference some examples at our docs.

All the best


#3

Screenshot%20(295)

How can I edit this part if I want to subscribe to multivariable and publish to multivariable at the same time?
by the way, I am using Esp 32 over mqtt .


#4

Greetings, the callback is the function that handles any incoming message from the broker. If you are subscribed to multiple variables you will need to parse the topic to know to which variable is the incoming value related with.

If you wish to know more about the PubSubclient library, I advise you to check this tutorial.

All the best