Advertisement
Guest User

POGO implant server

a guest
Dec 5th, 2019
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.47 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2.  
  3. const char* ssid = "ImplantWIFI";
  4. const char* password = "securepass2";
  5. String readString;
  6. int ledPin = 13; // GPIO13
  7. WiFiServer server(80);
  8.  
  9. void setup() {
  10.   Serial.begin(115200);
  11.   //Serial1.begin(115200);
  12.   delay(10);
  13.  
  14.   pinMode(ledPin, OUTPUT);
  15.   digitalWrite(ledPin, LOW);
  16.  
  17.   // Connect to WiFi network
  18.  // Serial.println();
  19.   //Serial.println();
  20.  // Serial.print("Connecting to ");
  21.   //Serial.println(ssid);
  22.  
  23.   WiFi.begin(ssid, password);
  24.  
  25.   while (WiFi.status() != WL_CONNECTED) {
  26.     delay(500);
  27.     //Serial.print(".");
  28.   }
  29.   //Serial.println("");
  30.   //Serial.println("WiFi connected");
  31.  
  32.   // Start the server
  33.   server.begin();
  34.  // Serial.println("Server started");
  35.  
  36.   // Print the IP address
  37.   //Serial.print("Use this URL to connect: ");
  38.   Serial.print("#");
  39.   Serial.println(WiFi.localIP());
  40.   //Serial.println("/");
  41.  
  42. }
  43.  
  44. void loop() {
  45.   int index1;
  46.   int index2;
  47.   int value = LOW;
  48.   String pogoString;
  49.   //Serial.println(WiFi.localIP());
  50.   // Check if a client has connected
  51.   WiFiClient client = server.available();
  52.   if (!client) {
  53.     return;
  54.   }
  55.  
  56.   // Wait until the client sends some data
  57.   //Serial.println("new client");
  58.   while(!client.available()){
  59.     delay(1);
  60.   }
  61.  
  62.   // Read the first line of the request
  63.   String request = client.readStringUntil('\r');
  64.   //Serial.println(request);
  65.   client.flush();
  66.  
  67.   // Match the request
  68.  
  69.   if (request.indexOf("/LED=ON") != -1)  {
  70.     digitalWrite(ledPin, HIGH);
  71.     value = HIGH;
  72.   }
  73.   if (request.indexOf("/LED=OFF") != -1)  {
  74.     digitalWrite(ledPin, LOW);
  75.     value = LOW;
  76.   }
  77.  
  78.   if (request.indexOf("command=") != -1){
  79.       //Serial1.println(request.substring(request.indexOf("command=")+8));
  80.       index1 = request.indexOf("command=")+8;
  81.       index2 = request.indexOf("HTTP/1.1");
  82.       Serial.println(request.substring(index1,index2));
  83.       //Serial1.println(request.substring(index1,index2));
  84.       readString="";
  85.       delay(1000);
  86.       while (Serial.available()) {
  87.         delay(2);  //delay to allow byte to arrive in input buffer
  88.         char c = Serial.read();
  89.         readString += c;
  90.       }
  91.    
  92.       if (readString.length() >0) {
  93.        // Serial.println(";");
  94.         //Serial.println(readString);
  95.         pogoString = readString;
  96.         //Serial.print("ls ;");
  97.         //Serial.println(pogoString);
  98.        
  99.       }
  100.      
  101.   }
  102.  
  103. // Set ledPin according to the request
  104. //digitalWrite(ledPin, value);
  105.  
  106.   // Return the response
  107.   client.println("HTTP/1.1 200 OK");
  108.   client.println("Content-Type: text/html");
  109.   client.println(""); //  do not forget this one
  110.   client.println("<!DOCTYPE HTML>");
  111.   client.println("<html>");
  112.  
  113.   client.print("Led pin is now: ");
  114.  
  115.   if(value == HIGH) {
  116.     client.print("On");
  117.   } else {
  118.     client.print("Off");
  119.   }
  120.   client.println("<br><br>");
  121.   client.println("<a href=\"/LED=ON\"\"><button>Turn On </button></a>");
  122.   client.println("<a href=\"/LED=OFF\"\"><button>Turn Off </button></a><br />");  
  123.   client.println("</html>");
  124.  
  125.   client.println("<br><br>");
  126.   client.println("<form action=\"/action_page.php\">");
  127.   client.println("Command: <input type=\"text\" name=\"command\"><br>");  
  128.   client.println(" <input type=\"submit\" value=\"Submit\">");
  129.   client.println("</form>");  
  130.   client.println(readString);
  131.   client.println("");  
  132.   client.println("</html>");
  133.  
  134.   delay(1);
  135.   //Serial.println("Client disonnected");
  136.   //Serial.println("");
  137.  
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement