String getAPIData()
  char res_buffer[450];
  int numdata = inet.httpGET("myserver.com", 80, "/call.php?id=1&q=1&code=1001", res_buffer, 450);
  String result = String(res_buffer);
  return result;

Output on Serial:

15:52:07.208 -> 
15:52:07.208 -> 393

But, When I print the buffer by loop I got the below output:

HTTP/1.1 200 OK
Date: Mon, 16 Sep 2019 06:28:59 GMT
Server: Apache
X-Powered-By: PHP/7.2.20
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Set-Cookie: PHPSESSID=5b21eeac22dcf61f2e4d2efd579d437c; path=/
Upgrade: h2,h2c
Connection: Upgrade, close
Vary: Accept-Encoding,User-Agent
Content-Type: text/html; charset=UTF-8


I am not sure why the char buffer is not converting to String in Arduino UNO.

Any known issues ? Please suggest if any correction required.

  • Don't use String. It's not fit for purpose. There is no cause to ever use String.
    – Majenko
    Sep 18 '19 at 10:45
  • Chances are you are running out or memory and the String allocation doesn't happen. You need 450 bytes for your buffer, 450 bytes for the String you are using, and another 450 bytes for the String you are returning. That's 1350 bytes out of a maximum 2048 just for that function.
    – Majenko
    Sep 18 '19 at 10:49

Do not use String. And especially do not use String in the way you are using it.

You can read more about why not here.

Instead stick to just using char* buffers.

The correct way of doing what you want is to define the buffer outside your function and then pass that buffer to the function to be populated:

int getAPIData(char *buf, int maxlen) {
  return inet.httpGET("myserver.com", 80, "/call.php?id=1&q=1&code=1001", buf, maxlen);

Then you call it with:

char *my_buffer[450];
getAPIData(my_buffer, 450);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.