Created
October 5, 2015 18:08
-
-
Save michaelsarduino/0b4119c6e6933bb8c348 to your computer and use it in GitHub Desktop.
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> | |
#include <WiFiClient.h> | |
#include <WiFiServer.h> | |
#include <ESP8266WebServer.h> | |
#include <ESP8266mDNS.h> | |
#include <SPI.h> | |
char ssid[] = "*******************"; //WLAN Netzwerk | |
char pass[] = "***************"; //WLAN Passwort | |
int status = WL_IDLE_STATUS; | |
char server[] = "michaelsarduino.blogspot.de"; //Webserver | |
WiFiClient client; | |
void setup() { | |
Serial.begin(115200); | |
while (status != WL_CONNECTED) { | |
Serial.print("Attempting to connect to SSID: "); | |
Serial.println(ssid); | |
//mit Wlan Netzwerk verbinden | |
status = WiFi.begin(ssid, pass); | |
//kurzes warten fuer Verbindungsversuch | |
delay(10000); | |
} | |
Serial.println("Connected to wifi"); | |
printWifiStatus(); | |
Serial.println("\nStarting connection to server..."); | |
//Ausgabe ueber serielle Verbindung | |
if (client.connect(server, 80)) { | |
Serial.println("connected to server"); | |
client.println("GET /index.html HTTP/1.1"); // /index.html durch gewuenschte Unterseite ersetzen (index.html = Startseite) | |
client.println("Host: michaelsarduino.blogspot.de"); //Adresse des Webservers | |
client.println("Connection: close"); | |
client.println(); //Verbindungs mit Server aufbauen und HTTP Anfrage senden | |
} | |
} | |
void loop() { | |
while (client.available()) { | |
char c = client.read(); | |
Serial.write(c); | |
} //Ausgabe des empfangenen HTML Codes | |
if (!client.connected()) { | |
Serial.println(); | |
Serial.println("disconnecting from server."); | |
client.stop(); | |
//Beenden der Verbindung | |
while (true); | |
} | |
} | |
void printWifiStatus() { | |
//Ausgabe des WLan Netzwerks | |
Serial.print("SSID: "); | |
Serial.println(WiFi.SSID()); | |
//Ausgabe IP Adresse | |
IPAddress ip = WiFi.localIP(); | |
Serial.print("IP Address: "); | |
Serial.println(ip); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment