[SOLVED] 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

1 Like

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 .

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

There is Error in calling both subscribe and publish method in same time there is no data sent or received .

Greetings, it is really hard to me to understand your issue in order to give you additional hints, What have you tried to solve your issue? Have you already check the example to publish and subscribe? What error are you getting?

All the best