This Topic allows to Publish one or more Dots to a Variable in a Device

To send data to one variable, please Publish to the following Topic with the following parameters:

Topic

/v1.6/devices/{DEVICE_LABEL}/{VARIABLE_LABEL}

Field

Value

Required

Host

industrial.api.ubidots.com

Yes

Port

1883/8883 (Non-TLS/TLS)

Yes

Username

Your Ubidots Token

Yes

Password

Any character or leave blank

No

Quality of Service

0 or 1

No

Payload

The accepted message payloads for different cases are as follows:

{"value": 27}
{
  "value": 10,
  "timestamp": 1634311791000,
  "context": {
    "status": "cold"
  }
}
[
  {
    "value": 27,
    "timestamp": 1634311791000
  },
  {
    "value": 28,
    "timestamp": 1634311435000
  },
  {
    "value": 34,
    "timestamp": 1634876591000
  }
]
{
  "value": 1, 
  "context": {
    "lat": "6.5423", 
    "lng": "-70.5783"
  }
}

📘

timestamp and context

The timestamp and context parameters are optional.

🚧

Timestamp Format

All timestamps must be in milliseconds. You can easily convert dates to timestamp values here.

Sending location data

You may use the context key to send location data. Ubidots will automatically recognize location data when using these variable labels:

  • position
  • location
  • gps

There are 3 ways to send location data:

{
  "position": {
    "value": 1, 
    "context": {
      "lat": "6.5423", 
      "lng": "-70.5783"
    }
  }
}
// Since the "value" of a dot is mandatory, this option will set the variable value to "1".

{
  "position": {
      "lat": "6.5423", 
      "lng": "-70.5783"
    }
}
// Since the "value" of a dot is mandatory, this option will set the variable value to  "1".

{
  "position": {
      "latitude": "6.5423", 
      "longitude": "-70.5783"
    }
}

👍

Location Data

You have a lot of ways to include longitude and latitude when sending your dots to Ubidots. Please refer to this documentation.

Examples

📘

Note

All the bash examples from this section make use of the Eclipse Mosquitto library, if you wish to test them please install it using the official instructions.

Send a value to a Variable
Update a variable and let Ubidots apply a timestamp equal to the reception time:

$ mosquitto_pub \
-h 'industrial.api.ubidots.com' \
-t '/v1.6/devices/weather-station/temperature' \
-u 'BBFF-Rfcgaxns6HlVb155WA0RhSY85xNDmB' \
-p 1883 \
-q 1 \
-m '{"value": 27}'

Send multiple values to a Variable
Update a Variable with multiple Values, each containing a specified timestamp:

$ mosquitto_pub \
-h 'industrial.api.ubidots.com' \
-t '/v1.6/devices/weather-station/temperature' \
-u 'BBFF-Rfcgaxns6HlVb155WA0RhSY85xNDmB' \
-p 1883 \
-q 1 \
-m '[
  {
    "value": 27,
    "timestamp": 1634311791000
  },
  {
    "value": 28,
    "timestamp": 1634311435000
  },
  {
    "value": 34,
    "timestamp": 1634876591000
  }
]'

Send a Dot to a single Variable
Update a variable with a complete Dot by specifying context and/or timestamp:

$ mosquitto_pub \
-h 'industrial.api.ubidots.com' \
-t '/v1.6/devices/weather-station/temperature' \
-u 'BBFF-Rfcgaxns6HlVb155WA0RhSY85xNDmB' \
-p 1883 \
-q 1 \
-m '{
  "value": 10,
  "timestamp": 1634311791000,
  "context": {
    "status": "cold"
  }
}'

Send location data
Update a position variable so that the Device displays its location:

$ mosquitto_pub \
-h 'industrial.api.ubidots.com' \
-t '/v1.6/devices/weather-station/position' \
-u 'BBFF-Rfcgaxns6HlVb155WA0RhSY85xNDmB' \
-p 1883 \
-q 1 \
-m '{
  "value": 1, 
  "context": {
    "lat": "6.5423", 
    "lng": "-70.5783"
  }
}'
$ mosquitto_pub \
-h 'industrial.api.ubidots.com' \
-t '/v1.6/devices/weather-station/position' \
-u 'BBFF-Rfcgaxns6HlVb155WA0RhSY85xNDmB' \
-p 1883 \
-q 1 \
-m '{
  "lat": "6.5423", 
  "lng": "-70.5783"
}'
mosquitto_pub \
-h 'industrial.api.ubidots.com' \
-t '/v1.6/devices/weather-station/position' \
-u 'BBFF-Rfcgaxns6HlVb155WA0RhSY85xNDmB' \
-p 1883 \
-q 1 \
-m '{
  "latitude": "6.5423", 
  "longitude": "-70.5783"
}'

📘

Same timestamp for multiple values

If the same timestamp is needed for multiple values, then Publishing data with a global timestamp might be a good idea to save payload space. For more instructions, please view Publish data with global timestamp.