How to connect to multiple MQTT channels?

I have a Node MCU board and I have a working sketch which subscribes to a channel, and published to a channel.

Easy.

However I would like it to subscribe to 2 channels.

I can’t work out how to do that.

This is the code so far - only as an offering that I have it working.
(Attached)

If you want, look at the code and show me where to add the required code, or:
Show me some code which subscribes to 2 topics.

Thanks in advance.

Expanded_External_Temperatures_new_5c.ino (24.1 KB)

You currently subscribe to one topic here:

      client.subscribe(inTopic);

Nothing keeps you from calling the subscribe method multiple times with different topics. Easy. :wink:

All topics are dealt with using the same callback so you will need to determine what topic the data is for in the callback to know what to do with it.

Riva said:
All topics are dealt with using the same callback so you will need to determine what topic the data is for in the callback to know what to do with it.

So that would be by looking at the topic of the message - yes?
Or something like that.
I remember seeing code and it had something like a message topic scanner and acted on that.

Thanks to both for the reply.

When I next get the time to look at the code I will see if I can work out how to do the multiple subscriptions.

Learning all the time.