[SOLVED] GET last value comes with unknown lines

Hello,

I am trying to fetch data from my Ubidots device by sending a GET request to “http://things.ubidots.com/api/v1.6/devices/{LABEL_DEVICE}/{VARIABLE_LABEL}/lv” as shown here. This is done by using an Arduino coupled with WiFi module ESP8266.

The command is shown below:

GET /api/v1.6/devices/Demo/temperature/lv HTTP/1.1
Host: things.ubidots.com
X-Auth-Token: MYTOKEN
Connection: close

This is what I get for response:

HTTP/1.1 200 OK
Server: nginx
Date: Thu, 30 Aug 2018 12:06:04 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Cookie
Allow: GET, HEAD, OPTIONS

5
34.57
0

While ‘34.57’ is the last value in the variable, I do not know what do the ‘5’ and ‘0’ mean. I suspect the ‘5’ is the number of characters, but in some cases (e.g. when sending POST to upload data) the numbers do not tally.

Also, if I directly paste the URL into a browser, it only shows the data “34.57” (the ‘5’ and ‘0’ are missing). Why are these lines appearing and is there anyway to get rid of them?

Greetings,

The ‘5’ represents the value char array length, while the ‘0’ is in fact 0 which is a typical HTTP end of the response, your browser usually omits them and that is why you only see your value when you make a GET using it while using an Arduino a routine to rid them off is not implemented and you get all the characters answered by the server.

All the best.

Thanks for the swift reply.

I was expecting that the server will embed the array length into ‘Content-Length’ in the header rather than outputting it in the message body. If the ‘5’ is the length of the value char array, why when I do a POST request:

POST /api/v1.6/devices/Demo/ HTTP/1.1
Host: things.ubidots.com
X-Auth-Token: MYTOKEN
Connection: close
Content-Type: application/json
Content-Length: 21

{“temperature”:34.57}

I get this:

HTTP/1> .1 200 OK
Server: nginx
Date: Fri, 31 Aug 2018 02:06:44 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Cookie
Allow: GET, POST, HEAD, OPTIONS

27
{“temperature”: [{“status_code”: 201}]}
0

The length of the returned array ‘{“temperature”: [{“status_code”: 201}]}’ is actually 39 instead of the ‘27’ returned. Why is there a discrepancy?

Greetings, it is not ‘discrepancy’, you are making two different kinds of requests, the first one is a POST request while the second one is a GET request. As they are different, the server response is different, so you should not expect the same server answer.

About the payload length, you get a 27 because it is coded in hexadecimal base, hex 27 is equal to 39 in decimal base, which is the payload response length. The answer is given as hexadecimal due to the transfer-encoding type. In both, POST and GET, the payload length is given in hexadecimal:

hex 5 = dec 5
hex 27 = dec 39

I notice that you have some doubts related with the HTTP protocol itself instead of with any Ubidots functionality, so I gently advise you to refer to the protocol docs reference (here, here ) if you wish to know more about this topic as unfortunately, our support bandwidth is not enough length for solving these kinds of doubts.

All the best.