The code is supposed to create a soft ap, and whenever the button is pushed, it should send a '1' to the client, causing the pin to go HIGH, and whenever it is not pushed, set the pin to LOW. This behavior is not displayed, and I am not sure what is causing it.
server:
#include <ESP8266WiFi.h>
IPAddress local_IP(192,168,0,1);
IPAddress gateway(192,168,4,9);
IPAddress subnet(255,255,255,0);
WiFiServer server(80);
int laststate = 0;
void setup() {
WiFi.softAPConfig(local_IP, gateway, subnet);
WiFi.softAP("Button");
server.begin();
}
void loop() {
WiFiClient client = server.available();
while (client.connected() == true) {
if (client) {
while (digitalRead(1) == HIGH) {
if (laststate == 0) {
client.println(1);
laststate == 1;
}
else {
if (digitalRead(1) == LOW) {
if (laststate == 1) {
client.println(0);
}
laststate == 0;
}
}
}
}
while (client.available()== true) {
client.read();
}
}
}
client:
#include <ESP8266WiFi.h>
WiFiClient client;
void setup() {
WiFi.begin("button");
client.connect("192.168.0.1", 80);
}
void loop() {
while (client.read() == 1) {
digitalWrite(1, HIGH);
}
digitalWrite(1,LOW);
}