Hello i have a problem with my code:
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
WiFiClient client;
const char* ssid = "WTC";
const char* password = "****";
int device1_pin = D0;
int device2_pin = D1;
int device3_pin = D2;
int device4_pin = D3;
int device5_pin = D4;
int device6_pin = D5;
int device_status1;
int device_status2;
int device_status3;
int device_status4;
int device_status5;
int device_status6;
void setup () {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting..");
}
pinMode(device1_pin,OUTPUT);
pinMode(device2_pin,OUTPUT);
pinMode(device3_pin,OUTPUT);
pinMode(device4_pin,OUTPUT);
pinMode(device5_pin,OUTPUT);
pinMode(device6_pin,OUTPUT);
}
void loop() {
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
WiFiClientSecure client;
client.setInsecure();
HTTPClient http; //Declare an object of class HTTPClient
/*----------------------------------------------*/
http.begin(client,"https://*******/data/device_status.php?did=1"); //Specify request destination
int httpCode1 = http.GET(); //Send the request
if (httpCode1 > 0) { //Check the returning code
String payload = http.getString(); //Get the request response payload
device_status1 = payload.toInt();
//Serial.print(httpCode1);
Serial.println();
Serial.print(payload);
Serial.println();
Serial.print("Device 1 Status=");
Serial.print(device_status1); //Print the response payload
Serial.println();
delay(1500);
}
/*----------------------------------------------*/
http.begin(client,"****datta/device_status.php?did=2"); //Specify request destination
int httpCode2 = http.GET(); //Send the request
if (httpCode2 > 0) { //Check the returning code
String payload = http.getString(); //Get the request response payload
device_status2 = payload.toInt();
Serial.println();
Serial.print(payload);
Serial.println();
Serial.print("Device 2 Status=");
Serial.print(device_status2); //Print the response payload
Serial.println();
delay(1500);
}
/*----------------------------------------------*/
http.begin(client,"https://********/data/device_status.php?did=3"); //Specify request destination
int httpCode3 = http.GET(); //Send the request
if (httpCode3 > 0) { //Check the returning code
String payload = http.getString(); //Get the request response payload
device_status3 = payload.toInt();
Serial.println();
Serial.print(payload);
Serial.println();
Serial.print("Device 3 Status=");
Serial.print(device_status3); //Print the response payload
Serial.println();
delay(1500);
}
/*----------------------------------------------*/
http.begin(client,"https://*****/data/device_status.php?did=4"); //Specify request destination
int httpCode4 = http.GET(); //Send the request
if (httpCode4 > 0) { //Check the returning code
String payload = http.getString(); //Get the request response payload
device_status4 = payload.toInt();
Serial.println();
Serial.print(payload);
Serial.println();
Serial.print("Device 4 Status=");
Serial.print(device_status4); //Print the response payload
Serial.println();
delay(1500);
}
http.begin(client,"https://*******/data/device_status.php?did=5"); //Specify request destination
int httpCode5 = http.GET(); //Send the request
if (httpCode5 > 0) { //Check the returning code
String payload = http.getString(); //Get the request response payload
device_status5 = payload.toInt();
Serial.println();
Serial.print(payload);
Serial.println();
Serial.print("Device 5 Status=");
Serial.print(device_status5); //Print the response payload
Serial.println();
delay(1500);
}
http.begin(client,"https://*******/data/device_status.php?did=6"); //Specify request destination
int httpCode6 = http.GET(); //Send the request
if (httpCode6 > 0) { //Check the returning code
String payload = http.getString(); //Get the request response payload
device_status6 = payload.toInt();
Serial.println();
Serial.print(payload);
Serial.println();
Serial.print("Device 6 Status=");
Serial.print(device_status6); //Print the response payload
Serial.println();
delay(1500);
}
http.end(); //Close connection
}
delay(5500);
if(device_status1 == 1){
digitalWrite(device1_pin,LOW);
Serial.println("Device 1 ON");
}else if(device_status1 == 0){
digitalWrite(device1_pin,HIGH);
Serial.println("Device 1 OFF");
}
if(device_status2 == 1){
digitalWrite(device2_pin,LOW);
Serial.println("Device 2 ON");
}else if(device_status2 == 0){
digitalWrite(device2_pin,HIGH);
Serial.println("Device 2 OFF");
}
if(device_status3 == 1){
digitalWrite(device3_pin,LOW);
Serial.println("Device 3 ON");
}else if(device_status3 == 0){
digitalWrite(device3_pin,HIGH);
Serial.println("Device 3 OFF");
}
if(device_status4 == 1){
digitalWrite(device4_pin,LOW);
Serial.println("Device 4 ON");
}else if(device_status4 == 0){
digitalWrite(device4_pin,HIGH);
Serial.println("Device 4 OFF");
}
if(device_status5 == 1){
digitalWrite(device5_pin,LOW);
Serial.println("Device 5 ON");
}else if(device_status5 == 0){
digitalWrite(device5_pin,HIGH);
Serial.println("Device 5 OFF");
}
if(device_status6 == 1){
digitalWrite(device6_pin,LOW);
Serial.println("Device 6 ON");
}else if(device_status6 == 0){
digitalWrite(device6_pin,HIGH);
Serial.println("Device 6 OFF");
}
delay(15000);
}
Evething is ok, Serial.print(payload) write 1 or 0 from my web page, but device_status1 is still 0
Where I make a mistake?