# MQTT wildcards using the spark core library

**URL:** <https://community.particle.io/t/mqtt-wildcards-using-the-spark-core-library/56796>\
**Category:** Libraries\
**Tags:** photon\
**Created:** [June 26, 2020, 11:27pm UTC](https://community.particle.io/t/mqtt-wildcards-using-the-spark-core-library/56796 "2020-06-26T23:27:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![trylaarsdam](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/trylaarsdam/32/24706_2.png) [@trylaarsdam](https://community.particle.io/u/trylaarsdam)\
**Post date:** [June 26, 2020, 11:27pm UTC](https://community.particle.io/t/mqtt-wildcards-using-the-spark-core-library/56796/1 "2020-06-26T23:27:30Z")

</div>

Hi there, I’m working with MQTT to connect a photon to a program running on a computer.

What I’d like to do is be able to make the photon subscribe to all topics under a certain topic, which with other MQTT clients is with `#` (e.g. `topic1/uuid/#` would subscribe to every topic under `topic1/uuid`)  
However this does not appear to be working on my photon.

Making a for loop and subscribing to different topics would work, it’s just a lot more work since the topics I would subscribe to differs based on the situation

Code:

```auto
#include "MQTT.h"
MQTT client("[server]", 1883, callback);

void callback(char* topic, byte* payload, unsigned int length) {
     //log
}

void subscribeToMQTT() {
     char buffer[64];
     sprintf(buffer, "topic/%s/#", currentUUID.c_str());
     client.subscribe(buffer);
}

```

---

<div class="post-metadata">

**Author:** ![trylaarsdam](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/trylaarsdam/32/24706_2.png) [@trylaarsdam](https://community.particle.io/u/trylaarsdam)\
**Post date:** [June 26, 2020, 11:35pm UTC](https://community.particle.io/t/mqtt-wildcards-using-the-spark-core-library/56796/2 "2020-06-26T23:35:06Z")

</div>

Not quite sure what solved it, but I think it was something to do with not putting my Serial.println(); in the right place in the callback.

Works now.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/3/2/3291e3c9351789fe8620ae5bcec8d3fec67ff221.png) [@system](https://community.particle.io/u/system)\
**Post date:** [August 25, 2020, 11:35pm UTC](https://community.particle.io/t/mqtt-wildcards-using-the-spark-core-library/56796/3 "2020-08-25T23:35:09Z")

</div>

Closed on August 25, 2020, 11:35pm UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
