NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

// Wi-Fi kütüphanesini yüklemek
#include <ESP8266WiFi.h>

// Bağlanacak sistemdeki kullanıcı adı ve şifreyi belirtmek
const char* ssid = "Admin";
const char* password = "Admin";

// Web server'ın port numarasını 80 olarak belirlemek
WiFiServer server(80);

// HTTP request'ini tutacak olan değişken
String header;

// Mevcut çıkış durumunu tutacak değişkenler
String output5State = "off";
String output4State = "off";

// GPIO1 ve GPIO2 pinleri
const int output5 = 5;
const int output4 = 4;

// Anlık sistem saati
unsigned long currentTime = millis();
// Önceki zaman değeri
unsigned long previousTime = 0;
// Timeout değeri belirlendi (Örneğin: 2000ms = 2s)
const long timeoutTime = 2000;

void setup() {
Serial.begin(115200);
// Çıkış pinleri belirlendi
pinMode(output5, OUTPUT);
pinMode(output4, OUTPUT);
// Çıkış pinlerine LOW değeri verildi
digitalWrite(output5, LOW);
digitalWrite(output4, LOW);

// Id ve şifreyi göndererek wifi ağına bağlanıldı
Serial.print("Şu adrese bağlanılıyor ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Ip adres bilgisi ve bağlanıldı bilgisi yazdırıldı
Serial.println("");
Serial.println("WiFi bağlandı.");
Serial.println("IP addresi: ");
Serial.println(WiFi.localIP());
server.begin(); // Server başlatıldı
}

void loop(){
WiFiClient client = server.available(); // Server aktiflik durumu kontrol edildi

if (client) { // Eğer server bağlantısı devam ediyorsa
Serial.println("Yeni Client."); // Mesaj yazdırıldı
String currentLine = ""; // Client'den dönen değeri tutacak olan değişken
currentTime = millis(); // Anlık saat değeri yakalandı
previousTime = currentTime;
while (client.connected() && currentTime - previousTime <= timeoutTime) { // Client bağlı olduğu sürece sürecek döngü
currentTime = millis();
if (client.available()) { // Client'den okunacak bir değer var ise
char c = client.read(); // Byte okundu
Serial.write(c); // Seri monitörde yazdırıldı
header += c;
if (c == 'n') { // Eğer okunan byte değeri yeni satır değeri ise
// Eğer yeni satır boş ise 2 adet /n olmalıdır
// Bu request'in sonu demektir ardından cevap gönderilmelidir
if (currentLine.length() == 0) {
// HTTP üst satırları daima yanıt koduyla başlar ( Örn: 201 , 404 vs)
// ve istemcinin ne olduğunu bilmesi için bir içerik türüyle başlar, ardından boş bir satır gelir
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();

// GDPIO'ları açmak ve kapamak işlemleri
if (header.indexOf("GET /5/on") >= 0) {
Serial.println("GPIO 5 on");
output5State = "on";
digitalWrite(output5, HIGH);
} else if (header.indexOf("GET /5/off") >= 0) {
Serial.println("GPIO 5 off");
output5State = "off";
digitalWrite(output5, LOW);
} else if (header.indexOf("GET /4/on") >= 0) {
Serial.println("GPIO 4 on");
output4State = "on";
digitalWrite(output4, HIGH);
} else if (header.indexOf("GET /4/off") >= 0) {
Serial.println("GPIO 4 off");
output4State = "off";
digitalWrite(output4, LOW);
}

// HTML sayfasını görüntüleme
client.println("<!DOCTYPE html><html>");
client.println("<head><meta name="viewport" content="width=device-width, initial-scale=1">");
client.println("<link rel="icon" href="data:,">");
// Aç/Kapa butonlarını stillendirmek için Css bilgileri

client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");
client.println(".button { background-color: #195B6A; border: none; color: white; padding: 16px 40px;");
client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");
client.println(".button2 {background-color: #77878A;}</style></head>");

// Web sayfası body'si ayarlanmaya başlandı
client.println("<body><h1>ESP8266 Web Server</h1>");

// GPIO 5 için mevcut durumu ve AÇMA/KAPAMA düğmelerini görüntüleme
client.println("<p>GPIO 5 - State " + output5State + "</p>");
// Eğer output5State kapalıysa, açma butonunu görüntüler
if (output5State=="off") {
client.println("<p><a href="/5/on"><button class="button">ON</button></a></p>");
} else {
client.println("<p><a href="/5/off"><button class="button button2">OFF</button></a></p>");
}

// GPIO 4 için mevcut durumu ve AÇMA/KAPAMA düğmelerini görüntüler
client.println("<p>GPIO 4 - State " + output4State + "</p>");
// Eğer output4State kapalıysa, açma düğmesini görüntüler.
if (output4State=="off") {
client.println("<p><a href="/4/on"><button class="button">ON</button></a></p>");
} else {
client.println("<p><a href="/4/off"><button class="button button2">OFF</button></a></p>");
}
client.println("</body></html>");

// HTTP yanıtı başka bir boş satırla bitiyor
client.println();
// while döngüsünden çıkıldı
break;
} else {
currentLine = "";
}
} else if (c != 'r') { // satır başı karakterinden başka bir karakter var ise
currentLine += c; // bunu currentLine'ın sonuna eklemek gerekir
}
}
}
// header değişkeninin sıfırlanması gerekir
header = "";
// Bağlantının kapatılması
client.stop();
Serial.println("Client bağlantısı kesildi.");
Serial.println("");
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.