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) {
- unsigned long timer = millis();
- Serial.println("got new client");
- String command = "";
- while (client.connected()) {
- while (client.available()) {
- char c = client.read();
- if (c == 0) {
- goto abort;
- } 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)")) {
- Serial.println("ON");
- digitalWrite(led, HIGH);
- command = "";
- }
- if (command.endsWith("LED(OFF)")) {
- Serial.println("OFF");
- digitalWrite(led, LOW);
- command = "";
- }
- }
- if (millis() - timer > 1000) {
- Serial.println("ping");
- client.write(";", 1);
- timer = millis();
- }
- }
- abort: Serial.println("closing connection");
- // close the connection:
- client.stop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement