Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WiFi.h>
- const char* ssid = "ezff";
- const char* password = "password";
- const uint8_t led = 2;
- WiFiServer server(10000);
- void setup() {
- Serial.begin(115200);
- WiFi.mode(WIFI_AP);
- WiFi.softAP(ssid, password);
- pinMode(led, OUTPUT); // set the LED pin mode
- server.setTimeout(5);
- server.begin();
- }
- void loop() {
- WiFiClient client = server.available();
- if (client) {
- Serial.println("got new client");
- String command = "";
- while (client.connected()) {
- if (client.available()) {
- Serial.println("client available");
- char c = client.read();
- if (c == 0) {
- break;
- } else if (c == ';') {
- command = "";
- } else {
- command += c;
- }
- // Check to see if the client request was "GET /H" or "GET /L":
- if (command.endsWith("LED(ON)")) {
- digitalWrite(led, HIGH);
- command = "";
- }
- if (command.endsWith("LED(OFF)")) {
- digitalWrite(led, LOW);
- command = "";
- }
- }else{
- delay(1000);
- Serial.println("client not available");
- Serial.println(errno);
- }
- }
- Serial.println("closing connection");
- // close the connection:
- client.stop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement