#include <ESP8266WiFi.h>
const char* ssid = "The Secrets Of Life";
const char* password = "lliamsrouter";
const char* host = "192.168.1.20";
void setup() {
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() {
delay(5000);
++value;
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
Serial.println("Turn off");
// We now create a URI for the request
client.print("PUT /api/TSqJdEjKABMLd6d4crEiZ7toqKdcq2iR4BTFuMwW");
client.print("/lights/3");
client.println("/state HTTP/1.1");
client.println("Keep-Alive: max=5, timeout=300");
client.println("Connection: Keep-Alive");
client.println("Host: 192.168.1.20");
client.println("Content-Length: 12");
client.println("Content-Type: text/plain;charset=UTF-8");
client.println(); // blank line before body
client.println("{\"on\":false}");
delay(1500);
//THIS COMMAND NEVER RUNS
Serial.println("Turn on");
// We now create a URI for the request
client.print("PUT /api/TSqJdEjKABMLd6d4crEiZ7toqKdcq2iR4BTFuMwW");
client.print("/lights/3");
client.println("/state HTTP/1.1");
client.println("Connection: Close");
client.println("Host: 192.168.1.20");
client.println("Content-Length: 11");
client.println("Content-Type: text/plain;charset=UTF-8");
client.println(); // blank line before body
client.println("{\"on\":true}");
Serial.println();
Serial.println("closing connection");
}
Moderator: igrr