title: ESP8266 Push button - pin State stay the same
body: <p>Wanted to do some IOT stuff so I bought an ESP8266 (WeMos D1 Mini Pro).</p>
  
  <p>I wanted to send a MQTT message to my server only if I push a button.</p>
  
  <p>I wired on side of the button to the GNR and the other side to D6 (GPIO12).</p>
  
  <p>I set <code>pinMode(12, INPUT);</code></p>
  
  <p>and inside the loop :</p>
  
  <pre><code>void loop() {
  
    if (!client.connected()) {
      reconnect();
    }
    client.loop();
  
    boolean pinState = digitalRead(12);
  
    Serial.printf("Start State: %s",(pinState)?"HIGH":"LOW");
    Serial.println();
    if (pinState == LOW) {
      const char* test2 = "Test";
      Serial.print("Publish message: ");
      Serial.println(test2);
      client.publish("iPub", test2);
    }
  }
  </code></pre>
  
  <p>pinState start at <code>HIGH</code> and I can see it looping. When I press the button it change to <code>LOW</code> (send the message), enter the if statement and the pin state continue to be <code>LOW</code>. So it cannot stop sending a message. But when I release the button the pin should change it's state ?</p>
  
  <p>I tried to add an <code>pinState = !pinState;</code> inside the if but the state stay <code>LOW</code> after that.</p>
  
  <p>How can I solve this ?</p>