Created
May 14, 2018 23:34
-
-
Save palmerabollo/ed379dcc5af0c0440da69a53e02e8b69 to your computer and use it in GitHub Desktop.
HTTP server with ESP32/ESP8266
This file contains hidden or 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
// Legacy HTTP-based approach. | |
// For it to work, you need to call server.begin(); in the setup function and declare a WiFiServer server(80); | |
// see https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/SimpleWiFiServer/SimpleWiFiServer.ino | |
if (incomingClient) { | |
Serial.println("client connect"); | |
digitalWrite(LED_PIN, LOW); // LOW = ON | |
while (incomingClient.connected()) { | |
if (incomingClient.available() > 0) { | |
char command = incomingClient.read(); | |
switch (command) { | |
case '0': | |
digitalWrite(RELAY_PIN, LOW); | |
break; | |
case '1': | |
digitalWrite(RELAY_PIN, HIGH); | |
break; | |
case '\n': | |
incomingClient.stop(); | |
break; | |
} | |
} | |
} | |
incomingClient.stop(); | |
Serial.println("client disconnect"); | |
digitalWrite(LED_PIN, HIGH); // HIGH = OFF | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
client