user60674: I have a program that depending on user input, it creates one or several objects that will publish data to a MQTT broker, each one with a different topic. This is already done. The ESP8266 also has subscribe itself to the same topics it publishes.
Now, the problem is that I have to create a dynamic callback in the ESP8266 to read the all the posible arriving topics to which the ESP8266 has subscribed and I am having trouble with that.
The callback function model is:
void MQTTcallback(char* topic, byte* payload, unsigned int length) {


// handle message arrived

}

The possible topics can be:
ObjectTL/TL_1
ObjectTL/TL_2
ObjectTL/TL_3
...
ObjectTL/TL_X
The number (TL_X) depends of the user input I mention at the beginning.
Thanks!

user48909: I think using sscanf may help you
void MQTTcallback(char* topic, byte* payload, unsigned int length) {

  sscanf(data, "ObjectTL/TL_%d", dynamicTopicName);
  // handle message arrived
  your_dynamic_function(dynamicTopicName,byte* payload, unsigned int length)

}


60674: <p>I have a program that depending on user input, it creates one or several objects that will publish data to a MQTT broker, each one with a different topic. This is already done. The ESP8266 also has subscribe itself to the same topics it publishes.
Now, the problem is that I have to create a dynamic callback in the ESP8266 to read the all the posible arriving topics to which the ESP8266 has subscribed and I am having trouble with that.</p>

<p>The callback function model is:</p>

<pre><code>void MQTTcallback(char* topic, byte* payload, unsigned int length) {


// handle message arrived

}
</code></pre>

<p>The possible topics can be:</p>

<p>ObjectTL/TL_1</p>

<p>ObjectTL/TL_2</p>

<p>ObjectTL/TL_3</p>

<p>...</p>

<p>ObjectTL/TL_X</p>

<p>The number (TL_X) depends of the user input I mention at the beginning.
Thanks!</p>
 48909: <p>I think using sscanf may help you</p>

<pre><code>void MQTTcallback(char* topic, byte* payload, unsigned int length) {

  sscanf(data, "ObjectTL/TL_%d", dynamicTopicName);
  // handle message arrived
  your_dynamic_function(dynamicTopicName,byte* payload, unsigned int length)

}
</code></pre>
