SIM7000 / GOBLIN 2 sending position to a variable is not working

I use the SIM7600 module to post HTTP to Ubidots. I used the Gremlin 2 demo and it works well for one variable. Now, I want to send my position (latitude, longitude) to be shown on the map. In order to do that, I created a new variable called “position”, I copied it’s ID and I try to send the position using these commands:

I am sending {“position”:{“lat”:6.2442, “lng”:-75.5812}} :

        Serial1.println("AT+CIPSEND=0,249");
        delay(500);
       Serial1.println(F("POST /api/v1.6/variables/5f0478691d84723eXXXXYYYY/values  HTTP/1.1"));
        delay(50);
        Serial1.println(F("Content-Type: application/json"));
        delay(50);
        Serial1.println(F("Content-Length:43"));
        delay(50);
        Serial1.println(F("X-Auth-Token: BBFF-UCuh8QmF1rBbutwYgfCodDXXXXYYYY"));
        delay(50);
        Serial1.println(F("Host: industrial.api.ubidots.com"));
        delay(50);
        Serial1.println("");
        delay(50);
        Serial1.println("{\"position\":{\"lat\":6.2442, \"lng\":-75.5812}}"); 
        delay(50);
        Serial1.write(0x1A);
        delay(2000);
        Serial1.println(F("AT+CIPCLOSE=0"));

the response I get is:
RECV FROM:169.55.61.243:80
+IPD314
HTTP/1.1 200 OK

but when I log into the dashboard, I see that “position” variable has no data at all.
I also set “Auto” to the device Mode.

What am I doing wrong?

Hello @rotemse,

You probably took this JSON payload format out this article, but such structure is only available through the /api/v1.6/devices/ endpoint, whereas you’re using the variables endpoint.

With that in mind, here are 2 options that you can choose from to fix the issue:

  1. Adapt you current payload (content-length as well) to what’s expected by the /api/v1.6/variables/{ID}/values/ endpoint:
Serial1.println("AT+CIPSEND=0,249");
delay(500);
Serial1.println(F("POST /api/v1.6/variables/5f0478691d84723eXXXXYYYY/values  HTTP/1.1"));
delay(50);
Serial1.println(F("Content-Type: application/json"));
delay(50);
Serial1.println(F("Content-Length:55"));
delay(50);
Serial1.println(F("X-Auth-Token: BBFF-UCuh8QmF1rBbutwYgfCodDXXXXYYYY"));
delay(50);
Serial1.println(F("Host: industrial.api.ubidots.com"));
delay(50);
Serial1.println("");
delay(50);
Serial1.println("{\"value\":1, \"context\":{\"lat\": 6.5423, \"lng\": -70.5783}}"); 
delay(50);
Serial1.write(0x1A);
delay(2000);
Serial1.println(F("AT+CIPCLOSE=0"));
  1. Leave the payload as is and change to the /api/v1.6/devices/{DEVICE_LABEL}/ endpoint instead. This option I recommend as you’d be using Labels (which are of your choice), as opposite to IDs.
Serial1.println("AT+CIPSEND=0,249");
delay(500);
Serial1.println(F("POST /api/v1.6/devices/gps/  HTTP/1.1"));
delay(50);
Serial1.println(F("Content-Type: application/json"));
delay(50);
Serial1.println(F("Content-Length:43"));
delay(50);
Serial1.println(F("X-Auth-Token: BBFF-UCuh8QmF1rBbutwYgfCodDXXXXYYYY"));
delay(50);
Serial1.println(F("Host: industrial.api.ubidots.com"));
delay(50);
Serial1.println("");
delay(50);
Serial1.println("{\"position\":{\"lat\":6.2442, \"lng\":-75.5812}}"); 
delay(50);
Serial1.write(0x1A);
delay(2000);
Serial1.println(F("AT+CIPCLOSE=0"));

–David

Thank you the second example works. Now I would like to be able to pull the position from Ubidots back to a PC / android app. Do you have an example on how to achieve that?

Thanks

Check out the HTTP GET requests docs to retrieve data. You can either:

  1. Make a GET to the variable and then access the “last value” key:

Request:
GET https://industrial.api.ubidots.com/api/v1.6/devices/<device_label>/<variable_label>

In response:

... "last_value": {
        "value": 0.874114,
        "timestamp": 1595258049892,
        "context": {},
        "created_at": 1595258049892
    },
  1. Make a GET to the values of the variable, retrieving only one value:

Request:
GET https://industrial.api.ubidots.com/api/v1.6/devices/<device_label>/<variable_label>/values?page_size=1

Response:

... {
"count": true,
"next": "https://industrial.api.ubidots.com/api/v1.6/devices/<device_label>/<variable_label>/values?page_size=1&page=2",
"previous": null,
"results": [
    {
        "timestamp": 1595258269532,
        "value": 0.87,
        "context": {},
        "created_at": 1595258269532
    }
]}}

The “lat” and “lng” values would appear in the “context” of the variable.