Skip to content

Instantly share code, notes, and snippets.

@michaelsarduino
Created September 27, 2015 14:16
Show Gist options
  • Save michaelsarduino/ae7cd6ec72d319391764 to your computer and use it in GitHub Desktop.
Save michaelsarduino/ae7cd6ec72d319391764 to your computer and use it in GitHub Desktop.
#include <ESP8266WiFi.h>
const char* ssid = "WLAN HORNISSENWEG 4";
const char* password = "unserpasswort";
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
// Start the server
server.begin();
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
while(!client.available()){
delay(1);
}
// Read the first line of the request
String req = client.readStringUntil('\r');
client.flush();
String html = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html> <h3> LED 1 </h3><form action=\"192.168.178.30/index.html\" method=\"GET\"> <input type=\"radio\" name=\"led1\" value=\"1\" />AN <br /> <input type=\"radio\" name=\"led1\" value=\"0\" />AUS <br /> <input type=\"submit\" name=\"absenden\" value=\"schalten!\" /><br /></form></html>\n";
// Match the request
int val = -1;
if (req.indexOf("?led1=0") != -1)
val = 0;
else if (req.indexOf("?led1=1") != -1)
val = 1;
else if(req.indexOf("/index.html") != -1)
client.print(html);
else {
//Serial.println("invalid request");
client.stop();
return;
}
if(val != -1)
{
Serial.println(val);
client.flush();
// Send the response to the client
client.print(html);
delay(1);
}
}
@hafizhullah
Copy link

cara buat bikin saklarnya di web gmana

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment