Created
November 13, 2016 21:17
-
-
Save yakutozcan/c0b9f4863f3fd0902b1cd00196349bab to your computer and use it in GitHub Desktop.
nodemcu tcp sample
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 | |
const char* ssid = "haydut";//kablosuz ağ adı | |
const char* password = "wifi_sifre"; | |
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"); | |
Serial.println("IP: "); | |
Serial.println(WiFi.localIP()); | |
server.begin(); | |
Serial.println("Server 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