0

I have connected my ESP8266 to my Arduino Uno on pin 2 & pin 3 as RX & TX. I adjusted the baud rates and I have no issue receiving the data from the ESP8266.

The ESP8266 gets connected as a client to a server and grabs the likes count of a Facebook page. The data on the ESP8266 serial port is updated correctly every time the ESP sends a get request to the server to get the updated likes count of a particular Facebook page.

Unfortunately I'm not receiving this updated likes count on my Arduino serial port. I'm always receiving the same likes count. I have to close the serial window and open it again to receive the new count. Or reset the Arduino itself to receive the new likes count.

So why isn't it posting the latest likes count sent from the ESP to the Arduino instantly without having to reset the Arduino? Maybe I have an issue in the void loop().

Because I display this data on an external display and I need it to be updated without me needing to reset the Arduino every time to receive the latest count.

void loop() {
 char c;
 while (esp8266.available() && c != '\n') {
 c = esp8266.read();
 response += c;
 }
 //If end of line
 if (c == '\n') {
 //Getting the likes string only
 if(likes = response.substring(response.indexOf("Likes:")+6, response.indexOf("::"))) {
 //Filtering some unneeded strings
 if((strstr(likes.c_str(), "URL")) == NULL) {
 currentLikes = atol(likes.c_str());
 Serial.print(currentLikes);
 //Printing likes count on serial port
 }
 Serial.println();
 }
 }
}
dda
1,5951 gold badge12 silver badges17 bronze badges
asked Jan 10, 2017 at 20:03
3
  • Please could you explain what you've done here: if(likes = response.substring(response.indexOf("Likes:")+6, response.indexOf("::"))) Commented Jun 26, 2018 at 14:05
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review Commented Jun 26, 2018 at 16:29
  • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review Commented Jun 26, 2018 at 18:25

1 Answer 1

1

Thank you everyone I had to just clear the response string every time.

I have just added response = ""; after the Serial.print(currentLikes);

dda
1,5951 gold badge12 silver badges17 bronze badges
answered Jan 10, 2017 at 20:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.