Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behaviour #10

Open
michelep opened this issue Oct 25, 2018 · 1 comment
Open

Strange behaviour #10

michelep opened this issue Oct 25, 2018 · 1 comment

Comments

@michelep
Copy link

Hi,

first, thanks for your work. I have a strange behaviuor using your RestClient library as a pointer.
I define a RestClient object as a pointer, because i need to create it after loading the collector host IP from a config file:

RestClient *restClient;

Later i initialize the object:

      ...
      restClient = new RestClient(config.collector_host); 
      ....

and i send data via POST like:

  char query[128];
  String response="";
  ...
          sprintf(query,"key=%s&ts=%d&t=%s&p=%s&h=%s&uv=%d&pm25=%s&pm10=%s",config.api_key,data.ts,data.temp,data.pres,data.hum,data.uv,data.pm25,data.pm10);
          statusCode = restClient->post("/rest/data/put", query, &response);

but watching data with tcpdump, i see strange behavour in header like:

POST /rest/data/put HTTP/1.1
Host: [host]:80
Connection: close
Content-Length: 36
**Content-Type: L.).**

key=KEY&t=21.60&h=39.80

Any help really appreciated !

@DaKaZ
Copy link
Owner

DaKaZ commented Dec 4, 2018

Sorry for the complete lack of response, I did not see this issue get created. I have not personally used the library with a pointer. Obviously you are getting some memory corruption. The new RestClient should properly alloc your memory. So some more questions:

  1. Are you ever calling restClient->setContentType? If you are, you might need to strdup (or we can update the library (see https://github.com/DaKaZ/esp8266-restclient/blob/master/RestClient.cpp#L145)

  2. Is the body correct there? I am assuming no since the length is reported at 36 and your body key=KEY&t=21.60&h=39.80 is only 23, but maybe you removed KEY?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants