electronicsguy / ESP8266

ESP8266 Projects
242 stars 183 forks source link

Storing output of client->GET(url, host) to String #45

Closed bigFin closed 6 years ago

bigFin commented 6 years ago

When client->GET(url, host) is invoked, the value from the spreadsheet is printed directly to the serial monitor. I would like to store this value in a String. How do i do it?

electronicsguy commented 6 years ago

@bigFin as of now, you cannot. it's on my list :) new job has taken up all the time, but 90% of a new project is ready, which will support this and a whole lot more. please stay tuned. Hopefully another 2-3 weeks.

bigFin commented 6 years ago

Heyo @electronicsguy, thanks for the prompt reply. Can you suggest a workaround for the time being? I suspect that there's a Serial.println() in the client GET method that could be replaced with a return. I'm going to go hunting for that now, but if you can point me in the right direction I'd appreciate it.

Otherwise, good luck with the new job and the new project! Thanks for your contributions to the digiverse.

bigFin commented 6 years ago

Wowza I should really read the documentation more thoroughly. I found this little gem getResponseBody(); and then used String str = client->getResponseBody(); to wrangle it into a string. A minor bug is that this causes the response to print to the serial monitor despite the fact that the option client->setPrintResponseBody(false); is false...

electronicsguy commented 6 years ago

@bigFin thanks for reporting it. I did have that function, but it was only used for testing. You can use it for now. It'll be corrected and more flexible methods will be added in the next version.

cheers.

tlujan0001 commented 6 years ago

Hi @electronicsguy, thank you for you contribution. I'm a beginner and have learned so much using this library. I too am trying to to pass the output to a string, @bigFin could you possibly share the code you used for your work around? I'm so new I don't even know where to paste String str = client->getResponseBody();.

bigFin commented 6 years ago

Hey @tlujan0001 You can use the function getResponseBody(); and then String str = client->getResponseBody(); in your main loop. Just be sure to call getResponseBody() before pointing a string to it. After this your output will be stored in the string str.

tlujan0001 commented 6 years ago

@bigFin I got it! Thank you for the clarification. It works great, except I'm seeing two additional strange characters after the string on my LCD. Have you experienced this?

electronicsguy commented 6 years ago

@tlujan0001 what characters are they? print int(c) to find out the ascii value.

bigFin commented 6 years ago

@tlujan0001 Nope it works as expected. Sounds like you've other fish to fry!

tlujan0001 commented 6 years ago

Hey guys, looks like the characters I was seeing on the LCD came from a return after printing my string. I added trim(); to fix this: String str= client->getResponseBody(); str.trim();