Esp8266 + mqtt + dht11 + multitopic

Hi Guys! Im very new to this fascinating world. But i want to learn more and more every day. Now i have a question

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


#define MQTT_SERVER ""
const char* ssid = "";
const char* password = "";

WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
int value = 0;

const int relay1Pin = D0;
const int btnPin =D6;
int buttonState = 0;
char* ledTopic = "test/led";
char* relayTopic = "test/relay";
const char* user = "";
const char* pass = "";
int relayState= 0;
int lastBtnState;
const int ledPin = D2;


/*
 Basic ESP8266 MQTT example

 This sketch demonstrates the capabilities of the pubsub library in combination
 with the ESP8266 board/library.

 It connects to an MQTT server then:
  - publishes "hello world" to the topic "outTopic" every two seconds
  - subscribes to the topic "inTopic", printing out any messages
    it receives. NB - it assumes the received payloads are strings not binary
  - If the first character of the topic "inTopic" is an 1, switch ON the ESP Led,
    else switch it off

 It will reconnect to the server if the connection is lost using a blocking
 reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to
 achieve the same result without blocking the main loop.

 To install the ESP8266 board, (using Arduino 1.6.4+):
  - Add the following 3rd party board manager under "File -> Preferences -> Additional Boards Manager URLs":
       http://arduino.esp8266.com/stable/package_esp8266com_index.json
  - Open the "Tools -> Board -> Board Manager" and click install for the ESP8266"
  - Select your ESP8266 in "Tools -> Board"

*/
void setup() {
  pinMode(relay1Pin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(btnPin, INPUT);
  Serial.begin(115200);
  setup_wifi();
  client.setServer(MQTT_SERVER, 10960);
  client.setCallback(callback);
}

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 callback(String topic, byte* message, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  String messageLed;
  for (int i = 0; i < length; i++) {
    Serial.print((char)message[i]);
    messageLed += (char)message[i];
  }
  Serial.println();
    if(topic=="test/led"){
       if(messageLed == "1"){
        Serial.println(messageLed);
        digitalWrite(ledPin, HIGH);
        Serial.print("On Led Topic");
      }
      else if(messageLed == "0"){
        digitalWrite(ledPin, LOW);
        Serial.print("Off Led Topic");
      }
  }
  
  Serial.println();

  relayState = digitalRead(relay1Pin);
  if(topic=="test/relay") {
      if(messageLed == "1"){
        Serial.println ("turning Relay On");
         digitalWrite(relay1Pin, HIGH);
      }else if(messageLed == "0"){
        digitalWrite(relay1Pin, LOW);
         Serial.println ("turning Relay OFF");
        
      }
       
   
  } 

}

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect("ESP8266Client", user,pass)) {
      Serial.println("connected");
      // Once connected, publish an announcement...
      client.publish(relayTopic, "hello world");
      // ... and resubscribe
      client.subscribe(relayTopic);
      client.subscribe(ledTopic);
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}
void loop() {
 buttonState = digitalRead(btnPin);
// read the state of the relay PIN:
relayState = digitalRead(relay1Pin);

if (buttonState != lastBtnState) {

  if (relayState == HIGH) {
    digitalWrite(relay1Pin,LOW);
    //digitalWrite(ledPin,LOW);
    client.publish(relayTopic, "Apagado");
  }
 if (relayState == LOW) {
    digitalWrite(relay1Pin,HIGH);
    //digitalWrite(ledPin,HIGH);
    client.publish(relayTopic, "Encendido");
  }
lastBtnState= buttonState;
}
  if (!client.connected()) {
    reconnect();
  }
  client.loop();

delay(10); 
 
  
}

HAve that code to subscribe to more than one topic, but the thing is that i cant read a dht11 sensor and include in the IF section where it waits for the topic, something related to the type of data (string vs float) . I ve been trying to mix this code with the one here for dht22(changing to dht11) http://www.esp8266.com/viewtopic.php?f=29&t=8746. But still gettting errors… any help?

Thanks in advance

void callback(String topic, byte* message, unsigned int length) {

You cannot just go changing the expected return datatype without modifying the underlying library code as well.
Better to read the data in the expected *char format and then convert it to a String or forget about String and just compare the chars to your topic.

the thing is that i cant read a dht11 sensor and include in the IF section where it waits for the topic

I have no idea what "IF section where it waits for the topic" even means. The client.loop() function is what checks for subscribers having made a request. That is the function that calls the callback that you registered.

In loop(), you should certainly be able to read a dht11 sensor. In callback() (a really meaningless name for a function), you would simply provide the last sensor reading.

Hi ! Realized that i was doing a mess.. so i started again and completly understood that the message has to be sent and not received. Thanks!