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();
}
}
}
-
Please could you explain what you've done here: if(likes = response.substring(response.indexOf("Likes:")+6, response.indexOf("::")))keenbeginner– keenbeginner2018年06月26日 14:05:30 +00:00Commented 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 ReviewVE7JRO– VE7JRO2018年06月26日 16:29:14 +00:00Commented 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 ReviewGreenonline– Greenonline2018年06月26日 18:25:11 +00:00Commented Jun 26, 2018 at 18:25
1 Answer 1
Thank you everyone I had to just clear the response string every time.
I have just added response = "";
after the Serial.print(currentLikes);