Created
September 17, 2017 13:37
-
-
Save yakutozcan/08d45dabd1b79309bd2ee0785f8d43b1 to your computer and use it in GitHub Desktop.
socketio, TCP, Web uygulamalari
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
#include <ESP8266WiFi.h> | |
#define SERVER_PORT 1907 //TCP Port | |
const char* ssid = "özcan";//kablosuz ağ adı | |
const char* password = "wifiSifre";//kablosuz ağ şifresi | |
WiFiServer server(SERVER_PORT); | |
void setup() | |
{ | |
pinMode(LED_BUILTIN, OUTPUT); | |
digitalWrite(LED_BUILTIN, LOW); | |
delay(500); | |
digitalWrite(LED_BUILTIN, HIGH); | |
Serial.begin(115200); | |
Serial.println(""); | |
Serial.println(""); | |
WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) | |
{ delay(500); | |
Serial.print("."); | |
} | |
Serial.println("WiFi Baglandi"); | |
//Statik ip ayarları | |
IPAddress ip(192, 168, 1, 103); | |
IPAddress gateway(192, 168, 1, 1); | |
Serial.print(F("Statik ip: ")); | |
Serial.println(ip); | |
IPAddress subnet(255, 255, 255, 0); | |
WiFi.config(ip, gateway, subnet); | |
server.begin(); | |
Serial.println("Sunucu Basladi"); | |
} | |
void loop() | |
{ WiFiClient client = server.available(); | |
if (client) | |
{ | |
Serial.print("Yeni Client"); | |
Serial.println(client); | |
while (1) | |
{ while (client.available()) | |
{ uint8_t data = client.read(); | |
Serial.print(char(data)); | |
if (char(data) == 'H') { | |
Serial.println(" Acik"); | |
client.write("Acik"); | |
//Nedendir bilmem ters | |
digitalWrite(LED_BUILTIN, LOW); | |
} | |
if (char(data) == 'L') { | |
Serial.println(" Kapali"); | |
client.write("Kapali"); | |
digitalWrite(LED_BUILTIN, HIGH); | |
} | |
} | |
if (server.hasClient()) | |
{ return; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment