nodMCU how to alternate between 2 topic

19 views
Skip to first unread message

PC

unread,
Aug 26, 2022, 10:47:05 AM8/26/22
to MQTT
Hello,
I have a nodeMCU (with an LCD display) which I would like to alternate the reading of 2 MQTT topic.
I have a flag (dependent on the state of a digital entry) which works, but I do not see the change of topic on reading.
Thank you for your help
code :
void reconnect() {
  while (!client.connected()) {
    Serial.println("Connection au serveur MQTT ...");
    if (client.connect("LectureXYZ_1")) {
      Serial.println("MQTT connecté");
    }
    else {
      Serial.print("echec, code erreur= ");
      Serial.println(client.state());
      Serial.println("nouvel essai dans 1.5 s");
      delay(1500);
    }
  }
   if (flagTfa) {
    client.subscribe("TFA");
  } else {
    client.subscribe("CPT");
  }
}

PC

unread,
Aug 26, 2022, 11:12:31 AM8/26/22
to MQTT
me again,
I have an idea to me: should I disconnect to the change of flag?
And in this case, how to do it?
thanks again

Greg Troxel

unread,
Aug 26, 2022, 12:34:43 PM8/26/22
to PC, MQTT
As I understand it, this list is more or less a protocol working group:

This group brings together discussions of the protocol and different
implementations. Other discussion media exist (for example, individual
software implementations may have their own project resources) but this
group is for discussion of the protocol and MQTT ecosystem as a
whole. Off-topic debates, discussion around alternative protocols,
etc. do not belong in this group.

rather than a help forum for programming.

Blaise Cacramp

unread,
Aug 26, 2022, 12:52:02 PM8/26/22
to Greg Troxel, MQTT
Merci pour votre aide, comment dire ... constructive !

Le 26-08-22 à 18:34, Greg Troxel a écrit :
Reply all
Reply to author
Forward
0 new messages