Hello,
Im not that familiar whit HTTP request and sending GPS coordinates.
Im using an arduino whit GSM shield V2 (and a GPS shield)
Im trying to send GPS coordinates to ubidots.
I want to make http request.
I can send the longitude and latidtude indivudiualy to ubidots but I cant get them togheter in 1 request.
Based of another users post I found out that &context=lat=%s,lng=%s has to be included.
Now im trying to use that sentence in my payload. I cant seem to get it to work.
Does anyone know a solution?
Here is a part of my code to get an idea what im trying to do.
// Important: Avoid to send a very long char as it is very memory space costly, send small char arrays
sprintf(payload, "{\"");
sprintf(payload, "&context=lat=%s,lng=%s", payload);
sprintf(payload, "%s%s\":%", payload, VARIABLE_LABEL_1,str_val_1,str_val_2);
sprintf(payload, "%s}", payload);
Serial.println(payload);
SendToUbidots(payload);
After the payload has been constucted im using this code to send it:
PayloadLenght = strlen(payload); //Determin the payload lenght (Needed to send data to a server)
/* Builds the request POST - Please reference this link to know all the request's structures https://ubidots.com/docs/api/ */
sprintf(HTTPPostString, "POST /api/v1.6/devices/%s/?force=true HTTP/1.1\r\n", DEVICE_LABEL);
sprintf(HTTPPostString, "%sHost: things.ubidots.com\r\n", HTTPPostString);
sprintf(HTTPPostString, "%sUser-Agent: %s/%s\r\n", HTTPPostString, USER_AGENT, VERSION);
sprintf(HTTPPostString, "%sX-Auth-Token: %s\r\n", HTTPPostString, TOKEN);
sprintf(HTTPPostString, "%sConnection: close\r\n", HTTPPostString);
sprintf(HTTPPostString, "%sContent-Type: application/json\r\n", HTTPPostString);
sprintf(HTTPPostString, "%sContent-Length: %d\r\n\r\n", HTTPPostString, PayloadLenght);
sprintf(HTTPPostString, "%s%s\r\n", HTTPPostString, payload);
Greetings,
Robert