title: MQTT code stops working after a couple of hours
body: <p>Made some code for a NodeMCU in the Arduino IDE to push a button using MQTT. The code works perfectly fine for some time, but after a couple of hours it will not respond anymore.</p>
  
  <p>The code is very frankenstein, since I am a mega rookie, and is as follows: </p>
  
  <pre><code>#include &lt;ESP8266WiFi.h&gt;
  #include &lt;PubSubClient.h&gt;
  #include &lt;Servo.h&gt;
  
  const char* ssid = "ap_name"; //change
  const char* password =  "ap_pw"; //change
  const char* mqttServer = "server_ip"; //change
  const int mqttPort = 1883; 
  const char* mqttUser = "server_name"; //change
  const char* mqttPassword = "server_pw"; //change
  
  WiFiClient espClient;
  PubSubClient client(espClient);
  
  Servo servo;
  
  void setup() {
    Serial.begin(115200); 
    WiFi.begin(ssid, password);
  
    servo.attach(D4);
    servo.write(70);
  
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.println("Connecting to WiFi..");
    }
    Serial.println("Connected to the WiFi network");
  
    client.setServer(mqttServer, mqttPort);
    client.setCallback(callback);
  
    while (!client.connected()) {
      Serial.println("Connecting to MQTT...");
  
      if (client.connect("ESP8266Client", mqttUser, mqttPassword )) {
  
        Serial.println("connected");  
  
      } else {
  
        Serial.print("failed with state ");
        Serial.print(client.state());
        delay(2000);
  
      }
    }
  
    client.publish("esp/test", "Hello from ESP8266");
    client.subscribe("esp/test");
  
  }
  
  void callback(char* topic, byte* payload, unsigned int length) {
  
    Serial.print("Message arrived in topic: ");
    Serial.println(topic);
  
    Serial.print("Message:");
    for (int i = 0; i &lt; length; i++) {
      Serial.print((char)payload[i]);
    }
  
    if(*payload == 49){
      rotServo();
      Serial.println();
      Serial.print("Roterar servo");
      delay(3000);
      client.publish("esp/test", "0");
    }
  
    Serial.println();
    Serial.println("-----------------------");
  
  }
  
  void rotServo(){
    servo.attach(D4);
    servo.write(70);
    delay(1000);
    servo.write(175);
    delay(2000);
    servo.write(70);
    delay(3000);
    servo.detach();
  }
  
  void loop() {
    client.loop();
  }
  </code></pre>
  
  <p>Anyone that would know what might be causing it to stop working? </p>