Hello
After a view runs (1-3) of the ServerDate() void i get "TCP connection failed". Can somebody help me?
#include <ESP8266WiFi.h>
const char* ssid = "*********";
const char* password = ""*********";";
const char* host = "myServer.com";
const char* streamId = "STREAMID";
const char* privateKey = "MEINSCHLUESSEL";
void setup() {
Serial.begin(115200);
delay(10);
// 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());
}
void ServerData(){
int value = 0;
WiFiClient client;
if (!client.connect(host, 80)) {
Serial.println("TCP connection failed");
return;
}
String url = "/input.php";
url += "?key=";
url += privateKey;
url += "&value=";
url += value;
// 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");
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> TCP Client Timeout !");
client.stop();
return;
}
}
// 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);
}
}
void loop() {
ServerData();
delay(10000);
}