Hi dears,
I want to program node mcu as an accesspoint that when the state of one of the pins of the node changed,it send me "start" or "stop" on webserver.
I wrote my codes,and I didn't get any error but "start" is only shown on the webserver.
thank you all for your helps.
and I will attach my codes.
[tt]
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
const int buttonPin = 0;
int buttonState = 0;
int lastButtonState = 0;
int x =100;
const char* ssid = "ESPWebServer";
const char* password = "12345678";
ESP8266WebServer server(80); //Server on port 80
//==============================================================
// This rutine is exicuted when you open its IP in browser
//==============================================================
void handleRoot() {
server.send(200, "text/plain", "start");
}
void handleRoot1(){
server.send(200, "text/plain", "stop");
}
//===============================================================
// SETUP
//===============================================================
void setup(void){
pinMode(buttonPin, INPUT);
Serial.begin(115200);
Serial.begin(115200);
Serial.println("");
WiFi.mode(WIFI_AP); //Only Access point
WiFi.softAP(ssid, password); //Start HOTspot removing password will disable security
IPAddress myIP = WiFi.softAPIP(); //Get IP address
Serial.print("HotSpt IP:");
Serial.println(myIP);
server.on("/", handleRoot); //Which routine to handle at root location
server.begin(); //Start server
Serial.println("HTTP server started");
}
//===============================================================
// LOOP
//===============================================================
void loop(void){buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
handleRoot();
} else {
handleRoot1();
}
delay(50);
}
lastButtonState = buttonState;
server.handleClient(); //Handle client requests
}
[/tt]