Created
August 13, 2018 05:05
-
-
Save nkenna/fc1b4c040947f014f04479c49e7e616b to your computer and use it in GitHub Desktop.
creates server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Create a WiFi access point and provide a web server on it. */ | |
#include <ESP8266WiFi.h> | |
#include <WiFiClient.h> | |
#include <ESP8266WebServer.h> | |
/* Set these to your desired credentials. */ | |
const char *ssid = "*********"; | |
const char *password = "***********"; | |
boolean ledState = false; | |
ESP8266WebServer server(80); | |
/* Just a little test message. Go to http://192.168.4.1 in a web browser | |
connected to this access point to see it. | |
*/ | |
void handleRoot() { | |
server.send(200, "text/html", "<h1>You are connected</h1>"); | |
} | |
void setup() { | |
pinMode(BUILTIN_LED, OUTPUT); | |
delay(1000); | |
Serial.begin(115200); | |
Serial.println(); | |
Serial.print("Configuring access point..."); | |
/* You can remove the password parameter if you want the AP to be open. */ | |
WiFi.softAP(ssid, password); | |
IPAddress myIP = WiFi.softAPIP(); | |
Serial.print("AP IP address: "); | |
Serial.println(myIP); | |
server.on("/", handleRoot); | |
server.on("/steinacoz/led", controlLED); | |
server.begin(); | |
Serial.println("HTTP server started"); | |
} | |
void controlLED() { | |
ledState = !ledState; | |
if(ledState == true){ | |
digitalWrite(BUILTIN_LED, ledState); | |
server.send(200, "text/plain", "LED OFF"); | |
Serial.println("led OFF"); | |
}else{ | |
digitalWrite(BUILTIN_LED, ledState); | |
server.send(200, "text/plain", "LED ON"); | |
Serial.println("led ON"); | |
} | |
} | |
void loop() { | |
server.handleClient(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment