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);
}
client.connect()succeeds. Put in some debugging messages. Right now you can't tell if you get a 1 or not. Output a message if you do. If you strip out the network code does your code successfully light up the LED or not? Find out what your code is doing by adding in debugging messages and go from there.WiFi.mode(WIFI_STA);. if it helps I will write an answerWiFi.mode(WIFI_STA);beforeWiFi.begin("button");. and in the other sketch change toIPAddress local_IP(192,168,4,1);