MQTT wildcards using the spark core library

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:

#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);
}


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.

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