Advertisement
Guest User

Untitled

a guest
Jul 9th, 2017
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include <WiFi.h>
  2.  
  3. const char* ssid = "ezff";
  4. const char* password = "password";
  5.  
  6. const uint8_t led = 2;
  7.  
  8. WiFiServer server(10000);
  9.  
  10. void setup() {
  11.     Serial.begin(115200);
  12.     WiFi.mode(WIFI_AP);
  13.     WiFi.softAP(ssid, password);
  14.  
  15.     pinMode(led, OUTPUT);      // set the LED pin mode
  16.  
  17.     server.setTimeout(5);
  18.     server.begin();
  19. }
  20.  
  21. void loop() {
  22.     WiFiClient client = server.available();
  23.  
  24.     if (client) {
  25.         Serial.println("got new client");
  26.         String command = "";
  27.         while (client.connected()) {
  28.             if (client.available()) {
  29.                 Serial.println("client available");
  30.                 char c = client.read();
  31.                 if (c == 0) {
  32.                     break;
  33.                 } else if (c == ';') {
  34.                     command = "";
  35.                 } else {
  36.                     command += c;
  37.                 }
  38.  
  39.                 // Check to see if the client request was "GET /H" or "GET /L":
  40.                 if (command.endsWith("LED(ON)")) {
  41.                     digitalWrite(led, HIGH);
  42.                     command = "";
  43.                 }
  44.                 if (command.endsWith("LED(OFF)")) {
  45.                     digitalWrite(led, LOW);
  46.                     command = "";
  47.                 }
  48.             }else{
  49.                 delay(1000);
  50.                 Serial.println("client not available");
  51.                 Serial.println(errno);
  52.             }
  53.         }
  54.         Serial.println("closing connection");
  55.         // close the connection:
  56.         client.stop();
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement