Subscribe and publish


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)??


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



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 .


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