title: How to fix arduino program to blink LED based on mqtt message
body: <p>I am doing program on Arduino IDE with goal to blink LED on breadboard with NodeMCU whenever it receives ON message from MQTT topic.I have done the program but the LED is not blinking. If I do the program removing MQTT portion, things are fine. Might be I am doing something wrong in loop().</p>
  
  <p>I created MQTT topic using Node-Red.When I tested publish-subscription on Node Red, the flow is working as expected. But when I am trying to read the message from arduino, I dont see LED changing it's state.</p>
  
  <p>Copying relevant portion of the code-</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;ESP8266WiFi.h&gt;
  #include &lt;PubSubClient.h&gt;
  
  // Update these with values suitable for your network.
  const char* ssid = "NET";
  const char* password = "xx";
  const char* mqtt_server = "192.x.x.x";
  const int lamp = 4;
  
  WiFiClient espClient;
  PubSubClient client(espClient);
  long lastMsg = 0;
  char msg[50];
  int value = 0;
  
  void callback(char* topic, byte* payload, unsigned int length) {
      Serial.print("Message arrived [");
      Serial.print(topic);
      Serial.print("] ");
      String messageTemp;
  
      for (int i = 0; i &lt; length; i++) {
          Serial.print((char)payload[i]);
          messageTemp += (char)payload[i];
      }
      Serial.println();
      Serial.println("messageTemp-"+messageTemp);
  
      if (topic=="room/lamp") {
          Serial.print("Changing Room lamp to ");
          if (messageTemp == "on") {
              digitalWrite(lamp, LOW);
              Serial.print("On");
          }
          else if (messageTemp == "off") {
              digitalWrite(lamp, HIGH);
              Serial.print("Off");
          }
      }
      Serial.println();
  }
  
  void setup() {
      pinMode(lamp, OUTPUT);
      Serial.begin(9600);
      setup_wifi();
      client.setServer(mqtt_server, 1883);
      client.setCallback(callback);
  }
  
  void loop() {
      if (!client.connected()) {
          reconnect();
      }
      client.loop();
  }
  </code></pre>
  
  <p>I expect whenever I am pushing ON and OFF messages on the topic 'room/lamp' from nodered, the LED should get turned on and off.But it is not happening now.I am new to Arduino.Please advise.</p>