Go Down

Topic: websites get data (Read 171 times) previous topic - next topic

atiker

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

DrAzzy

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.
ATtiny core for 841+1634+828 and x313/x4/x5/x61/x7/x8 series Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts (some assembled), mosfets and awesome prototyping board in my store http://tindie.com/stores/DrAzzy

atiker

#2
May 22, 2019, 12:09 am Last Edit: May 22, 2019, 12:09 am by atiker
Code: [Select]
#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
}



Code: [Select]
Serial.println(payload);
answer is 1 but not working

PaulS

Quote
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.

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

conveys orders of magnitude more information than
Code: [Select]
Serial.println(payload);

Code: [Select]
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.
The art of getting good answers lies in asking good questions.

atiker

#4
May 22, 2019, 11:35 am Last Edit: May 22, 2019, 11:58 am by atiker
hi Paul

there is a meaningless problem


Code: [Select]
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
Code: [Select]
payload : 1
pinState : 0


payload and pinstate not equal

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

and led is not blinking

PaulS

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.
The art of getting good answers lies in asking good questions.

atiker

hi Paul

I've tried

Code: [Select]

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
Code: [Select]

payload: [1]
pinState: 0



Did you mean that?

I understand you say that

result does not change

PaulS

Quote
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.
The art of getting good answers lies in asking good questions.

atiker

Code: [Select]
#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


Quote
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

PaulS

Quote
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.

Code: [Select]
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?
The art of getting good answers lies in asking good questions.

atiker

Code: [Select]
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

PaulS

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.
The art of getting good answers lies in asking good questions.

atiker

i will try Paul

Thanks for the help

Go Up