Can someone pls tell me whats wrong with this code....
Button 2 doesnt work.
#include <ESP8266WiFi.h>
const char* ssid = "***";
const char* password = "***";
const char* host = "192.168.1.90";
// set pin numbers:
const int buttonPin1 = 5; // the number of the pushbutton pin 5
const int buttonPin2 = 4; // the number of the pushbutton pin 4
// variables will change:
int buttonState1 = 1; // variable for reading the pushbutton status
int buttonState2 = 1; // variable for reading the pushbutton status
void setup() {
WiFi.begin(ssid, password);
// initialize the LED pin as an output:
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
}
void loop(){
buttonState1 = digitalRead(buttonPin1);
if (buttonState1 == 0) {
// turn button on: //
delay(5000);
WiFiClient client;
const int httpPort1 = 80;
if (!client.connect(host, httpPort1)) {
Serial.println("connection failed");
return;
}
String url1 = "http://192.168.1.90/salvardados.php?teste1";
client.print(String("GET ") + url1 + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
unsigned long timeout = millis();
buttonState2 = digitalRead(buttonPin2);
}
//////////////////////////////////////button 2////////////////////////////////////
else if (buttonState2 == 0) {
// turn button on: //
delay(5000);
WiFiClient client;
const int httpPort2 = 80;
if (!client.connect(host, httpPort2)) {
Serial.println("connection failed");
return;
}
String url2 = "http://192.168.1.90/salvardados.php?teste2";
client.print(String("GET ") + url2 + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
unsigned long timeout = millis();
}
}