websites get data

hi friends...i get data to websites

serial monitor is data payload=1

arduino code is

digitalWrite(2, payload);

but circuit is not working...why could it be

There is a bug in the code you have not posted. Please post the entire sketch, otherwise we can't tell you what the problem is.

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

const char* ssid = "Kablonet_Netmaster-FAF6-G";
const char* password = "mortMen20122111";

void setup() {

  Serial.begin(115200); // Start the serial monitor.
  pinMode(2, OUTPUT); // Set GPIO2 as an OUTPUT.
  digitalWrite(2, 0); // Start off.
  
  Serial.println("Hello Digital Craft");
  Serial.println("connecting");

  WiFi.begin(ssid,password);


  // Show ... until connected:
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("WiFi connected");

  // Print the IP address of the device:
  Serial.println(WiFi.localIP());
  
}

void loop() {
  // put your main code here, to run repeatedly:
// Verfiy WiFi is connected:
  if (WiFi.status() == WL_CONNECTED) {

    HTTPClient http;  // Object of the class HTTPClient.

    http.begin("http://dislik.com/nodemcu//urun-lux-kasket-sapka-5");  // Request destination.
    int httpCode = http.GET(); // Send the request.

    if (httpCode > 0) { //Check the returning code

      Serial.println("We got a repsonse!");
      String payload = http.getString();   // Get the text from the destination (1 or 0).
      Serial.println(payload); // Print the text.
      digitalWrite(2, payload.toInt()); // Send the payload value to the pin.

    }else{

      Serial.println("Something baaaaaaad happened!");

    }

    http.end();   //Close connection

  }

  delay(1000);    //Send a request every 30 seconds
}
Serial.println(payload);

answer is 1 but not working

answer is 1 but not working

The answer is NOT 1. The answer is "1".

But, all you have is a bunch of meaningless anonymous printing of something that you don't use.

Serial.print("payload: [");
Serial.print(payload);
Serial.println("]");

conveys orders of magnitude more information than

Serial.println(payload);
int pinState = payload.toInt();
Serial.print("pinState: ");
Serial.println(pinState);

Now, you can use pinState and KNOW what value if contains.

If the pin does not appear to change state, when you KNOW what state it is supposed to change to, then whatever means you are using to determine that is wrong.

hi Paul

there is a meaningless problem

String payload = http.getString();   
      int pinState=payload.toInt();
      Serial.print("payload: ");
      Serial.print(payload);
      Serial.print("pinState: ");
      Serial.println(pinState);
      digitalWrite(2, payload.toInt());

seial monitor

payload : 1
pinState : 0

payload and pinstate not equal

payload is "1"
pinstate=payload.toint();
pinstate= "0"

and led is not blinking

I suggested that you print payload between markers so that you could see EXACTLY what it contains. You didn't. Before I will offer more help, I need to understand why you did not follow my previous advice.

You just MIGHT have learned something interesting.

hi Paul

I've tried

String payload = http.getString();  
Serial.print("payload: [");
Serial.print(payload);
Serial.println("]");
int pinState = payload.toInt();
Serial.print("pinState: ");
Serial.println(pinState);
digitalWrite(2, pinState);

Serial monitor

payload: [1]
pinState: 0

Did you mean that?

I understand you say that

result does not change

Did you mean that?

Yes.

Now, it is clear that payload is a String wrapping a string that contains just one character.

It is equally clear that the toInt() method of that String is failing to convert the string in the payload String to an int correctly.

Or, is it? Actually, it is not, which is why we ask that you post ALL of your code every time. I'd like to believe that the 8 lines of code in your snippet are 8 consecutive lines in you total code, but I need to be convinced that that is the case.

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

const char* ssid = "Kablonet_Netmaster-FAF6-G";
const char* password = "mortMen20122111";

void setup() {

  Serial.begin(115200); // Start the serial monitor.
  pinMode(2, OUTPUT); // Set GPIO2 as an OUTPUT.
  digitalWrite(2, 0); // Start off.
  
  Serial.println("Hello Digital Craft");
  Serial.println("connecting");

  WiFi.begin(ssid,password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("WiFi connected");

  Serial.println(WiFi.localIP());
  }
void loop() {

  if (WiFi.status() == WL_CONNECTED) {

    HTTPClient http;  // Object of the class HTTPClient.

    http.begin("http://www.atikermuhendislik.com/urun-lux-kasket-sapka-5");  // Request destination.
    int httpCode = http.GET(); // Send the request.

    if (httpCode > 0) { //Check the returning code

     String payload = http.getString();  
    Serial.print("payload: [");
    Serial.print(payload);
    Serial.println("]");
    int pinState = payload.toInt();
    Serial.print("pinState: ");
    Serial.println(pinState);
    digitalWrite(2, pinState); 
      
    }else{

      Serial.println("Something baaaaaaad happened!");

    }

    http.end();   //Close connection

  }

  delay(1000);    //Send a request every 30 seconds
}

this all code

It is equally clear that the toInt() method of that String is failing to convert the string in the payload String to an int correctly.

yes, not working properly

yes, not working properly

The next step would be to edit the String class' toInt() method, to add some Serial.print() statements, to learn why it does not work. There is nothing in the code you posted to suggest why toInt() is failing. The input looks good. The output should be something different from what is actually output.

But, before you go there, create a simple sketch.

void setup()
{
   Serial.begin(115200);

   pinMode(2, OUTPUT); // Set GPIO2 as an OUTPUT.
   digitalWrite(2, 0); // Start off.

   String payload = "1";

   Serial.print("payload: [");
   Serial.print(payload);
   Serial.println("]");

   int pinState = payload.toInt();
   Serial.print("pinState: ");
   Serial.println(pinState);

   digitalWrite(2, pinState);
}

void loop()
{
}

What does this code show? What happens to pin 2?

PaulS:

void setup()

{
  Serial.begin(115200);

pinMode(2, OUTPUT); // Set GPIO2 as an OUTPUT.
  digitalWrite(2, 0); // Start off.

String payload = "1";

Serial.print("payload: [");
  Serial.print(payload);
  Serial.println("]");

int pinState = payload.toInt();
  Serial.print("pinState: ");
  Serial.println(pinState);

digitalWrite(2, pinState);
}

void loop()
{
}




What does this code show? What happens to pin 2?

result of this code

serial monitor => pinState:1

pin2 is led blinking

So, there is something in the ESP8266xxxx libraries that is causing String::toInt() to malfunction. Start adding the header files into that code, one at a time, compiling and linking and testing in between each addition.

If it isn't just a matter of adding an otherwise unused header file, start adding bits of code back in, compiling and linking and testing in between each addition. It shouldn't take long to figure out what the problem is.

i will try Paul

Thanks for the help