I need help about my proyect with wemos d1 and MQTT server

Hi everybody, as the title says i have a problem with a if in my program.
The real cuestion is why don't works with two topics.
In color black is the problem

#include <ESP8266WiFi.h>
#include <PubSubClient.h>

// Connect to the WiFi
const char* ssid = "";        // Poner aquí la SSID de la WiFi
const char* password = "";  // Poner aquí el passwd de la WiFi
const char* mqtt_server = "";
const int mqttPort = ;
const char* mqttUser = "";
const char* mqttPassword = "";

WiFiClient espClient;
PubSubClient client(espClient);
 
[b]void callback(char* topic, byte* payload, unsigned int length) {
 Serial.print("Message arrived [");
 Serial.print(topic);
 Serial.print("] ");
 for (int i=0;i<length;i++) {
  char receivedChar = (char)payload[i];
  Serial.print(receivedChar);
  if (strcmp(topic, "Luces") == 0){
  if (receivedChar == '0' )
  // ESP8266 Huzzah outputs are "reversed"
   { digitalWrite(D2, LOW);  }
  if (receivedChar == '1')
   { digitalWrite(D2, HIGH); }
  }
  if (strcmp(topic, "Puerta") == 0){
  if (receivedChar == '0' )
  // ESP8266 Huzzah outputs are "reversed"
   { digitalWrite(D4, LOW);  }
  if (receivedChar == '1')
   { digitalWrite(D4, HIGH); }
  }
  if (strcmp(topic, "Aire") == 0){
  if (receivedChar == '0' )
  // ESP8266 Huzzah outputs are "reversed"
   { digitalWrite(D3, LOW);  }
  if (receivedChar == '1')
   { digitalWrite(D3, HIGH); }
  }
  Serial.println();
  }
  }[/b]
 
 
void reconnect() {
 // Loop until we're reconnected
 while (!client.connected()) {
 Serial.print("Attempting MQTT connection...");
 // Attempt to connect
 if (client.connect("ESP8266 Client",mqttUser,mqttPassword)) {
  Serial.println("connected");
  // ... and subscribe to topic
  client.subscribe("Luces");
  client.subscribe("Puerta");
 } else {
  Serial.print("failed, rc=");
  Serial.print(client.state());
  Serial.println(" try again in 5 seconds");
  // Wait 5 seconds before retrying
  delay(5000);
  }
 }
}
 
void setup()
{
 Serial.begin(9600);
 client.setServer(mqtt_server, mqttPort);
 client.setCallback(callback);
 setup_wifi();
 pinMode(D2,OUTPUT);
 pinMode(D3,OUTPUT);
 pinMode(D4,OUTPUT);
}

void setup_wifi() {

  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}
 
void loop()
{
 if (!client.connected()) {
  reconnect();
 }
 client.loop();
}

Thanks for your time and apologize for my english

In color black is the problem

All of your code is in black.

You can NOT apply color tags to code.

 for (int i=0;i<length;i++) {
  char receivedChar = (char)payload[i];
  Serial.print(receivedChar);
  if (strcmp(topic, "Luces") == 0){

Comparing topic to a literal in a for loop does not make sense. If it match one time, it will match every time. If it doesn't match one time, it won't ever match.

  Serial.print(receivedChar);

Something shows up in the Serial Monitor app. You have no clue what it is, AND you didn't share that with us.

How are we to know what is going wrong?

ok, apologize.

The code is all, in the serial port i see values send to topics from cloudmqtt.
I can't give my server but the values is 0 or 1. My problem is when i have two topics and i can't identify because this " if (strcmp(topic, "Luces") == 0) " It doesn't work or i don't know the real problem.

void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i=0;i<length;i++) {
char receivedChar = (char)payload*;*

  • Serial.print(receivedChar);*
    _ if (strcmp(topic, "Luces") == 0){_
  • if (receivedChar == '0' )*
  • // ESP8266 Huzzah outputs are "reversed"*
  • { digitalWrite(D2, LOW); }*
  • if (receivedChar == '1')*
  • { digitalWrite(D2, HIGH); }*
  • }*
  • if (strcmp(topic, "Puerta") == 0){*
  • if (receivedChar == '0' )*
  • // ESP8266 Huzzah outputs are "reversed"*
  • { digitalWrite(D4, LOW); }*
  • if (receivedChar == '1')*
  • { digitalWrite(D4, HIGH); }*
  • }*
  • if (strcmp(topic, "Aire") == 0){*
  • if (receivedChar == '0' )*
  • // ESP8266 Huzzah outputs are "reversed"*
  • { digitalWrite(D3, LOW); }*
  • if (receivedChar == '1')*
  • { digitalWrite(D3, HIGH); }*
  • }*
  • Serial.println();*
  • }*
  • }*
    thanks for your help

My problem is when i have two topics and i can't identify because this " if (strcmp(topic, "Luces") == 0) " It doesn't work or i don't know the real problem.

And, yet you continued to write code hoping that the problem would magically resolve itself when the code reached critical mass. That never happens.

i see values send to topics from cloudmqtt.

I can see the solution, printed right here on my desk. If you can't share, I won't either.