Picproje Elektronik Sitesi

ENDÜSTRiYEL OTOMASYON => IoT => Konuyu başlatan: larions4 - 05 Aralık 2017, 23:53:57

Başlık: Esp8266-12E nodemcu Server Adresine http Üzerinden Ulaşamıyorum
Gönderen: larions4 - 05 Aralık 2017, 23:53:57
Merhabalar esp8266 ya arduino ide ile iletişim kurup istediğim kodları gönderiyorum. Webserver kodlarını gönderdiğimde seri port ekranında wifi connected ve server started bilgilendirmesi ve esp nin ip si geliyor. Fakat esp nin ip sine chrome üzerinden bağlanmaya çalıştığımda bağlantı etkin olarak redediliyor. Esp nin enerjisini kesip o şekilde ip ye bağlanmaya çalışınca bir süre bekledikten sonra zaman aşımı hatası alıyorum. Burdan esp nin etkin olarak redettiğini saptadım. Kodlarım şu şekilde:

#include <ESP8266WiFi.h>

const char* ssid = "your-ssid";
const char* password = "your-password";

// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);

void setup() {
  Serial.begin(115200);
  delay(10);

  // prepare GPIO2
  pinMode(2, OUTPUT);
  digitalWrite(2, 0);
 
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.println(WiFi.localIP());
}

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
 
  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
 
  // Read the first line of the request
  String req = client.readStringUntil('\r');
  Serial.println(req);
  client.flush();
 
  // Match the request
  int val;
  if (req.indexOf("/gpio/0") != -1)
    val = 0;
  else if (req.indexOf("/gpio/1") != -1)
    val = 1;
  else {
    Serial.println("invalid request");
    client.stop();
    return;
  }

  // Set GPIO2 according to the request
  digitalWrite(2, val);
 
  client.flush();

  // Prepare the response
  String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
  s += (val)?"high":"low";
  s += "</html>\n";

  // Send the response to the client
  client.print(s);
  delay(1);
  Serial.println("Client disonnected");


Herhangi bir yerde yanlışlık mı yapıyorum yada eksik bir yer varsa yazarsanız çok sevinirim.