GPS Location

This section explains the 3 different types of location data.

Many Devices or Variables are in a particular GPS position. It can be very useful to set a fixed GPS location for a Device. Another case where location data come in handy is for moving devices (imagine a truck or a boat). Hence it might be necessary to send location data in every dot.

There are 3 different ways you can post location data to Ubidots:

  • Manual
  • Auto
  • Specified

  1. Setting GPS location manually

In this case the latitude and longitude are posted in the properties attribute in the body when creating a Device or updating a Device. This is the default of each device.

To add the location manually add the following object to the Device body:

"properties": { "location_type": "manual", "_location_fixed": { "lat": 6.2486, "lng": 75.5742 } }

//POST a Device with its exact GPS coordinates

curl -X POST 'https://industrial.api.ubidots.com/api/v2.0/devices/' \
 -H 'Content-Type: application/json' \
 -H 'X-Auth-Token: oaXBo6ODhIjPsusNRPUGIK4d72bc73' \
 -d '{
    "label": "truck-1-device",
    "name": "Truck 1 Device",
    "description": "Moving Truck",
    "isActive": true,
    "properties": {
        "location_type": "manual",
      	"_location_fixed": { 
          	"lat": 6.2486, 
            "lng": 75.5742 
        } 
    }
}'
  1. Setting GPS location automatically (Default)

When the Device location is set to auto it will search for the first Variable that has a matching label with one of the three options:

  • position
  • gps
  • location

To set the location automatically add the following object to the Device body:
"properties": { "_location_type":"auto" }

🚧

Please Avoid

Please avoid having two or more Variables with the allowed names (position, gps, location) as it might create inconsistencies.

//POST a Device with automatic GPS location

curl -X POST 'https://industrial.api.ubidots.com/api/v2.0/devices/' \
 -H 'Content-Type: application/json' \
 -H 'X-Auth-Token: oaXBo6ODhIjPsusNRPUGIK4d72bc73' \
 -d '{
    "label": "truck-1-device",
    "name": "Truck 1 Device",
    "description": "Moving Truck",
    "isActive": true,
    "properties": { 
      	"_location_type":"auto"
    }
}'
  1. Setting GPS location specifically

Another option to set the GPS location of a device is setting it specifically by adding the following to the properties object of a Device:
"properties": { "_location_type":"specified", "_location_variable": <variable-label> }

The <variable_label> is the Variable that contains the GPS location, please note that it goes without the tilde ~.

Thus, the isLocationVariable key is automatically set to true inside the properties of the corresponding Variable.

Using the specified mode frees you to use any name for your Variable.

//POST a Device with specific GPS location

curl -X POST 'https://industrial.api.ubidots.com/api/v2.0/devices/' \
 -H 'Content-Type: application/json' \
 -H 'X-Auth-Token: oaXBo6ODhIjPsusNRPUGIK4d72bc73' \
 -d '{
    "label": "truck-1-device",
    "name": "Truck 1 Device",
    "description": "Moving Truck",
    "isActive": true,
    "properties": { 
      	"_location_type":"specified",
        "_location_variable":<variable-label>
    }
}'