| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- /*
- * Simple HTTP get webclient test
- */
- #include <ESP8266WiFi.h>
- const char* ssid = "hazard18";
- const char* password = "pu1f0xylu1";
- const char* host = "route69.hopto.org";
- void setup() {
- pinMode(0, OUTPUT);
-
- Serial.begin(115200);
- delay(100);
- // We start by connecting to a 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");
- Serial.println("IP address: ");
- Serial.println(WiFi.localIP());
- }
- int value = 0;
- void loop() {
- digitalWrite(0, HIGH);
- delay(5000);
- ++value;
- digitalWrite(0, LOW);
- Serial.print("connecting to ");
- Serial.println(host);
-
- // Use WiFiClient class to create TCP connections
- WiFiClient client;
- const int httpPort = 443;
- if (!client.connect(host, httpPort)) {
- Serial.println("connection failed");
- return;
- }
-
- // We now create a URI for the request
- String url = "/testwifi/index.html";
- Serial.print("Requesting URL (" + String(value) + ")" + " : ");
- Serial.println(url);
-
- // This will send the request to the server
- client.print(String("GET ") + url + " HTTP/1.1\r\n" +
- "Host: " + host + "\r\n" +
- "Connection: close\r\n\r\n");
- delay(500);
-
- // Read all the lines of the reply from server and print them to Serial
- while(client.available()){
- String line = client.readStringUntil('\r');
- Serial.print(line);
- }
-
- Serial.println();
- Serial.println("closing connection");
- }
|