[SOLVED] Arduino with SIM900 - POST works, GET does not

Hello comunity,

Had my first encounter with Ubidots, not using the library they published, I prefer to do the code manually so I know exactly what happens for debugging purposes. I got my test device - arduino mega with SIM900 module - to send variable to ubidots, updates regularly without fail. Now I’m trying to get a value from one variable in the cloud in order to switch on pin13, the html GET request sends OK but the ubidots server does not respond. The only response I get is 408 (timout) a couple minutes after the request was sent. “Your browser didn’t send a complete request in time.”

Ubidots support says the syntax is received correct at their end and that it must be with my device. After the request is sent it goes over to loop where it continually checks the SIM900 for a response. I know this part of the code is good because the same code works perfectly to receive the response from the server when I send a POST request.

Exchanges between my device and ubidots below. Any ideas why the server ignores what I send? I use the exact syntax as per the REST API docs with correct token and labels. What is missing from my request body?

Thanks


AT+CIPSPRT=0

OK
AT+CIPSTART="TCP","http://things.ubidots.com","80"

OK

CONNECT OK

AT+CIPSEND=123
GET /api/v1.6/devices/demovolts/pin13switch/?token=xxxxxxxxxx HTTP/1.1
Host: things.ubidots.com



SEND OK
HTTP/1.0 408 Request Time-out
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html><body><h1>408 Request Time-out</h1>
Your browser didn't send a complete request in time.
</body></html>


CLOSED

Hello @agrisense,

As I can see your request is missing a parameter. Your actual endpoint is:

/api/v1.6/devices/demovolts/pin13switch/?token=xxxxxxxxxx

You have to specify if you want to retreive the last value or the values of the variable specified in the request. Please follow the structure below based on your needs:

  • Last Value:

/api/v1.6/devices/{LABEL_DEVICE}/{VARIABLE_LABEL}/lv?token={TOKEN}

  • Values:

/api/v1.6/devices/{LABEL_DEVICE}/{VARIABLE_LABEL}/values?token={TOKEN}

For more information, see Ubidots REST API Reference.

All the best,
Maria C.

thanks Maria.

I have just tried with both suggestions, all with the same result. I need last value only so I am leaving it with lv?. But no luck. The server response is still that the request is incomplete. Are you able to see on the backend what data is actually received on your end?

Currently my device sends this:

GET /api/v1.6/devices/demovolts/pin13switch/lv?token=BBFF-U75pxqjfbPeP3Q56C6FntSlkGH9GbQ HTTP/1.1
Host: things.ubidots.com

Dear user,

Are you able to make a GET request to google.com? It seems an error at your device side!

Ok I got it working - minor issue. I needed an additional \r\n at the end of my request before the server recognised it as a full request.

Thanks for your help

On a similar note, can you tell me if there is a special termination character at the end of Ubidots server responses? If there is it would make it a bit easier to parse

Hello @agrisense,

Please, take a look of the get method of this Ubidots Library, over there you can get a better idea how to parse the last value received.

All the best,
Maria C.