Hi guys,
I need your help, is it possible to subscribe on multiple mqtt topic with pubSubClient library ?
I found a solution by using strcmp()
void callback(char* topic, byte* payload, unsigned int length) {
if(strcmp(topic,inTopicPwmChannel) == 0) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.println("] ");
for (int i = 0; i < length; i++) {
charPwm[i] = (char)payload[i];
}
sscanf(charPwm, "%d", &pwmValue);
Serial.print("PWM: ");
Serial.println(pwmValue);
}
if(strcmp(topic,inTopicCommandChannel) == 0) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.println("]");
for (int i = 0; i < length; i++) {
charPwm[i] = (char)payload[i];
}
sscanf(charPwm, "%d", &pwmValue);
Serial.print("PWM: ");
Serial.println(pwmValue);
}
}
So there is another method to have the same result ?
My goal is eliminate the if(strcmp(....)) inside void callback(), to have multiple void callback() for each subscription.
In this example: void pwmCallback()... and void commandCallback()...
Is it possible ?