Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- const char* ssid = "ImplantWIFI";
- const char* password = "securepass2";
- String readString;
- int ledPin = 13; // GPIO13
- WiFiServer server(80);
- void setup() {
- Serial.begin(115200);
- //Serial1.begin(115200);
- delay(10);
- pinMode(ledPin, OUTPUT);
- digitalWrite(ledPin, LOW);
- // Connect to WiFi network
- // Serial.println();
- //Serial.println();
- // Serial.print("Connecting to ");
- //Serial.println(ssid);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- //Serial.print(".");
- }
- //Serial.println("");
- //Serial.println("WiFi connected");
- // Start the server
- server.begin();
- // Serial.println("Server started");
- // Print the IP address
- //Serial.print("Use this URL to connect: ");
- Serial.print("#");
- Serial.println(WiFi.localIP());
- //Serial.println("/");
- }
- void loop() {
- int index1;
- int index2;
- int value = LOW;
- String pogoString;
- //Serial.println(WiFi.localIP());
- // Check if a client has connected
- WiFiClient client = server.available();
- if (!client) {
- return;
- }
- // Wait until the client sends some data
- //Serial.println("new client");
- while(!client.available()){
- delay(1);
- }
- // Read the first line of the request
- String request = client.readStringUntil('\r');
- //Serial.println(request);
- client.flush();
- // Match the request
- if (request.indexOf("/LED=ON") != -1) {
- digitalWrite(ledPin, HIGH);
- value = HIGH;
- }
- if (request.indexOf("/LED=OFF") != -1) {
- digitalWrite(ledPin, LOW);
- value = LOW;
- }
- if (request.indexOf("command=") != -1){
- //Serial1.println(request.substring(request.indexOf("command=")+8));
- index1 = request.indexOf("command=")+8;
- index2 = request.indexOf("HTTP/1.1");
- Serial.println(request.substring(index1,index2));
- //Serial1.println(request.substring(index1,index2));
- readString="";
- delay(1000);
- while (Serial.available()) {
- delay(2); //delay to allow byte to arrive in input buffer
- char c = Serial.read();
- readString += c;
- }
- if (readString.length() >0) {
- // Serial.println(";");
- //Serial.println(readString);
- pogoString = readString;
- //Serial.print("ls ;");
- //Serial.println(pogoString);
- }
- }
- // Set ledPin according to the request
- //digitalWrite(ledPin, value);
- // Return the response
- client.println("HTTP/1.1 200 OK");
- client.println("Content-Type: text/html");
- client.println(""); // do not forget this one
- client.println("<!DOCTYPE HTML>");
- client.println("<html>");
- client.print("Led pin is now: ");
- if(value == HIGH) {
- client.print("On");
- } else {
- client.print("Off");
- }
- client.println("<br><br>");
- client.println("<a href=\"/LED=ON\"\"><button>Turn On </button></a>");
- client.println("<a href=\"/LED=OFF\"\"><button>Turn Off </button></a><br />");
- client.println("</html>");
- client.println("<br><br>");
- client.println("<form action=\"/action_page.php\">");
- client.println("Command: <input type=\"text\" name=\"command\"><br>");
- client.println(" <input type=\"submit\" value=\"Submit\">");
- client.println("</form>");
- client.println(readString);
- client.println("");
- client.println("</html>");
- delay(1);
- //Serial.println("Client disonnected");
- //Serial.println("");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement